23 #define GLOBUS_LIBC_H 1
28 #if defined(WIN32) && !defined(__CYGWIN__)
34 #if !defined(__USE_MINGW_ANSI_STDIO)
35 #define snprintf _snprintf
40 # define GLOBUS_DEPRECATED(func) func __attribute__((deprecated))
41 #elif defined(_MSC_VER)
42 # define GLOBUS_DEPRECATED(func) __declspec(deprecated) func
44 # define GLOBUS_DEPRECATED(func) func
53 #define globus_macro_libc_lock() \
54 globus_mutex_lock(&globus_libc_mutex)
55 #define globus_macro_libc_unlock() \
56 globus_mutex_unlock(&globus_libc_mutex)
59 #define globus_libc_lock() globus_macro_libc_lock()
60 #define globus_libc_unlock() globus_macro_libc_unlock()
62 extern int globus_libc_lock(
void);
63 extern int globus_libc_unlock(
void);
67 # define globus_libc_va_copy(dest,src) \
69 #elif defined(__va_copy)
70 # define globus_libc_va_copy(dest,src) \
73 # define globus_libc_va_copy(dest,src) \
74 memcpy(&dest, &src, sizeof(va_list))
78 #define globus_stdio_lock globus_libc_lock
79 #define globus_stdio_unlock globus_libc_unlock
80 #define globus_libc_printf printf
81 #define globus_libc_fprintf fprintf
82 #define globus_libc_sprintf sprintf
83 #define globus_libc_vprintf vprintf
84 #define globus_libc_vfprintf vfprintf
85 #define globus_libc_vsprintf vsprintf
87 #if __STDC_VERSION__ >= 199901L
88 #define globus_libc_snprintf snprintf
89 #define globus_libc_vsnprintf vsnprintf
91 extern int globus_libc_snprintf(
char *s,
size_t n,
const char *format, ...);
92 extern int globus_libc_vsnprintf(
char *s,
size_t n,
const char *format,
100 #define globus_libc_open open
101 #define globus_libc_close close
102 #define globus_libc_read read
103 #define globus_libc_write write
104 #define globus_libc_umask umask
105 #define globus_libc_writev writev
106 #define globus_libc_fstat fstat
108 #define globus_libc_opendir opendir
109 #define globus_libc_telldir telldir
110 #define globus_libc_seekdir seekdir
111 #define globus_libc_rewinddir rewinddir
112 #define globus_libc_closedir closedir
113 #define globus_libc_getpwuid_r getpwuid_r
119 globus_libc_umask_win32(
122 # define globus_libc_open _open
123 # define globus_libc_close _close
124 # define globus_libc_read _read
125 # define globus_libc_write _write
126 # define globus_libc_umask globus_libc_umask_win32
127 # define globus_libc_writev(fd,iov,iovcnt) \
128 write(fd,iov[0].iov_base,iov[0].iov_len)
130 #if defined(TARGET_ARCH_CYGWIN) || defined(TARGET_ARCH_MINGW32)
131 #define globus_libc_opendir opendir
132 #define globus_libc_telldir telldir
133 #define globus_libc_seekdir seekdir
134 #define globus_libc_rewinddir rewinddir
135 #define globus_libc_closedir closedir
140 globus_libc_readdir_r(
142 struct dirent ** result);
147 #define globus_malloc(bytes) globus_libc_malloc(bytes)
148 #define globus_realloc(ptr,bytes) globus_libc_realloc(ptr,bytes)
149 #define globus_calloc(nobjs,bytes) globus_libc_calloc(nobjs,bytes)
150 #define globus_free(ptr) globus_libc_free(ptr)
152 #define globus_libc_malloc malloc
153 #define globus_libc_realloc realloc
154 #define globus_libc_calloc calloc
155 #define globus_libc_free free
156 #define globus_libc_alloca alloca
157 #define globus_libc_lseek lseek
160 int globus_libc_gethostname(
char *name,
int len);
161 int globus_libc_getpid(
void);
162 int globus_libc_fork(
void);
163 int globus_libc_usleep(
long usec);
164 double globus_libc_wallclock(
void);
167 extern int globus_libc_sprint_off_t(
char * s, globus_off_t off);
169 extern int globus_libc_scan_off_t(
char *s, globus_off_t *off,
int *consumed);
172 GLOBUS_DEPRECATED(
struct hostent *globus_libc_gethostbyname_r(
char *name,
173 struct hostent *result,
178 GLOBUS_DEPRECATED(
struct hostent *globus_libc_gethostbyaddr_r(
char *addr,
181 struct hostent *result,
186 #ifdef _POSIX_THREAD_SAFE_FUCTIONS
187 #define globus_libc_ctime_r(clock, buf, buflen) ctime_r(clock, buf)
188 #define globus_libc_localtime_r(timer, result) localtime_r(timer, result)
189 #define globus_libc_gmtime_r(timer, result) gmtime_r(timer, result)
191 char *globus_libc_ctime_r(time_t *clock,
char *buf,
int buflen);
192 struct tm * globus_libc_localtime_r(
const time_t *timep,
struct tm *result);
193 struct tm * globus_libc_gmtime_r(
const time_t *timep,
struct tm *result);
197 #define globus_libc_getpwnam_r getpwnam_r
201 globus_libc_strncasecmp(
206 int globus_libc_setenv(
const char *name,
209 void globus_libc_unsetenv(
const char *name);
212 GLOBUS_DEPRECATED(
char *globus_libc_getenv(
const char *name));
215 char *globus_libc_system_error_string(
int the_error);
218 globus_libc_strdup(
const char * source);
221 globus_libc_strndup(
const char *
string,
globus_size_t length);
228 #define globus_libc_strcmp strcmp
229 #define globus_libc_strlen strlen
237 globus_libc_vprintf_length(
const char * fmt, va_list ap);
240 globus_libc_printf_length(
const char * fmt, ...);
243 int globus_libc_gethomedir(
char *result,
int bufsize);
246 globus_common_create_string(
251 globus_common_create_nstring(
257 globus_common_v_create_string(
262 globus_common_v_create_nstring(
268 #define globus_libc_memmove(d, s, n) memmove((d), (s), (n))
271 # define globus_libc_setegid(a) setresgid(-1,a,-1)
272 # define globus_libc_seteuid(a) setresuid(-1,a,-1)
274 # define globus_libc_setegid(a) setegid(a)
275 # define globus_libc_seteuid(a) seteuid(a)
280 typedef struct sockaddr_storage globus_sockaddr_t;
281 typedef struct addrinfo globus_addrinfo_t;
284 #define GlobusLibcProtocolFamilyIsIP(family) \
285 ((family == AF_INET ? 1 : (family == AF_INET6 ? 1 : 0)))
287 #define GlobusLibcProtocolFamilyIsIP(family) \
288 (family == AF_INET ? 1 : 0)
292 #define PF_INET AF_INET
296 #define PF_UNSPEC AF_UNSPEC
299 #define GlobusLibcSockaddrSetFamily(_addr, fam) ((struct sockaddr *) &(_addr))->sa_family = fam
300 #define GlobusLibcSockaddrGetFamily(_addr) ((struct sockaddr *) &(_addr))->sa_family
303 #define GlobusLibcSockaddrGetPort(addr, port) \
306 const struct sockaddr * _addr = (struct sockaddr *) &(addr);\
308 switch(_addr->sa_family) \
311 (port) = ntohs(((struct sockaddr_in *) _addr)->sin_port); \
315 (port) = ntohs(((struct sockaddr_in6 *) _addr)->sin6_port); \
320 "Unknown family in GlobusLibcSockaddrGetPort"); \
326 #define GlobusLibcSockaddrGetPort(addr, port) \
329 const struct sockaddr * _addr = (struct sockaddr *) &(addr);\
331 switch(_addr->sa_family) \
334 (port) = ntohs(((struct sockaddr_in *) _addr)->sin_port); \
339 "Unknown family in GlobusLibcSockaddrGetPort"); \
347 #define GlobusLibcSockaddrSetPort(addr, port) \
350 struct sockaddr * _addr = (struct sockaddr *) &(addr);\
352 switch(_addr->sa_family) \
355 ((struct sockaddr_in *) _addr)->sin_port = htons((port)); \
359 ((struct sockaddr_in6 *) _addr)->sin6_port = htons((port)); \
364 "Unknown family in GlobusLibcSockaddrSetPort"); \
369 #define GlobusLibcSockaddrSetPort(addr, port) \
372 struct sockaddr * _addr = (struct sockaddr *) &(addr);\
374 switch(_addr->sa_family) \
377 ((struct sockaddr_in *) _addr)->sin_port = htons((port)); \
382 "Unknown family in GlobusLibcSockaddrSetPort"); \
389 #define GlobusLibcSockaddrSetLen(addr, len) \
392 struct sockaddr * _addr = (struct sockaddr *) &(addr);\
394 switch(_addr->sa_family) \
397 ((struct sockaddr_in *) _addr)->sin_len = (len); \
401 ((struct sockaddr_in6 *) _addr)->sin6_len = (len); \
406 "Unknown family in GlobusLibcSockaddrSetLen"); \
411 #define GlobusLibcSockaddrCopy(dest_addr, source_addr, source_len) \
412 (memcpy(&(dest_addr), &(source_addr), (source_len)))
414 #define GlobusLibcSockaddrLen(addr) \
415 (((struct sockaddr *) (addr))->sa_family == AF_INET \
416 ? sizeof(struct sockaddr_in) : \
417 (((struct sockaddr *) (addr))->sa_family == AF_INET6 \
418 ? sizeof(struct sockaddr_in6) : -1))
420 #define GLOBUS_AI_PASSIVE AI_PASSIVE
421 #define GLOBUS_AI_NUMERICHOST AI_NUMERICHOST
422 #define GLOBUS_AI_CANONNAME AI_CANONNAME
424 #define GLOBUS_NI_MAXHOST NI_MAXHOST
425 #define GLOBUS_NI_NOFQDN NI_NOFQDN
426 #define GLOBUS_NI_NAMEREQD NI_NAMEREQD
427 #define GLOBUS_NI_DGRAM NI_DGRAM
428 #define GLOBUS_NI_NUMERICSERV NI_NUMERICSERV
429 #define GLOBUS_NI_NUMERICHOST NI_NUMERICHOST
431 #define GLOBUS_EAI_ERROR_OFFSET 2048
433 #define GLOBUS_EAI_FAMILY (EAI_FAMILY + GLOBUS_EAI_ERROR_OFFSET)
434 #define GLOBUS_EAI_SOCKTYPE (EAI_SOCKTYPE + GLOBUS_EAI_ERROR_OFFSET)
435 #define GLOBUS_EAI_BADFLAGS (EAI_BADFLAGS + GLOBUS_EAI_ERROR_OFFSET)
436 #define GLOBUS_EAI_NONAME (EAI_NONAME + GLOBUS_EAI_ERROR_OFFSET)
437 #define GLOBUS_EAI_SERVICE (EAI_SERVICE + GLOBUS_EAI_ERROR_OFFSET)
438 #define GLOBUS_EAI_ADDRFAMILY (EAI_ADDRFAMILY + GLOBUS_EAI_ERROR_OFFSET)
439 #define GLOBUS_EAI_NODATA (EAI_NODATA + GLOBUS_EAI_ERROR_OFFSET)
440 #define GLOBUS_EAI_MEMORY (EAI_MEMORY + GLOBUS_EAI_ERROR_OFFSET)
441 #define GLOBUS_EAI_FAIL (EAI_FAIL + GLOBUS_EAI_ERROR_OFFSET)
442 #define GLOBUS_EAI_AGAIN (EAI_AGAIN + GLOBUS_EAI_ERROR_OFFSET)
443 #define GLOBUS_EAI_SYSTEM (EAI_SYSTEM + GLOBUS_EAI_ERROR_OFFSET)
446 globus_libc_getaddrinfo(
448 const char * service,
449 const globus_addrinfo_t * hints,
450 globus_addrinfo_t ** res);
453 globus_libc_freeaddrinfo(
454 globus_addrinfo_t * res);
457 globus_libc_getnameinfo(
458 const globus_sockaddr_t * addr,
466 globus_libc_addr_is_loopback(
467 const globus_sockaddr_t * addr);
470 globus_libc_addr_is_wildcard(
471 const globus_sockaddr_t * addr);
474 #define GLOBUS_LIBC_ADDR_NUMERIC 1
476 #define GLOBUS_LIBC_ADDR_LOCAL 2
478 #define GLOBUS_LIBC_ADDR_IPV6 4
480 #define GLOBUS_LIBC_ADDR_IPV4 8
486 globus_libc_addr_to_contact_string(
487 const globus_sockaddr_t * addr,
489 char ** contact_string);
493 globus_libc_addr_convert_family(
494 const globus_sockaddr_t * src,
495 globus_sockaddr_t * dest,
500 const char * contact_string,
503 unsigned short * port);
511 globus_libc_ints_to_contact_string(
514 unsigned short port);
517 globus_libc_gethostaddr(
518 globus_sockaddr_t * addr);
521 globus_libc_gethostaddr_by_family(
522 globus_sockaddr_t * addr,
globus_result_t globus_libc_contact_string_to_ints(const char *contact_string, int *host, int *count, unsigned short *port)
Definition: globus_libc.c:2965
Globus Threading Abstraction.
int globus_bool_t
Boolean type.
Definition: globus_types.h:93
Mutex.
Definition: globus_thread.h:107
size_t globus_size_t
Standard size of memory objectThe globus_size_t is the size of a memory object. It is identical to si...
Definition: globus_types.h:48
uint32_t globus_result_t
Definition: globus_types.h:99
char * globus_libc_join(const char **array, int count)
Definition: globus_libc.c:3227