Globus Common: Globus_libc Function Reference
Overview
Globus libc provides a thread-safe, portable, interface to common 'libc' functionality.Globus libc provides thread-safe functions for file and directory I/O, environment querying/setting, host resolution, and password querying. It relies on the globus_threads thread interface.
The return codes from these functions are the return codes from the underlying system calls. Some of these functions may set variable errno.
Functions
int
globus_libc_lock(void);
This function locks the mutex used by globus libc for coordinating accesses
to non-reentrant libc functions. This can be used to call unsafe libc functions
which do not have a globus_libc interface.int
globus_libc_unlock(void);This function unlocks the mutex used by globus_libc
for coordinating accesses to non-reentrant libc functions. This can be used
to call unsafe libc functions which do not have a globus_libc interface.int
globus_libc_printf(const char *format, ...);Thread-safe printf.int
globus_libc_fprintf(FILE *strm,
const
char *format,
...);Thread-safe
printf.int
globus_libc_sprintf(char *s,
const
char *format,
...);Thread-safe
sprintf.
int
globus_libc_vprintf(const char *format,
va_list
ap);Thread-safe vprintf.
int
globus_libc_vfprintf(FILE *strm,
const
char *format,
va_list
ap);Thread-safe vfprintf.
int
globus_libc_vsprintf(char *s,
const
char *format,
va_list
ap);Thread-safe vsprintf.int
globus_libc_open(char *path,
int
flags,
...
/* int mode */);Thread-safe file descriptor open. Open file located at path.int
globus_libc_close(int fd);Thread-safe file descriptor close.
int
globus_libc_read(int fd,
char
*buf,
int
nbytes);Thread-safe file descriptor read.
int
globus_libc_write(int fd,
char
*buf,
int
nbytes);Thread-safe file descriptor write.int
globus_libc_fstat(int fd,
struct
stat *buf);Thread-safe file descriptor stat.
int
globus_libc_lseek(int fd,
off_t
offset,
int
whence);Thread-safe file descriptor lseek.DIR *
globus_libc_opendir(char *filename);Thread-safe, portable opendir.
long
globus_libc_telldir(DIR *dirp);Thread-safe, portable telldir.
void
globus_libc_seekdir(DIR *dirp,
long
loc);Thread-safe, portable seekdir.
void globus_libc_rewinddir(DIR *dirp);Thread-safe, portable rewinddir.
void
globus_libc_closedir(DIR *dirp);Thread-safe, portable closedir.int
globus_libc_readdir_r(DIR *dirp,
struct
dirent **result);Thread-safe, portable, readdir. The globus_libc_readdir_r function
allocates the result using globus_libc_malloc. This structure should be deallocated
by the user by calling globus_libc_free on the result pointer.void *
globus_libc_malloc(size_t bytes);Thread-safe malloc.
void *
globus_libc_realloc(void *ptr,
size_t
bytes);Thread-safe realloc.
void *
globus_libc_calloc(size_t nobj,
size_t
bytes);Thread-safe calloc.
void
globus_libc_free(void *ptr)Thread-safe free.int
globus_libc_gethostname(char *name,
int
len);Thread-safe gethostname. This function attempts several methods to return
a fully-qualified domain name.
int
globus_libc_getpid(void);Thread-safe getpid.
int
globus_libc_fork(void);Thread-safe fork. Forks only the calling thread.int
globus_libc_usleep(long usec);Thread-safe sleep for usec microseconds.
double
globus_libc_wallclock(void);Returns the current time in seconds and microseconds
from 1 Jan 1970.
struct hostent *
globus_libc_gethostbyname_r(char *name,
struct
hostent *result,
char
*buffer,
int
buflen,
int
*h_errnop);Thread-safe, portable gethostbyname.struct hostent *
globus_libc_gethostbyaddr_r(char *addr,
int
length,
int
type,
struct
hostent *result,
char
*buffer,
int
buflen,
int
*h_errnop);Thread-safe, portable gethostbyaddr.
char *
globus_libc_ctime_r(time_t *clock,
char
*buf,
int
buflen);Thread-safe ctime.int
globus_libc_getpwnam_r(char *name,
struct
passwd *pwd,
char
*buffer,
int
bufsize,
struct
passwd **result);Thread-safe, portable getpwnam.
int
globus_libc_getpwuid_r(uid_t uid,
struct
passwd *pwd,
char
*buffer,
int
bufsize,
struct
passwd **result);Thread-safe, portable getpwuid.
int
globus_libc_setenv(register const char *name,
register
const char *value,
int
rewrite);Thread-safe setenv.
void
globus_libc_unsetenv(register const char *name);Thread-safe unsetenv.
char *
globus_libc_getenv(register const char *name);Thread-safe getenv.
char *
globus_libc_system_error_string(int the_error);
Translate the error code to a system error string.