{"id":5483,"date":"2022-12-20T18:45:15","date_gmt":"2022-12-20T21:45:15","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/getgrgid-man3p\/"},"modified":"2022-12-20T18:45:15","modified_gmt":"2022-12-20T21:45:15","slug":"getgrgid-man3p","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/getgrgid-man3p\/","title":{"rendered":"GETGRGID (man3p)"},"content":{"rendered":"<h1 align=\"center\">GETGRGID<\/h1>\n<p> <a href=\"#PROLOG\">PROLOG<\/a><br \/> <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=\"#EXAMPLES\">EXAMPLES<\/a><br \/> <a href=\"#APPLICATION USAGE\">APPLICATION USAGE<\/a><br \/> <a href=\"#RATIONALE\">RATIONALE<\/a><br \/> <a href=\"#FUTURE DIRECTIONS\">FUTURE DIRECTIONS<\/a><br \/> <a href=\"#SEE ALSO\">SEE ALSO<\/a><br \/> <a href=\"#COPYRIGHT\">COPYRIGHT<\/a> <\/p>\n<hr>\n<h2>PROLOG <a name=\"PROLOG\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">This manual page is part of the POSIX Programmer\u2019s Manual. The Linux implementation of this interface may differ (consult the corresponding Linux manual page for details of Linux behavior), or the interface may not be implemented on Linux.<\/p>\n<h2>NAME <a name=\"NAME\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">getgrgid, getgrgid_r \u2014 get group database entry for a group ID<\/p>\n<h2>SYNOPSIS <a name=\"SYNOPSIS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">#include <grp.h><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">struct group *getgrgid(gid_t <i>gid<\/i>); <br \/> int getgrgid_r(gid_t <i>gid<\/i>, struct group *<i>grp<\/i>, char *<i>buffer<\/i>, <br \/> size_t <i>bufsize<\/i>, struct group **<i>result<\/i>);<\/p>\n<h2>DESCRIPTION <a name=\"DESCRIPTION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>getgrgid<\/i>() function shall search the group database for an entry with a matching <i>gid<\/i>.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>getgrgid<\/i>() function need not be thread-safe.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Applications wishing to check for error situations should set <i>errno<\/i> to 0 before calling <i>getgrgid<\/i>(). If <i>getgrgid<\/i>() returns a null pointer and <i>errno<\/i> is set to non-zero, an error occurred.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>getgrgid_r<\/i>() function shall update the <b>group<\/b> structure pointed to by <i>grp<\/i> and store a pointer to that structure at the location pointed to by <i>result<\/i>. The structure shall contain an entry from the group database with a matching <i>gid<\/i>. Storage referenced by the group structure is allocated from the memory provided with the <i>buffer<\/i> parameter, which is <i>bufsize<\/i> bytes in size. A call to <i>sysconf<\/i>(_SC_GETGR_R_SIZE_MAX) returns either \u22121 without changing <i>errno<\/i> or an initial value suggested for the size of this buffer. A null pointer shall be returned at the location pointed to by <i>result<\/i> on error or if the requested entry is not found.<\/p>\n<h2>RETURN VALUE <a name=\"RETURN VALUE\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Upon successful completion, <i>getgrgid<\/i>() shall return a pointer to a <b>struct group<\/b> with the structure defined in <i><grp.h><\/i> with a matching entry if one is found. The <i>getgrgid<\/i>() function shall return a null pointer if either the requested entry was not found, or an error occurred. If the requested entry was not found, <i>errno<\/i> shall not be changed. On error, <i>errno<\/i> shall be set to indicate the error.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The application shall not modify the structure to which the return value points, nor any storage areas pointed to by pointers within the structure. The returned pointer, and pointers within the structure, might be invalidated or the structure or the storage areas might be overwritten by a subsequent call to <i>getgrent<\/i>(), <i>getgrgid<\/i>(), or <i>getgrnam<\/i>(). The returned pointer, and pointers within the structure, might also be invalidated if the calling thread is terminated.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">If successful, the <i>getgrgid_r<\/i>() function shall return zero; otherwise, an error number shall be returned to indicate the error.<\/p>\n<h2>ERRORS <a name=\"ERRORS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>getgrgid<\/i>() and <i>getgrgid_r<\/i>() functions may fail if:<\/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>EIO<\/b><\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"78%\">\n<p>An I\/O error has occurred.<\/p>\n<\/td>\n<\/tr>\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 during <i>getgrgid<\/i>().<\/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>All file descriptors available to the process are currently open.<\/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 maximum allowable number of files is currently open in the system.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>getgrgid_r<\/i>() function may fail if:<\/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 style=\"margin-top: 1em\"><b>ERANGE<\/b><\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"78%\">\n<p style=\"margin-top: 1em\">Insufficient storage was supplied via <i>buffer<\/i> and <i>bufsize<\/i> to contain the data to be referenced by the resulting <b>group<\/b> structure.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%; margin-top: 1em\"><i>The following sections are informative.<\/i><\/p>\n<h2>EXAMPLES <a name=\"EXAMPLES\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Note that <i>sysconf<\/i>(_SC_GETGR_R_SIZE_MAX) may return \u22121 if there is no hard limit on the size of the buffer needed to store all the groups returned. This example shows how an application can allocate a buffer of sufficient size to work with <i>getgrid_r<\/i>().<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">long int initlen = sysconf(_SC_GETGR_R_SIZE_MAX); <br \/> size_t len; <br \/> if (initlen == -1) <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 Default initial length. bodies\/ usr\/ <br \/> len = 1024; <br \/> else <br \/> len = (size_t) initlen; <br \/> struct group result; <br \/> struct group *resultp; <br \/> char *buffer = malloc(len); <br \/> if (buffer == NULL) <br \/> &#8230;handle error&#8230; <br \/> int e; <br \/> while ((e = getgrgid_r(42, &#038;result, buffer, len, &#038;resultp)) == ERANGE) <br \/> { <br \/> size_t newlen = 2 bodies manpages.csv script_extrae_body.sh script.sh usr len; <br \/> if (newlen < len) <br \/> &#8230;handle error&#8230; <br \/> len = newlen; <br \/> char *newbuffer = realloc(buffer, len); <br \/> if (newbuffer == NULL) <br \/> &#8230;handle error&#8230; <br \/> buffer = newbuffer; <br \/> } <br \/> if (e != 0) <br \/> &#8230;handle error&#8230; <br \/> free (buffer);<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>Finding an Entry in the Group Database<\/b> <br \/> The following example uses <i>getgrgid<\/i>() to search the group database for a group ID that was previously stored in a <b>stat<\/b> structure, then prints out the group name if it is found. If the group is not found, the program prints the numeric value of the group for the entry.<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">#include <sys\/types.h> <br \/> #include <grp.h> <br \/> #include <stdio.h> <br \/> &#8230; <br \/> struct stat statbuf; <br \/> struct group *grp; <br \/> &#8230; <br \/> if ((grp = getgrgid(statbuf.st_gid)) != NULL) <br \/> printf(&#8221; %-8.8s&#8221;, grp->gr_name); <br \/> else <br \/> printf(&#8221; %-8d&#8221;, statbuf.st_gid); <br \/> &#8230;<\/p>\n<h2>APPLICATION USAGE <a name=\"APPLICATION USAGE\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>getgrgid_r<\/i>() function is thread-safe and shall return values in a user-supplied buffer instead of possibly using a static data area that may be overwritten by each call.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Portable applications should take into account that it is usual for an implementation to return \u22121 from <i>sysconf<\/i>() indicating that there is no maximum for _SC_GETGR_R_SIZE_MAX.<\/p>\n<h2>RATIONALE <a name=\"RATIONALE\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">None.<\/p>\n<h2>FUTURE DIRECTIONS <a name=\"FUTURE DIRECTIONS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">None.<\/p>\n<h2>SEE ALSO <a name=\"SEE ALSO\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><i>endgrent<\/i>(), <i>getgrnam<\/i>(), <i>sysconf<\/i>()<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The Base Definitions volume of POSIX.1-2017, <b><grp.h><\/b>, <b><sys_types.h><\/b><\/p>\n<h2>COPYRIGHT <a name=\"COPYRIGHT\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology &#8212; Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http:\/\/www.opengroup.org\/unix\/online.html .<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https:\/\/www.kernel.org\/doc\/man-pages\/reporting_bugs.html .<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>  getgrgid, getgrgid_r \u2014 get group database entry for a group ID <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3779,1],"tags":[2370,1594],"class_list":["post-5483","post","type-post","status-publish","format-standard","hentry","category-3pm-perl-llamadas-de-bibliotecas","category-sin-categoria","tag-getgrgid","tag-man3p"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/5483","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=5483"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/5483\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=5483"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=5483"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=5483"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}