summaryrefslogtreecommitdiff
path: root/libattr/syscalls.c
blob: 51fe98c9ea9020badd2d2dfac9674077a8f92313 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
 * Copyright (c) 2001-2002 Silicon Graphics, Inc.
 * All Rights Reserved.
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/*
 * The use of the syscall() function is an additional level of
 * indirection.  This avoids the dependency on kernel sources.
 */

#include <errno.h>
#include <unistd.h>
#include <sys/syscall.h>

#if defined (__NR_setxattr)
# define HAVE_XATTR_SYSCALLS 1
#else
# warning "Extended attribute syscalls undefined for this architecture"
# define HAVE_XATTR_SYSCALLS 0
#endif

#if HAVE_XATTR_SYSCALLS
# define SYSCALL(args...)	syscall(args)
#else
# define SYSCALL(args...)	( errno = ENOSYS, -1 )
#endif

int setxattr (const char *path, const char *name,
			void *value, size_t size, int flags)
{
	return SYSCALL(__NR_setxattr, path, name, value, size, flags);
}

int lsetxattr (const char *path, const char *name,
			void *value, size_t size, int flags)
{
	return SYSCALL(__NR_lsetxattr, path, name, value, size, flags);
}

int fsetxattr (int filedes, const char *name,
			void *value, size_t size, int flags)
{
	return SYSCALL(__NR_fsetxattr, filedes, name, value, size, flags);
}

ssize_t getxattr (const char *path, const char *name,
				void *value, size_t size)
{
	return SYSCALL(__NR_getxattr, path, name, value, size);
}

ssize_t lgetxattr (const char *path, const char *name,
				void *value, size_t size)
{
	return SYSCALL(__NR_lgetxattr, path, name, value, size);
}

ssize_t fgetxattr (int filedes, const char *name,
				void *value, size_t size)
{
	return SYSCALL(__NR_fgetxattr, filedes, name, value, size);
}

ssize_t listxattr (const char *path, char *list, size_t size)
{
	return SYSCALL(__NR_listxattr, path, list, size);
}

ssize_t llistxattr (const char *path, char *list, size_t size)
{
	return SYSCALL(__NR_llistxattr, path, list, size);
}

ssize_t flistxattr (int filedes, char *list, size_t size)
{
	return SYSCALL(__NR_flistxattr, filedes, list, size);
}

int removexattr (const char *path, const char *name)
{
	return SYSCALL(__NR_removexattr, path, name);
}

int lremovexattr (const char *path, const char *name)
{
	return SYSCALL(__NR_lremovexattr, path, name);
}

int fremovexattr (int filedes, const char *name)
{
	return SYSCALL(__NR_fremovexattr, filedes, name);
}