getgrnam_r 的缓冲区设置太小?

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, in which case the caller can retry with a larger buffer.)

buf 的大小需要可以容纳 gr_name, gr_passwd, gr_mem 三部分内容;
gr_mem 是需要存储组成员的,



posted @ 2019-09-23 16:08  you_magic  阅读(449)  评论(0编辑  收藏  举报