diff options
author | Ian Moffett <ian@osmora.org> | 2024-03-07 17:28:52 -0500 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2024-03-07 18:24:51 -0500 |
commit | f5e48e94a2f4d4bbd6e5628c7f2afafc6dbcc459 (patch) | |
tree | 93b156621dc0303816b37f60ba88051b702d92f6 /lib/mlibc/tests/linux/xattr.c | |
parent | bd5969fc876a10b18613302db7087ef3c40f18e1 (diff) |
build: Build mlibc + add distclean target
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'lib/mlibc/tests/linux/xattr.c')
-rw-r--r-- | lib/mlibc/tests/linux/xattr.c | 80 |
1 files changed, 0 insertions, 80 deletions
diff --git a/lib/mlibc/tests/linux/xattr.c b/lib/mlibc/tests/linux/xattr.c deleted file mode 100644 index c6dd152..0000000 --- a/lib/mlibc/tests/linux/xattr.c +++ /dev/null @@ -1,80 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> -#include <errno.h> -#include <string.h> -#include <unistd.h> -#include <sys/xattr.h> - -#define assert_perror(x) \ - ({ \ - int res = (x); \ - if (res < 0) { \ - perror(#x); \ - return 1; \ - } \ - res; \ - }) - -#define soft_assert(x, m) \ - ({ \ - if (!(x)) { \ - fprintf(stderr, "cond \"%s\" failed: %s\n", #x, m); \ - return 1; \ - } \ - }) - -void remove_tmp(const char (*fname)[]) { - unlink(&(*fname)[0]); -} -#define _cleanup_file_ __attribute__((cleanup(remove_tmp))) - -int main(void) { - int ret; - char buf[32] = { 0 }; - _cleanup_file_ char filename[] = "xattr_test.XXXXXX"; - _cleanup_file_ char filename2[] = "xattr_test.XXXXXX.2"; - - int tmpfile = assert_perror(mkstemp(filename)); - memcpy(filename2, filename, sizeof(filename) - 1); - assert_perror(symlink(filename, filename2)); - - assert_perror(setxattr(filename, "user.T1", "ABC", 3, XATTR_CREATE)); - assert_perror(fsetxattr(tmpfile, "user.T2", "DEF", 3, XATTR_CREATE)); - - // for testing remove - assert_perror(fsetxattr(tmpfile, "user.T3", "DEF", 3, XATTR_CREATE)); - - if ((ret = getxattr(filename, "user.T1", buf, 3)) != 3) { - if (ret < 0) { - perror("getxattr"); - return 1; - } - - soft_assert(memcmp(buf, "ABC", 3) == 0, "xattr read wrong"); - } - - ret = lgetxattr(filename2, "user.T1", buf, 3); - soft_assert(ret < 0 && errno == ENODATA, "lgetxattr deref'd"); - - if ((ret = fgetxattr(tmpfile, "user.T3", buf, 3)) != 3) { - if (ret < 0) { - perror("fgetxattr"); - return 1; - } - - soft_assert(memcmp(buf, "DEF", 3) == 0, "xattr read wrong"); - } - - assert_perror(removexattr(filename, "user.T2")); - assert_perror(fremovexattr(tmpfile, "user.T3")); - - ret = assert_perror(listxattr(filename, buf, sizeof(buf) - 1)); - soft_assert(memmem(buf, ret, "user.T1", 7), "user.T1 not found"); - soft_assert(!memmem(buf, ret, "user.T2", 7), "user.T2 found"); - soft_assert(!memmem(buf, ret, "user.T3", 7), "user.T3 found"); - - ret = assert_perror(flistxattr(tmpfile, buf, sizeof(buf) - 1)); - soft_assert(memmem(buf, ret, "user.T1", 7), "user.T1 not found"); - soft_assert(!memmem(buf, ret, "user.T2", 7), "user.T2 found"); - soft_assert(!memmem(buf, ret, "user.T3", 7), "user.T3 found"); -} |