source: azure_iot_hub/trunk/musl-1.1.18/src/unistd/faccessat.c@ 388

Last change on this file since 388 was 388, checked in by coas-nagasima, 5 years ago

Azure IoT Hub Device C SDK を使ったサンプルの追加

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-csrc
File size: 1.4 KB
Line 
1#include <unistd.h>
2#include <fcntl.h>
3#include <errno.h>
4#include <sys/wait.h>
5#include "syscall.h"
6#include "pthread_impl.h"
7
8struct ctx {
9 int fd;
10 const char *filename;
11 int amode;
12};
13
14static const int errors[] = {
15 0, -EACCES, -ELOOP, -ENAMETOOLONG, -ENOENT, -ENOTDIR,
16 -EROFS, -EBADF, -EINVAL, -ETXTBSY,
17 -EFAULT, -EIO, -ENOMEM,
18 -EBUSY
19};
20
21static int checker(void *p)
22{
23 struct ctx *c = p;
24 int ret;
25 int i;
26 if (__syscall(SYS_setregid, __syscall(SYS_getegid), -1)
27 || __syscall(SYS_setreuid, __syscall(SYS_geteuid), -1))
28 __syscall(SYS_exit, 1);
29 ret = __syscall(SYS_faccessat, c->fd, c->filename, c->amode, 0);
30 for (i=0; i < sizeof errors/sizeof *errors - 1 && ret!=errors[i]; i++);
31 return i;
32}
33
34int faccessat(int fd, const char *filename, int amode, int flag)
35{
36 if (!flag || (flag==AT_EACCESS && getuid()==geteuid() && getgid()==getegid()))
37 return syscall(SYS_faccessat, fd, filename, amode, flag);
38
39 if (flag != AT_EACCESS)
40 return __syscall_ret(-EINVAL);
41
42 char stack[1024];
43 sigset_t set;
44 pid_t pid;
45 int ret = -EBUSY;
46 struct ctx c = { .fd = fd, .filename = filename, .amode = amode };
47
48 __block_all_sigs(&set);
49
50 pid = __clone(checker, stack+sizeof stack, 0, &c);
51 if (pid > 0) {
52 int status;
53 do {
54 __syscall(SYS_wait4, pid, &status, __WCLONE, 0);
55 } while (!WIFEXITED(status) && !WIFSIGNALED(status));
56 if (WIFEXITED(status))
57 ret = errors[WEXITSTATUS(status)];
58 }
59
60 __restore_sigs(&set);
61
62 return __syscall_ret(ret);
63}
Note: See TracBrowser for help on using the repository browser.