llvm-project
53 строки · 1.5 Кб
1// UNSUPPORTED: target={{.*windows.*}}
2// RUN: %clang_pgogen -o %t.bin %s -DTESTPATH=\"%t.dir\"
3// RUN: rm -rf %t.dir
4// RUN: %run %t.bin
5
6#include <stdio.h>7#include <stdlib.h>8#include <string.h>9#include <sys/stat.h>10
11void __llvm_profile_set_dir_mode(unsigned Mode);12unsigned __llvm_profile_get_dir_mode(void);13void __llvm_profile_recursive_mkdir(char *Path);14
15static int test(unsigned Mode, const char *TestDir) {16int Ret = 0;17
18/* Create a dir and set the mode accordingly. */19char *Dir = strdup(TestDir);20if (!Dir)21return -1;22__llvm_profile_set_dir_mode(Mode);23__llvm_profile_recursive_mkdir(Dir);24
25if (Mode != __llvm_profile_get_dir_mode())26Ret = -1;27else {28// From 'man mkdir':29// "If the parent directory has the set-group-ID bit set, then so will the30// newly created directory." So we mask off S_ISGID below; this test cannot31// control its parent directory.32const unsigned Expected = ~umask(0) & Mode;33struct stat DirSt;34if (stat(Dir, &DirSt) == -1)35Ret = -1;36// AIX has some extended definition of high order bits for st_mode, avoid trying to comparing those by masking them off.37else if (((DirSt.st_mode & ~S_ISGID) & 0xFFFF) != Expected) {38printf("Modes do not match: Expected %o but found %o (%s)\n", Expected,39DirSt.st_mode, Dir);40Ret = -1;41}42}43
44free(Dir);45return Ret;46}
47
48int main(void) {49if (test(S_IFDIR | 0777, TESTPATH "/foo/bar/baz/") ||50test(S_IFDIR | 0666, TESTPATH "/foo/bar/qux/"))51return -1;52return 0;53}
54