Книга: Programming with POSIX® Threads

9.3.11 Thread-safe functions

9.3.11 Thread-safe functions

Thread-safe functions provide improved access to traditional features of ANSI C and POSIX that cannot be effectively made thread-safe without interface changes. These routines are designated by the "_r" suffix added to the traditional function name they replace, for example, getlogin_r for getlogin.

getlogin_r

int getlogin_r (

char *name,

size_t namesize);

Write the user name associated with the current process into the buffer pointed to by name. The buffer is namesize bytes long, and should have space for the name and a terminating null character. The maximum size of the login name is LOGIN_

NAME_MAX.

References: 6.5.1 Headers: <unistd.h>

readdir_r

int readdir_r (

DIR *dirp,

struct dirent *entry, struct dirent **result);

Return a pointer (result) to the directory entry at the current position in the directory stream to which dirp refers. Whereas readdir retains the current position using a static variable, readdir_r uses the entry parameter, supplied by the caller.

References: 6.5.2

Headers: <sys/types.h>, <dirent.h>

Errors: [EBADF] dirp is not an open directory stream.

strtok_r

char *strtok_r (

char *s,

const char *sep,

char **lasts);

Return a pointer to the next token in the strings. Whereas strtok retains the current position within a string using a static variable, strtok_r uses the lasts parameter, supplied by the caller.

References: 6.5.3 Headers: <string.h>

asctime_r

char *asctime_r (

const struct tm*tm,

char *buf);

Convert the "broken-down" time in the structure pointed to by tm into a string, which is stored in the buffer pointed to by buf. The buffer pointed to by buf must

contain at least 26 bytes. The function returns a pointer to the buffer on success, or NULL on failure.

References: 6.5.4 Headers: <time.h>

ctime_r

char *ctime_r (

const time_t *clock, char *buf);

Convert the calendar time pointed to by clock into a string representing the local time, which is stored in the buffer pointed to by buf. The buffer pointed to by buf must contain at least 26 bytes. The function returns a pointer to the buffer on success, or NULL on failure.

References: 6.5.4 Headers: <time.h>

gmtime_r

struct tm *gmtime_r (

const time_t *clock, struct tm *result);

Convert the calendar time pointed to by clock into a "broken-down time" expressed as Coordinated Universal Time (UTC), which is stored in the structure pointed to by result. The function returns a pointer to the structure on success, or NULL on failure.

References: 6.5.4 Headers: <time.h>

localtime_r

struct tm *localtime_r (

const time_t *clock, struct tm *result);

Convert the calendar time pointed to by clock into a "broken-down time" expressed as local time, which is stored in the structure pointed to by result. The function returns a pointer to the structure on success, or NULL on failure.

References: 6.5.4 Headers: <time.h>

rand_r

int rand_r (

unsigned int *seed);

Return the next value in a sequence of pseudorandom integers in the range of 0 to RAND_MAX. Whereas rand uses a static variable to maintain the context between a series of calls, rand_r uses the value pointed to by seed, which is supplied by the caller.

References: 6.5.5 Headers: <stdlib.h>

getgrgid_r

int getgrgid_r (

gid_t gid,

struct group *group,

char *buffer,

size_t bufsize,

struct group **result);

Locate an entry from the group database with a group id matching the gid argument. The group entry is stored in the memory pointed to by buffer, which contains bufsize bytes, and a pointer to the entry is stored at the address pointed to by result. The maximum buffer size required can be determined by calling sysconf with the _SC_GETGR_R_SIZE_MAX parameter.

References: 6.5.6

Headers: <sys/types.h>,<grp.h>

Errors: [ERANGE] the specified buffer is too small.

| getgrnam

r

int getgrnam_r (

const char *name,

struct group *group,

char *buffer,

size_t bufsize,

struct group **result);

Locate an entry from the group database with a group name matching the name argument. The group entry is stored in the memory pointed to by buffer, which contains bufsize bytes, and a pointer to the entry is stored at the address pointed to by result. The maximum buffer size required can be determined by calling sysconf with the _SC_GETGR_R_SIZE_MAX parameter.

References: 6.5.6 Headers: <sys/types.h>, <grp.h>

Errors: [ERANGE] the specified buffer is too small.

getpwuid_r

int getpwuid_r (

uid_t uid,

struct passwd *pwd,

char *buffer,

size_t bufsize,

struct passwd **result);

Locate an entry from the user database with a user id matching the uid argument. The user entry is stored in the memory pointed to by buffer, which contains bufsize bytes, and a pointer to the entry is stored at the address pointed to by result. The maximum buffer size required can be determined by calling sysconf with the _SC_GETPW_R_SIZE_MAX parameter.

References: 6.5.6

Headers: <sys/types.h>, <pwd.h>

Errors: [ERANGE ] the specified buffer is too small.

getpwnam_r

int getpwnam_r (

const char *name,

struct passwd *pwd,

char *buffer,

size_t bufsize,

struct passwd **result);

Locate an entry from the user database with a user name matching the name argument. The user entry is stored in the memory pointed to by buffer, which contains bufsize bytes, and a pointer to the entry is stored at the address pointed to by result. The maximum buffer size required can be determined by calling sysconf with the _SC_GETPW_R_SIZE_MAX parameter.

References: 6.5.6

Headers: <sys/types.h>, <pwd.h>

Errors: [ERANGE] the specified buffer is too small.

Оглавление книги


Генерация: 0.077. Запросов К БД/Cache: 0 / 3
поделиться
Вверх Вниз