libexplain
1.4.D001
|
00001 /* 00002 * libexplain - a library of system-call-specific strerror replacements 00003 * Copyright (C) 2013 Peter Miller 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU Lesser General Public License as 00007 * published by the Free Software Foundation; either version 3 of the 00008 * License, or (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Lesser General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Lesser General Public License 00016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00017 */ 00018 00019 #include <libexplain/ac/acl/libacl.h> 00020 #include <libexplain/ac/errno.h> 00021 00022 #include <libexplain/buffer/acl.h> 00023 #include <libexplain/buffer/pointer.h> 00024 #include <libexplain/is_efault.h> 00025 00026 00027 void 00028 explain_buffer_acl(explain_string_buffer_t *sb, acl_t acl) 00029 { 00030 const char *text = 0; 00031 int errno_hold; 00032 00033 if (acl == (acl_t)NULL) 00034 { 00035 explain_string_buffer_puts(sb, "NULL"); 00036 return; 00037 } 00038 00039 /* 00040 * The acl_to_any_text and the acl_to_text functions will 00041 * frequently clobber errno, because it uses numerous system 00042 * calls (e.g. looking up user names and group names). 00043 */ 00044 errno_hold = errno; 00045 00046 if (explain_is_efault_pointer(acl, sizeof(void *))) 00047 { 00048 barf: 00049 explain_buffer_pointer(sb, acl); 00050 errno = errno_hold; 00051 return; 00052 } 00053 if (acl_valid(acl) < 0) 00054 goto barf; 00055 00056 #ifdef HAVE_ACL_TO_ANY_TEXT 00057 { 00058 int options = TEXT_ABBREVIATE; 00059 text = acl_to_any_text(acl, NULL, ' ', options); 00060 } 00061 #else 00062 { 00063 ssize_t len = 0; 00064 text = acl_to_text(acl, &len); 00065 } 00066 #endif 00067 if (!text) 00068 goto barf; 00069 explain_string_buffer_puts_quoted(sb, text); 00070 acl_free((void *)text); 00071 errno = errno_hold; 00072 } 00073 00074 00075 /* vim: set ts=8 sw=4 et : */