{"id":6657,"date":"2022-12-20T19:19:37","date_gmt":"2022-12-20T22:19:37","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/getgrnam-man3\/"},"modified":"2022-12-20T19:19:37","modified_gmt":"2022-12-20T22:19:37","slug":"getgrnam-man3","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/getgrnam-man3\/","title":{"rendered":"GETGRNAM (man3)"},"content":{"rendered":"<h1 align=\"center\">GETGRNAM<\/h1>\n<p> <a href=\"#NAME\">NAME<\/a><br \/> <a href=\"#SYNOPSIS\">SYNOPSIS<\/a><br \/> <a href=\"#DESCRIPTION\">DESCRIPTION<\/a><br \/> <a href=\"#RETURN VALUE\">RETURN VALUE<\/a><br \/> <a href=\"#ERRORS\">ERRORS<\/a><br \/> <a href=\"#FILES\">FILES<\/a><br \/> <a href=\"#ATTRIBUTES\">ATTRIBUTES<\/a><br \/> <a href=\"#CONFORMING TO\">CONFORMING TO<\/a><br \/> <a href=\"#NOTES\">NOTES<\/a><br \/> <a href=\"#SEE ALSO\">SEE ALSO<\/a><br \/> <a href=\"#COLOPHON\">COLOPHON<\/a> <\/p>\n<hr>\n<h2>NAME <a name=\"NAME\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">getgrnam, getgrnam_r, getgrgid, getgrgid_r \u2212 get group file entry<\/p>\n<h2>SYNOPSIS <a name=\"SYNOPSIS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>#include <sys\/types.h> <br \/> #include <grp.h><\/b><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>struct group *getgrnam(const char *<\/b><i>name<\/i><b>);<\/b><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>struct group *getgrgid(gid_t<\/b> <i>gid<\/i><b>);<\/b><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>int getgrnam_r(const char *<\/b><i>name<\/i><b>, struct group *<\/b><i>grp<\/i><b>, <br \/> char *<\/b><i>buf<\/i><b>, size_t<\/b> <i>buflen<\/i><b>, struct group **<\/b><i>result<\/i><b>);<\/b><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>int getgrgid_r(gid_t<\/b> <i>gid<\/i><b>, struct group *<\/b><i>grp<\/i><b>, <br \/> char *<\/b><i>buf<\/i><b>, size_t<\/b> <i>buflen<\/i><b>, struct group **<\/b><i>result<\/i><b>);<\/b><\/p>\n<p style=\"margin-left:5%; margin-top: 1em\">Feature Test Macro Requirements for glibc (see <b>feature_test_macros<\/b>(7)):<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>getgrnam_r<\/b>(), <b>getgrgid_r<\/b>():<\/p>\n<p style=\"margin-left:17%;\">_POSIX_C_SOURCE <br \/> || \/bin \/boot \/dead.letter \/dev \/etc \/home \/initrd \/lib \/lib64 \/lost+found \/media \/mnt \/opt \/proc \/release-notes.html \/release-notes.txt \/root \/run \/sbin \/srv \/sys \/tmp \/usr \/var Glibc versions <= 2.19: bodies\/ usr\/ _BSD_SOURCE || _SVID_SOURCE<\/p>\n<h2>DESCRIPTION <a name=\"DESCRIPTION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The <b>getgrnam<\/b>() function returns a pointer to a structure containing the broken-out fields of the record in the group database (e.g., the local group file <i>\/etc\/group<\/i>, NIS, and LDAP) that matches the group name <i>name<\/i>.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The <b>getgrgid<\/b>() function returns a pointer to a structure containing the broken-out fields of the record in the group database that matches the group ID <i>gid<\/i>.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>group<\/i> structure is defined in <i><grp.h><\/i> as follows:<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">struct group { <br \/> char *gr_name; \/bin \/boot \/dead.letter \/dev \/etc \/home \/initrd \/lib \/lib64 \/lost+found \/media \/mnt \/opt \/proc \/release-notes.html \/release-notes.txt \/root \/run \/sbin \/srv \/sys \/tmp \/usr \/var group name bodies\/ usr\/ <br \/> char *gr_passwd; \/bin \/boot \/dead.letter \/dev \/etc \/home \/initrd \/lib \/lib64 \/lost+found \/media \/mnt \/opt \/proc \/release-notes.html \/release-notes.txt \/root \/run \/sbin \/srv \/sys \/tmp \/usr \/var group password bodies\/ usr\/ <br \/> gid_t gr_gid; \/bin \/boot \/dead.letter \/dev \/etc \/home \/initrd \/lib \/lib64 \/lost+found \/media \/mnt \/opt \/proc \/release-notes.html \/release-notes.txt \/root \/run \/sbin \/srv \/sys \/tmp \/usr \/var group ID bodies\/ usr\/ <br \/> char **gr_mem; \/bin \/boot \/dead.letter \/dev \/etc \/home \/initrd \/lib \/lib64 \/lost+found \/media \/mnt \/opt \/proc \/release-notes.html \/release-notes.txt \/root \/run \/sbin \/srv \/sys \/tmp \/usr \/var NULL-terminated array of pointers <br \/> to names of group members bodies\/ usr\/ <br \/> };<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">For more information about the fields of this structure, see <b>group<\/b>(5).<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The <b>getgrnam_r<\/b>() and <b>getgrgid_r<\/b>() functions obtain the same information as <b>getgrnam<\/b>() and <b>getgrgid<\/b>(), but store the retrieved <i>group<\/i> structure in the space pointed to by <i>grp<\/i>. The string fields pointed to by the members of the <i>group<\/i> structure are stored in the buffer <i>buf<\/i> of size <i>buflen<\/i>. A pointer to the result (in case of success) or NULL (in case no entry was found or an error occurred) is stored in <i>*result<\/i>.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The call<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">sysconf(_SC_GETGR_R_SIZE_MAX)<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">returns either \u22121, without changing <i>errno<\/i>, or an initial suggested size for <i>buf<\/i>. (If this size is too small, the call fails with <b>ERANGE<\/b>, in which case the caller can retry with a larger buffer.)<\/p>\n<h2>RETURN VALUE <a name=\"RETURN VALUE\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The <b>getgrnam<\/b>() and <b>getgrgid<\/b>() functions return a pointer to a <i>group<\/i> structure, or NULL if the matching entry is not found or an error occurs. If an error occurs, <i>errno<\/i> is set appropriately. If one wants to check <i>errno<\/i> after the call, it should be set to zero before the call.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The return value may point to a static area, and may be overwritten by subsequent calls to <b>getgrent<\/b>(3), <b>getgrgid<\/b>(), or <b>getgrnam<\/b>(). (Do not pass the returned pointer to <b>free<\/b>(3).)<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">On success, <b>getgrnam_r<\/b>() and <b>getgrgid_r<\/b>() return zero, and set <i>*result<\/i> to <i>grp<\/i>. If no matching group record was found, these functions return 0 and store NULL in <i>*result<\/i>. In case of error, an error number is returned, and NULL is stored in <i>*result<\/i>.<\/p>\n<h2>ERRORS <a name=\"ERRORS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>0<\/b> or <b>ENOENT<\/b> or <b>ESRCH<\/b> or <b>EBADF<\/b> or <b>EPERM<\/b> or &#8230;<\/p>\n<p style=\"margin-left:22%;\">The given <i>name<\/i> or <i>gid<\/i> was not found.<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"9%\">\n<p><b>EINTR<\/b><\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"78%\">\n<p>A signal was caught; see <b>signal<\/b>(7).<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"9%\">\n<p><b>EIO<\/b><\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"78%\">\n<p>I\/O error.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"9%\">\n<p><b>EMFILE<\/b><\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"78%\">\n<p>The per-process limit on the number of open file descriptors has been reached.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"9%\">\n<p><b>ENFILE<\/b><\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"78%\">\n<p>The system-wide limit on the total number of open files has been reached.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"9%\">\n<p><b>ENOMEM<\/b><\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"78%\">\n<p>Insufficient memory to allocate <i>group<\/i> structure.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"9%\">\n<p><b>ERANGE<\/b><\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"78%\">\n<p>Insufficient buffer space supplied.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<h2>FILES <a name=\"FILES\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><i>\/etc\/group<\/i><\/p>\n<p style=\"margin-left:22%;\">local group database file<\/p>\n<h2>ATTRIBUTES <a name=\"ATTRIBUTES\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">For an explanation of the terms used in this section, see <b>attributes<\/b>(7).<\/p>\n<p align=\"center\" style=\"margin-top: 1em\"><img decoding=\"async\" src=\"grohtml-1657501.png\" alt=\"Image grohtml-1657501.png\"><\/p>\n<h2>CONFORMING TO <a name=\"CONFORMING TO\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">POSIX.1-2001, POSIX.1-2008, SVr4, 4.3BSD.<\/p>\n<h2>NOTES <a name=\"NOTES\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The formulation given above under &#8220;RETURN VALUE&#8221; is from POSIX.1. It does not call &#8220;not found&#8221; an error, hence does not specify what value <i>errno<\/i> might have in this situation. But that makes it impossible to recognize errors. One might argue that according to POSIX <i>errno<\/i> should be left unchanged if an entry is not found. Experiments on various UNIX-like systems show that lots of different values occur in this situation: 0, ENOENT, EBADF, ESRCH, EWOULDBLOCK, EPERM, and probably others.<\/p>\n<h2>SEE ALSO <a name=\"SEE ALSO\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>endgrent<\/b>(3), <b>fgetgrent<\/b>(3), <b>getgrent<\/b>(3), <b>getpwnam<\/b>(3), <b>setgrent<\/b>(3), <b>group<\/b>(5)<\/p>\n<h2>COLOPHON <a name=\"COLOPHON\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">This page is part of release 5.10 of the Linux <i>man-pages<\/i> project. A description of the project, information about reporting bugs, and the latest version of this page, can be found at https:\/\/www.kernel.org\/doc\/man\u2212pages\/.<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>  getgrnam, getgrnam_r, getgrgid, getgrgid_r \u2212 get group file entry <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2536],"tags":[2538,1934,3007],"class_list":["post-6657","post","type-post","status-publish","format-standard","hentry","category-3-llamadas-de-bibliotecas","tag-2538","tag-getgrnam","tag-man3"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/6657","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/comments?post=6657"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/6657\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=6657"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=6657"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=6657"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}