]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/test/test-xattr-util.c
2 This file is part of systemd.
4 Copyright 2010 Lennart Poettering
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 #include <sys/types.h>
23 #include <sys/xattr.h>
26 #include "alloc-util.h"
30 #include "string-util.h"
31 #include "xattr-util.h"
33 static void test_fgetxattrat_fake(void) {
34 char t
[] = "/var/tmp/xattrtestXXXXXX";
35 _cleanup_close_
int fd
= -1;
40 assert_se(mkdtemp(t
));
41 x
= strjoina(t
, "/test");
42 assert_se(touch(x
) >= 0);
44 r
= setxattr(x
, "user.foo", "bar", 3, 0);
45 if (r
< 0 && errno
== EOPNOTSUPP
) /* no xattrs supported on /var/tmp... */
49 fd
= open(t
, O_RDONLY
|O_DIRECTORY
|O_CLOEXEC
|O_NOCTTY
);
52 assert_se(fgetxattrat_fake(fd
, "test", "user.foo", v
, 3, 0) >= 0);
53 assert_se(memcmp(v
, "bar", 3) == 0);
56 fd
= open("/", O_RDONLY
|O_DIRECTORY
|O_CLOEXEC
|O_NOCTTY
);
58 assert_se(fgetxattrat_fake(fd
, "usr", "user.idontexist", v
, 3, 0) == -ENODATA
);
61 assert_se(unlink(x
) >= 0);
62 assert_se(rmdir(t
) >= 0);
66 test_fgetxattrat_fake();