libexplain
1.4.D001
|
00001 /* 00002 * libexplain - Explain errno values returned by libc functions 00003 * Copyright (C) 2008-2013 Peter Miller 00004 * Written by Peter Miller <pmiller@opensource.org.au> 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU Lesser General Public License as 00008 * published by the Free Software Foundation; either version 3 of the 00009 * License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public License 00017 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00018 */ 00019 00020 #include <libexplain/ac/grp.h> 00021 #include <libexplain/ac/limits.h> /* for NGROUPS_MAX on Solaris */ 00022 #include <libexplain/ac/sys/param.h> 00023 #include <libexplain/ac/unistd.h> 00024 00025 #include <libexplain/buffer/gid.h> 00026 #include <libexplain/buffer/int.h> 00027 #include <libexplain/buffer/long.h> 00028 #include <libexplain/option.h> 00029 00030 00031 void 00032 explain_buffer_gid(explain_string_buffer_t *sb, gid_t gid) 00033 { 00034 if (sizeof(gid_t) <= sizeof(int)) 00035 explain_buffer_int(sb, gid); 00036 else 00037 explain_buffer_long(sb, gid); 00038 00039 if (explain_option_dialect_specific()) 00040 { 00041 struct group *gr; 00042 00043 gr = getgrgid(gid); 00044 if (gr) 00045 { 00046 explain_string_buffer_putc(sb, ' '); 00047 explain_string_buffer_puts_quoted(sb, gr->gr_name); 00048 } 00049 } 00050 } 00051 00052 00053 void 00054 explain_buffer_gid_supplementary(explain_string_buffer_t *sb) 00055 { 00056 gid_t groups[NGROUPS_MAX]; 00057 int n; 00058 int j; 00059 00060 n = getgroups(NGROUPS_MAX, groups); 00061 for (j = 0; j < n; ++j) 00062 { 00063 if (j) 00064 explain_string_buffer_putc(sb, ','); 00065 explain_string_buffer_putc(sb, ' '); 00066 explain_buffer_gid(sb, groups[j]); 00067 } 00068 } 00069 00070 00071 /* vim: set ts=8 sw=4 et : */