Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1209)

Unified Diff: fusl/src/unistd/faccessat.c

Issue 1714623002: [fusl] clang-format fusl (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: headers too Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: fusl/src/unistd/faccessat.c
diff --git a/fusl/src/unistd/faccessat.c b/fusl/src/unistd/faccessat.c
index 33478959cb0edeaf08ed3860ecac04a1d5c488f3..408df85ae2b27787ed83ac826d1e4f17538e7cde 100644
--- a/fusl/src/unistd/faccessat.c
+++ b/fusl/src/unistd/faccessat.c
@@ -6,58 +6,55 @@
#include "pthread_impl.h"
struct ctx {
- int fd;
- const char *filename;
- int amode;
+ int fd;
+ const char* filename;
+ int amode;
};
static const int errors[] = {
- 0, -EACCES, -ELOOP, -ENAMETOOLONG, -ENOENT, -ENOTDIR,
- -EROFS, -EBADF, -EINVAL, -ETXTBSY,
- -EFAULT, -EIO, -ENOMEM,
- -EBUSY
-};
-
-static int checker(void *p)
-{
- struct ctx *c = p;
- int ret;
- int i;
- if (__syscall(SYS_setregid, __syscall(SYS_getegid), -1)
- || __syscall(SYS_setreuid, __syscall(SYS_geteuid), -1))
- __syscall(SYS_exit, 1);
- ret = __syscall(SYS_faccessat, c->fd, c->filename, c->amode, 0);
- for (i=0; i < sizeof errors/sizeof *errors - 1 && ret!=errors[i]; i++);
- return i;
+ 0, -EACCES, -ELOOP, -ENAMETOOLONG, -ENOENT, -ENOTDIR, -EROFS,
+ -EBADF, -EINVAL, -ETXTBSY, -EFAULT, -EIO, -ENOMEM, -EBUSY};
+
+static int checker(void* p) {
+ struct ctx* c = p;
+ int ret;
+ int i;
+ if (__syscall(SYS_setregid, __syscall(SYS_getegid), -1) ||
+ __syscall(SYS_setreuid, __syscall(SYS_geteuid), -1))
+ __syscall(SYS_exit, 1);
+ ret = __syscall(SYS_faccessat, c->fd, c->filename, c->amode, 0);
+ for (i = 0; i < sizeof errors / sizeof *errors - 1 && ret != errors[i]; i++)
+ ;
+ return i;
}
-int faccessat(int fd, const char *filename, int amode, int flag)
-{
- if (!flag || (flag==AT_EACCESS && getuid()==geteuid() && getgid()==getegid()))
- return syscall(SYS_faccessat, fd, filename, amode, flag);
-
- if (flag != AT_EACCESS)
- return __syscall_ret(-EINVAL);
-
- char stack[1024];
- sigset_t set;
- pid_t pid;
- int ret = -EBUSY;
- struct ctx c = { .fd = fd, .filename = filename, .amode = amode };
-
- __block_all_sigs(&set);
-
- pid = __clone(checker, stack+sizeof stack, 0, &c);
- if (pid > 0) {
- int status;
- do {
- __syscall(SYS_wait4, pid, &status, __WCLONE, 0);
- } while (!WIFEXITED(status) && !WIFSIGNALED(status));
- if (WIFEXITED(status))
- ret = errors[WEXITSTATUS(status)];
- }
-
- __restore_sigs(&set);
-
- return __syscall_ret(ret);
+int faccessat(int fd, const char* filename, int amode, int flag) {
+ if (!flag ||
+ (flag == AT_EACCESS && getuid() == geteuid() && getgid() == getegid()))
+ return syscall(SYS_faccessat, fd, filename, amode, flag);
+
+ if (flag != AT_EACCESS)
+ return __syscall_ret(-EINVAL);
+
+ char stack[1024];
+ sigset_t set;
+ pid_t pid;
+ int ret = -EBUSY;
+ struct ctx c = {.fd = fd, .filename = filename, .amode = amode};
+
+ __block_all_sigs(&set);
+
+ pid = __clone(checker, stack + sizeof stack, 0, &c);
+ if (pid > 0) {
+ int status;
+ do {
+ __syscall(SYS_wait4, pid, &status, __WCLONE, 0);
+ } while (!WIFEXITED(status) && !WIFSIGNALED(status));
+ if (WIFEXITED(status))
+ ret = errors[WEXITSTATUS(status)];
+ }
+
+ __restore_sigs(&set);
+
+ return __syscall_ret(ret);
}

Powered by Google App Engine
This is Rietveld 408576698