23 #define GLOBUS_LIBC_H 1
28 #if defined(WIN32) && !defined(__CYGWIN__)
33 #define snprintf _snprintf
37 # define GLOBUS_DEPRECATED(func) func __attribute__((deprecated))
38 #elif defined(_MSC_VER)
39 # define GLOBUS_DEPRECATED(func) __declspec(deprecated) func
41 # define GLOBUS_DEPRECATED(func) func
50 #define globus_macro_libc_lock() \
51 globus_mutex_lock(&globus_libc_mutex)
52 #define globus_macro_libc_unlock() \
53 globus_mutex_unlock(&globus_libc_mutex)
56 #define globus_libc_lock() globus_macro_libc_lock()
57 #define globus_libc_unlock() globus_macro_libc_unlock()
59 extern int globus_libc_lock(
void);
60 extern int globus_libc_unlock(
void);
64 # define globus_libc_va_copy(dest,src) \
66 #elif defined(__va_copy)
67 # define globus_libc_va_copy(dest,src) \
70 # define globus_libc_va_copy(dest,src) \
71 memcpy(&dest, &src, sizeof(va_list))
75 #define globus_stdio_lock globus_libc_lock
76 #define globus_stdio_unlock globus_libc_unlock
77 #define globus_libc_printf printf
78 #define globus_libc_fprintf fprintf
79 #define globus_libc_sprintf sprintf
80 #define globus_libc_vprintf vprintf
81 #define globus_libc_vfprintf vfprintf
82 #define globus_libc_vsprintf vsprintf
84 #if __STDC_VERSION__ >= 199901L
85 #define globus_libc_snprintf snprintf
86 #define globus_libc_vsnprintf vsnprintf
88 extern int globus_libc_snprintf(
char *s,
size_t n,
const char *format, ...);
89 extern int globus_libc_vsnprintf(
char *s,
size_t n,
const char *format,
97 #define globus_libc_open open
98 #define globus_libc_close close
99 #define globus_libc_read read
100 #define globus_libc_write write
101 #define globus_libc_umask umask
102 #define globus_libc_writev writev
103 #define globus_libc_fstat fstat
105 #define globus_libc_opendir opendir
106 #define globus_libc_telldir telldir
107 #define globus_libc_seekdir seekdir
108 #define globus_libc_rewinddir rewinddir
109 #define globus_libc_closedir closedir
110 #define globus_libc_getpwuid_r getpwuid_r
116 globus_libc_umask_win32(
119 # define globus_libc_open _open
120 # define globus_libc_close _close
121 # define globus_libc_read _read
122 # define globus_libc_write _write
123 # define globus_libc_umask globus_libc_umask_win32
124 # define globus_libc_writev(fd,iov,iovcnt) \
125 write(fd,iov[0].iov_base,iov[0].iov_len)
127 #if defined(TARGET_ARCH_CYGWIN) || defined(TARGET_ARCH_MINGW32)
128 #define globus_libc_opendir opendir
129 #define globus_libc_telldir telldir
130 #define globus_libc_seekdir seekdir
131 #define globus_libc_rewinddir rewinddir
132 #define globus_libc_closedir closedir
137 globus_libc_readdir_r(
139 struct dirent ** result);
144 #define globus_malloc(bytes) globus_libc_malloc(bytes)
145 #define globus_realloc(ptr,bytes) globus_libc_realloc(ptr,bytes)
146 #define globus_calloc(nobjs,bytes) globus_libc_calloc(nobjs,bytes)
147 #define globus_free(ptr) globus_libc_free(ptr)
149 #define globus_libc_malloc malloc
150 #define globus_libc_realloc realloc
151 #define globus_libc_calloc calloc
152 #define globus_libc_free free
153 #define globus_libc_alloca alloca
154 #define globus_libc_lseek lseek
157 int globus_libc_gethostname(
char *name,
int len);
158 int globus_libc_getpid(
void);
159 int globus_libc_fork(
void);
160 int globus_libc_usleep(
long usec);
161 double globus_libc_wallclock(
void);
164 extern int globus_libc_sprint_off_t(
char * s, globus_off_t off);
166 extern int globus_libc_scan_off_t(
char *s, globus_off_t *off,
int *consumed);
169 GLOBUS_DEPRECATED(
struct hostent *globus_libc_gethostbyname_r(
char *name,
170 struct hostent *result,
175 GLOBUS_DEPRECATED(
struct hostent *globus_libc_gethostbyaddr_r(
char *addr,
178 struct hostent *result,
183 #ifdef _POSIX_THREAD_SAFE_FUCTIONS
184 #define globus_libc_ctime_r(clock, buf, buflen) ctime_r(clock, buf)
185 #define globus_libc_localtime_r(timer, result) localtime_r(timer, result)
186 #define globus_libc_gmtime_r(timer, result) gmtime_r(timer, result)
188 char *globus_libc_ctime_r(time_t *clock,
char *buf,
int buflen);
189 struct tm * globus_libc_localtime_r(
const time_t *timep,
struct tm *result);
190 struct tm * globus_libc_gmtime_r(
const time_t *timep,
struct tm *result);
194 #define globus_libc_getpwnam_r getpwnam_r
198 globus_libc_strncasecmp(
203 int globus_libc_setenv(
register const char *name,
204 register const char *value,
206 void globus_libc_unsetenv(
register const char *name);
209 GLOBUS_DEPRECATED(
char *globus_libc_getenv(
register const char *name));
212 char *globus_libc_system_error_string(
int the_error);
215 globus_libc_strdup(
const char * source);
218 globus_libc_strndup(
const char *
string,
globus_size_t length);
225 #define globus_libc_strcmp strcmp
226 #define globus_libc_strlen strlen
234 globus_libc_vprintf_length(
const char * fmt, va_list ap);
237 globus_libc_printf_length(
const char * fmt, ...);
240 int globus_libc_gethomedir(
char *result,
int bufsize);
243 globus_common_create_string(
248 globus_common_create_nstring(
254 globus_common_v_create_string(
259 globus_common_v_create_nstring(
265 #define globus_libc_memmove(d, s, n) memmove((d), (s), (n))
268 # define globus_libc_setegid(a) setresgid(-1,a,-1)
269 # define globus_libc_seteuid(a) setresuid(-1,a,-1)
271 # define globus_libc_setegid(a) setegid(a)
272 # define globus_libc_seteuid(a) seteuid(a)
277 typedef struct sockaddr_storage globus_sockaddr_t;
278 typedef struct addrinfo globus_addrinfo_t;
281 #define GlobusLibcProtocolFamilyIsIP(family) \
282 ((family == AF_INET ? 1 : (family == AF_INET6 ? 1 : 0)))
284 #define GlobusLibcProtocolFamilyIsIP(family) \
285 (family == AF_INET ? 1 : 0)
289 #define PF_INET AF_INET
293 #define PF_UNSPEC AF_UNSPEC
296 #define GlobusLibcSockaddrSetFamily(_addr, fam) ((struct sockaddr *) &(_addr))->sa_family = fam
297 #define GlobusLibcSockaddrGetFamily(_addr) ((struct sockaddr *) &(_addr))->sa_family
300 #define GlobusLibcSockaddrGetPort(addr, port) \
303 const struct sockaddr * _addr = (struct sockaddr *) &(addr);\
305 switch(_addr->sa_family) \
308 (port) = ntohs(((struct sockaddr_in *) _addr)->sin_port); \
312 (port) = ntohs(((struct sockaddr_in6 *) _addr)->sin6_port); \
317 "Unknown family in GlobusLibcSockaddrGetPort"); \
323 #define GlobusLibcSockaddrGetPort(addr, port) \
326 const struct sockaddr * _addr = (struct sockaddr *) &(addr);\
328 switch(_addr->sa_family) \
331 (port) = ntohs(((struct sockaddr_in *) _addr)->sin_port); \
336 "Unknown family in GlobusLibcSockaddrGetPort"); \
344 #define GlobusLibcSockaddrSetPort(addr, port) \
347 struct sockaddr * _addr = (struct sockaddr *) &(addr);\
349 switch(_addr->sa_family) \
352 ((struct sockaddr_in *) _addr)->sin_port = htons((port)); \
356 ((struct sockaddr_in6 *) _addr)->sin6_port = htons((port)); \
361 "Unknown family in GlobusLibcSockaddrSetPort"); \
366 #define GlobusLibcSockaddrSetPort(addr, port) \
369 struct sockaddr * _addr = (struct sockaddr *) &(addr);\
371 switch(_addr->sa_family) \
374 ((struct sockaddr_in *) _addr)->sin_port = htons((port)); \
379 "Unknown family in GlobusLibcSockaddrSetPort"); \
386 #define GlobusLibcSockaddrSetLen(addr, len) \
389 struct sockaddr * _addr = (struct sockaddr *) &(addr);\
391 switch(_addr->sa_family) \
394 ((struct sockaddr_in *) _addr)->sin_len = (len); \
398 ((struct sockaddr_in6 *) _addr)->sin6_len = (len); \
403 "Unknown family in GlobusLibcSockaddrSetLen"); \
408 #define GlobusLibcSockaddrCopy(dest_addr, source_addr, source_len) \
409 (memcpy(&(dest_addr), &(source_addr), (source_len)))
411 #define GlobusLibcSockaddrLen(addr) \
412 (((struct sockaddr *) (addr))->sa_family == AF_INET \
413 ? sizeof(struct sockaddr_in) : \
414 (((struct sockaddr *) (addr))->sa_family == AF_INET6 \
415 ? sizeof(struct sockaddr_in6) : -1))
417 #define GLOBUS_AI_PASSIVE AI_PASSIVE
418 #define GLOBUS_AI_NUMERICHOST AI_NUMERICHOST
419 #define GLOBUS_AI_CANONNAME AI_CANONNAME
421 #define GLOBUS_NI_MAXHOST NI_MAXHOST
422 #define GLOBUS_NI_NOFQDN NI_NOFQDN
423 #define GLOBUS_NI_NAMEREQD NI_NAMEREQD
424 #define GLOBUS_NI_DGRAM NI_DGRAM
425 #define GLOBUS_NI_NUMERICSERV NI_NUMERICSERV
426 #define GLOBUS_NI_NUMERICHOST NI_NUMERICHOST
428 #define GLOBUS_EAI_ERROR_OFFSET 2048
430 #define GLOBUS_EAI_FAMILY (EAI_FAMILY + GLOBUS_EAI_ERROR_OFFSET)
431 #define GLOBUS_EAI_SOCKTYPE (EAI_SOCKTYPE + GLOBUS_EAI_ERROR_OFFSET)
432 #define GLOBUS_EAI_BADFLAGS (EAI_BADFLAGS + GLOBUS_EAI_ERROR_OFFSET)
433 #define GLOBUS_EAI_NONAME (EAI_NONAME + GLOBUS_EAI_ERROR_OFFSET)
434 #define GLOBUS_EAI_SERVICE (EAI_SERVICE + GLOBUS_EAI_ERROR_OFFSET)
435 #define GLOBUS_EAI_ADDRFAMILY (EAI_ADDRFAMILY + GLOBUS_EAI_ERROR_OFFSET)
436 #define GLOBUS_EAI_NODATA (EAI_NODATA + GLOBUS_EAI_ERROR_OFFSET)
437 #define GLOBUS_EAI_MEMORY (EAI_MEMORY + GLOBUS_EAI_ERROR_OFFSET)
438 #define GLOBUS_EAI_FAIL (EAI_FAIL + GLOBUS_EAI_ERROR_OFFSET)
439 #define GLOBUS_EAI_AGAIN (EAI_AGAIN + GLOBUS_EAI_ERROR_OFFSET)
440 #define GLOBUS_EAI_SYSTEM (EAI_SYSTEM + GLOBUS_EAI_ERROR_OFFSET)
443 globus_libc_getaddrinfo(
445 const char * service,
446 const globus_addrinfo_t * hints,
447 globus_addrinfo_t ** res);
450 globus_libc_freeaddrinfo(
451 globus_addrinfo_t * res);
454 globus_libc_getnameinfo(
455 const globus_sockaddr_t * addr,
463 globus_libc_addr_is_loopback(
464 const globus_sockaddr_t * addr);
467 globus_libc_addr_is_wildcard(
468 const globus_sockaddr_t * addr);
471 #define GLOBUS_LIBC_ADDR_NUMERIC 1
473 #define GLOBUS_LIBC_ADDR_LOCAL 2
475 #define GLOBUS_LIBC_ADDR_IPV6 4
477 #define GLOBUS_LIBC_ADDR_IPV4 8
483 globus_libc_addr_to_contact_string(
484 const globus_sockaddr_t * addr,
486 char ** contact_string);
490 globus_libc_addr_convert_family(
491 const globus_sockaddr_t * src,
492 globus_sockaddr_t * dest,
496 globus_libc_contact_string_to_ints(
497 const char * contact_string,
500 unsigned short * port);
508 globus_libc_ints_to_contact_string(
511 unsigned short port);
514 globus_libc_gethostaddr(
515 globus_sockaddr_t * addr);
518 globus_libc_gethostaddr_by_family(
519 globus_sockaddr_t * addr,