Clarify acl_entries.
[pspp] / lib / acl_entries.c
1 /* Return the number of entries in an ACL.
2
3    Copyright (C) 2002-2003, 2005-2009 Free Software Foundation, Inc.
4
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.
9
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.
14
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/>.
17
18    Written by Paul Eggert and Andreas Gruenbacher.  */
19
20 #include <config.h>
21
22 #include "acl-internal.h"
23
24 /* This file assumes POSIX-draft like ACLs
25    (Linux, FreeBSD, MacOS X, IRIX, Tru64).  */
26
27 /* Return the number of entries in ACL.
28    Return -1 and set errno upon failure to determine it.  */
29
30 int
31 acl_entries (acl_t acl)
32 {
33   int count = 0;
34
35   if (acl != NULL)
36     {
37 #if HAVE_ACL_FIRST_ENTRY /* Linux, FreeBSD, MacOS X */
38       acl_entry_t ace;
39       int at_end;
40
41       for (at_end = acl_get_entry (acl, ACL_FIRST_ENTRY, &ace);
42            !at_end;
43            at_end = acl_get_entry (acl, ACL_NEXT_ENTRY, &ace))
44         count++;
45 #else /* IRIX, Tru64 */
46 # if HAVE_ACL_TO_SHORT_TEXT /* IRIX */
47       /* Don't use acl_get_entry: it is undocumented.  */
48       count = acl->acl_cnt;
49 # endif
50 # if HAVE_ACL_FREE_TEXT /* Tru64 */
51       /* Don't use acl_get_entry: it takes only one argument and does not
52          work.  */
53       count = acl->acl_num;
54 # endif
55 #endif
56     }
57
58   return count;
59 }