getgrnam_r buffer set too small?

int getgrnam_r(const char *name, struct group *grp,
          char *buf, size_t buflen, struct group **result);
的bufsize 应该多大?

struct group {
    char   *gr_name;       /* group name */
    char   *gr_passwd;     /* group password */
    gid_t   gr_gid;        /* group ID */
    char  **gr_mem;        /* group members */
};

关于getgrnam_r 的说明:

 The string fields pointed to by the members of the group structure are stored in the buffer buf of size buflen. A pointer to the result (in case of success) or NULL (in case no entry was found or an error occurred) is stored in *result.

returns either -1, without changing errno, or an initial suggested size for buf. (If this size is too small, the call fails with ERANGE is ., Case in Which the retry The Caller CAN with Buffer A larger)

size that can accommodate the needs of buf gr_name, gr_passwd, gr_mem three parts;
gr_mem is necessary to store the group membership,



Guess you like

Origin www.cnblogs.com/mu-zhang/p/11572884.html