Related Re-entrant Functions

A number of functions covered in this chapter so far have re-entrant counterparts on some platforms. For example, the function synopsis for getgrnam_r(3C) under IRIX 6.5 is as follows:

#include <stdio.h>
#include <grp.h>
#include <sys/types.h>

int getgrnam_r(const char *name,  /* Group name to search */
    struct group *grent,          /* Used for storage */
    char *buffer,                 /* Used for storage */
    int bufsize,                  /* Size of buffer in bytes */
    struct group **grp);          /* Pointer to return pointer */

To be re-entrant, the caller must supply the function with all of its needs. In the case of getgrnam_r(3C) shown, argument grent and buffer are two storage areas that are provided to the function for its own internal use. The buffer points to an I/O buffer, and it is suggested to be BUFSIZ bytes in size. The last argument, grp, is a pointer to a pointer, which is used to return the group structure pointer of interest.

Most of the re-entrant functions work similarly to this one. These functions are preferred when they are available, because they permit multithreaded code to be used. Check the man(1) pages by appending the characters _r to the normal function name to see if you have documentation and support for them.

Note

At the time of this writing, FreeBSD and Linux do not support re-entrant functions such as getgrnam_r(3) for password and group files.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.224.73.125