lisp/ChangeLog: Fix a recent log entry.
[emacs.git] / lib / acl_entries.c
blob39d6b28fe8a4241dc8fa46a4fa33ab37d4e65809
1 /* Return the number of entries in an ACL.
3 Copyright (C) 2002-2003, 2005-2014 Free Software Foundation, Inc.
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 Written by Paul Eggert and Andreas Gruenbacher. */
20 #include <config.h>
22 #include "acl-internal.h"
24 /* This file assumes POSIX-draft like ACLs
25 (Linux, FreeBSD, Mac OS X, IRIX, Tru64). */
27 /* Return the number of entries in ACL.
28 Return -1 and set errno upon failure to determine it. */
30 int
31 acl_entries (acl_t acl)
33 int count = 0;
35 if (acl != NULL)
37 #if HAVE_ACL_FIRST_ENTRY /* Linux, FreeBSD, Mac OS X */
38 # if HAVE_ACL_TYPE_EXTENDED /* Mac OS X */
39 /* acl_get_entry returns 0 when it successfully fetches an entry,
40 and -1/EINVAL at the end. */
41 acl_entry_t ace;
42 int got_one;
44 for (got_one = acl_get_entry (acl, ACL_FIRST_ENTRY, &ace);
45 got_one >= 0;
46 got_one = acl_get_entry (acl, ACL_NEXT_ENTRY, &ace))
47 count++;
48 # else /* Linux, FreeBSD */
49 /* acl_get_entry returns 1 when it successfully fetches an entry,
50 and 0 at the end. */
51 acl_entry_t ace;
52 int got_one;
54 for (got_one = acl_get_entry (acl, ACL_FIRST_ENTRY, &ace);
55 got_one > 0;
56 got_one = acl_get_entry (acl, ACL_NEXT_ENTRY, &ace))
57 count++;
58 if (got_one < 0)
59 return -1;
60 # endif
61 #else /* IRIX, Tru64 */
62 # if HAVE_ACL_TO_SHORT_TEXT /* IRIX */
63 /* Don't use acl_get_entry: it is undocumented. */
64 count = acl->acl_cnt;
65 # endif
66 # if HAVE_ACL_FREE_TEXT /* Tru64 */
67 /* Don't use acl_get_entry: it takes only one argument and does not
68 work. */
69 count = acl->acl_num;
70 # endif
71 #endif
74 return count;