Make copy_acl work on MacOS X 10.5.
[gnulib.git] / lib / acl-internal.h
1 /* Internal implementation of access control lists.
2
3    Copyright (C) 2002-2003, 2005-2008 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 "acl.h"
21
22 #include <stdbool.h>
23 #include <stdlib.h>
24
25 /* All systems define the ACL related API in <sys/acl.h>.  */
26 #if HAVE_SYS_ACL_H
27 # include <sys/acl.h>
28 #endif
29 #if defined HAVE_ACL && ! defined GETACLCNT && defined ACL_CNT
30 # define GETACLCNT ACL_CNT
31 #endif
32
33 /* On Linux, additional ACL related API is available in <acl/libacl.h>.  */
34 #ifdef HAVE_ACL_LIBACL_H
35 # include <acl/libacl.h>
36 #endif
37
38 #include "error.h"
39 #include "quote.h"
40
41 #include <errno.h>
42 #ifndef ENOSYS
43 # define ENOSYS (-1)
44 #endif
45 #ifndef ENOTSUP
46 # define ENOTSUP (-1)
47 #endif
48
49 #include "gettext.h"
50 #define _(msgid) gettext (msgid)
51
52 #ifndef HAVE_FCHMOD
53 # define HAVE_FCHMOD false
54 # define fchmod(fd, mode) (-1)
55 #endif
56
57 #ifndef MIN_ACL_ENTRIES
58 # define MIN_ACL_ENTRIES 4
59 #endif
60
61 /* POSIX 1003.1e (draft 17) */
62 #ifndef HAVE_ACL_GET_FD
63 # define HAVE_ACL_GET_FD false
64 # undef acl_get_fd
65 # define acl_get_fd(fd) (NULL)
66 #endif
67
68 /* POSIX 1003.1e (draft 17) */
69 #ifndef HAVE_ACL_SET_FD
70 # define HAVE_ACL_SET_FD false
71 # undef acl_set_fd
72 # define acl_set_fd(fd, acl) (-1)
73 #endif
74
75 /* Linux-specific */
76 #ifndef HAVE_ACL_EXTENDED_FILE
77 # define HAVE_ACL_EXTENDED_FILE false
78 # define acl_extended_file(name) (-1)
79 #endif
80
81 /* Linux-specific */
82 #ifndef HAVE_ACL_FROM_MODE
83 # define HAVE_ACL_FROM_MODE false
84 # define acl_from_mode(mode) (NULL)
85 #endif
86
87 /* Set to 1 if a file's mode is implicit by the ACL.
88    Set to 0 if a file's mode is stored independently from the ACL.  */
89 #if HAVE_ACL_COPY_EXT_NATIVE && HAVE_ACL_CREATE_ENTRY_NP /* MacOS X */
90 # define MODE_INSIDE_ACL 0
91 #else
92 # define MODE_INSIDE_ACL 1
93 #endif
94
95 #if defined __APPLE__ && defined __MACH__ /* MacOS X */
96 # define ACL_NOT_WELL_SUPPORTED(Err) \
97    ((Err) == ENOTSUP || (Err) == ENOSYS || (Err) == EINVAL || (Err) == EBUSY || (Err) == ENOENT)
98 #else
99 # define ACL_NOT_WELL_SUPPORTED(Err) \
100    ((Err) == ENOTSUP || (Err) == ENOSYS || (Err) == EINVAL || (Err) == EBUSY)
101 #endif
102
103 /* Define a replacement for acl_entries if needed.  */
104 #if USE_ACL && HAVE_ACL_GET_FILE && HAVE_ACL_FREE && !HAVE_ACL_ENTRIES
105 # define acl_entries rpl_acl_entries
106 int acl_entries (acl_t);
107 #endif