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