From f5e48e94a2f4d4bbd6e5628c7f2afafc6dbcc459 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Thu, 7 Mar 2024 17:28:52 -0500 Subject: build: Build mlibc + add distclean target Signed-off-by: Ian Moffett --- lib/mlibc/tests/linux/xattr.c | 80 ------------------------------------------- 1 file changed, 80 deletions(-) delete mode 100644 lib/mlibc/tests/linux/xattr.c (limited to 'lib/mlibc/tests/linux/xattr.c') 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 -#include -#include -#include -#include -#include - -#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"); -} -- cgit v1.2.3