diff options
author | Eric Andersen <andersen@codepoet.org> | 2004-01-21 20:14:41 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2004-01-21 20:14:41 +0000 |
commit | 2fde23582edd0a813b632931801d8c4d3294528f (patch) | |
tree | 5207b998e368eb111bf7a443fea16741e5907651 | |
parent | 43b32ce6bedb4bb0cc65bfe6e23b0e9f27288618 (diff) |
Massive formatting cleanup, making it easier to parse
-rw-r--r-- | libc/sysdeps/linux/common/syscalls.c | 934 |
1 files changed, 503 insertions, 431 deletions
diff --git a/libc/sysdeps/linux/common/syscalls.c b/libc/sysdeps/linux/common/syscalls.c index 882de8106..2fb0f97f1 100644 --- a/libc/sysdeps/linux/common/syscalls.c +++ b/libc/sysdeps/linux/common/syscalls.c @@ -45,15 +45,15 @@ #include <unistd.h> # ifdef __ARCH_HAS_MMU__ #define __NR___libc_fork __NR_fork - _syscall0(pid_t, __libc_fork); +_syscall0(pid_t, __libc_fork); # else - pid_t __libc_fork(void) - { - __set_errno(ENOSYS); - return -1; - } +pid_t __libc_fork(void) +{ + __set_errno(ENOSYS); + return -1; +} # endif -weak_alias (__libc_fork, fork) +weak_alias(__libc_fork, fork); #endif //#define __NR_read 3 @@ -61,18 +61,19 @@ weak_alias (__libc_fork, fork) #include <unistd.h> #define __NR___libc_read __NR_read _syscall3(ssize_t, __libc_read, int, fd, __ptr_t, buf, size_t, count); -weak_alias(__libc_read, read) +weak_alias(__libc_read, read); #endif //#define __NR_write 4 #ifdef L___libc_write #include <unistd.h> #define __NR___libc_write __NR_write -_syscall3(ssize_t, __libc_write, int, fd, const __ptr_t, buf, size_t, count); -weak_alias(__libc_write, write) +_syscall3(ssize_t, __libc_write, int, fd, const __ptr_t, buf, + size_t, count); +weak_alias(__libc_write, write); /* Stupid libgcc.a from gcc 2.95.x uses __write in pure.o * which is a blatent GNU libc-ism... */ -weak_alias (__libc_write, __write) +weak_alias(__libc_write, __write); #endif //#define __NR_open 5 @@ -84,23 +85,27 @@ weak_alias (__libc_write, __write) #include <string.h> #include <sys/param.h> static inline -_syscall3(int, __syscall_open, const char *, file, int, flags, __kernel_mode_t, mode); -int __libc_open (const char * file, int flags, ...) +_syscall3(int, __syscall_open, const char *, file, int, flags, + __kernel_mode_t, mode); +int __libc_open(const char *file, int flags, ...) { mode_t mode; + if (flags & O_CREAT) { va_list ap; + va_start(ap, flags); mode = va_arg(ap, mode_t); va_end(ap); } return __syscall_open(file, flags, mode); } -weak_alias(__libc_open, open) + +weak_alias(__libc_open, open); int creat(const char *file, mode_t mode) { - return __libc_open (file, O_WRONLY|O_CREAT|O_TRUNC, mode); + return __libc_open(file, O_WRONLY | O_CREAT | O_TRUNC, mode); } #endif @@ -109,11 +114,11 @@ int creat(const char *file, mode_t mode) #include <unistd.h> #define __NR___libc_close __NR_close _syscall1(int, __libc_close, int, fd); -weak_alias(__libc_close, close) +weak_alias(__libc_close, close); #endif //#define __NR_waitpid 7 -// Implemented using wait4 +// Implemented using wait4 //#define __NR_creat 8 // Implemented using open @@ -137,9 +142,9 @@ _syscall1(int, unlink, const char *, pathname); #include <string.h> #include <sys/param.h> static inline -_syscall3(int, __syscall_execve, const char *, filename, - char *const *, argv, char *const *, envp); -weak_alias(__syscall_execve, execve) +_syscall3(int, __syscall_execve, const char *, filename, + char *const *, argv, char *const *, envp); +weak_alias(__syscall_execve, execve); #endif //#define __NR_chdir 12 @@ -147,9 +152,8 @@ weak_alias(__syscall_execve, execve) #define __NR___syscall_chdir __NR_chdir #include <string.h> #include <sys/param.h> -static inline -_syscall1(int, __syscall_chdir, const char *, path); -weak_alias(__syscall_chdir, chdir) +static inline _syscall1(int, __syscall_chdir, const char *, path); +weak_alias(__syscall_chdir, chdir); #endif //#define __NR_time 13 @@ -159,14 +163,19 @@ weak_alias(__syscall_chdir, chdir) #ifdef __NR_time _syscall1(time_t, time, time_t *, t); #else -time_t time (time_t *t) -{ +time_t time(time_t * t) +{ time_t result; struct timeval tv; - if (gettimeofday (&tv, (struct timezone *) NULL)) { - result = (time_t) -1; - } else { result = (time_t) tv.tv_sec; } - if (t != NULL) { *t = result; } + + if (gettimeofday(&tv, (struct timezone *) NULL)) { + result = (time_t) - 1; + } else { + result = (time_t) tv.tv_sec; + } + if (t != NULL) { + *t = result; + } return result; } #endif @@ -176,11 +185,13 @@ time_t time (time_t *t) #ifdef L___syscall_mknod #define __NR___syscall_mknod __NR_mknod #include <sys/stat.h> -_syscall3(int, __syscall_mknod, const char *, path, __kernel_mode_t, mode, __kernel_dev_t, dev); +_syscall3(int, __syscall_mknod, const char *, path, __kernel_mode_t, mode, + __kernel_dev_t, dev); int mknod(const char *path, mode_t mode, dev_t dev) -{ +{ /* We must convert the dev_t value to a __kernel_dev_t */ __kernel_dev_t k_dev; + k_dev = ((major(dev) & 0xff) << 8) | (minor(dev) & 0xff); return __syscall_mknod(path, mode, k_dev); } @@ -190,7 +201,7 @@ int mknod(const char *path, mode_t mode, dev_t dev) #ifdef L___syscall_chmod #include <sys/stat.h> #define __NR___syscall_chmod __NR_chmod -static inline +static inline _syscall2(int, __syscall_chmod, const char *, path, __kernel_mode_t, mode); int chmod(const char *path, mode_t mode) { @@ -199,9 +210,9 @@ int chmod(const char *path, mode_t mode) #endif /* Old kernels don't have lchown -- do chown instead. This - * is sick and wrong, but at least things will compile. + * is sick and wrong, but at least things will compile. * They may not follow links when they should though... */ -#ifndef __NR_lchown +#ifndef __NR_lchown #define __NR_lchown __NR_chown #endif @@ -209,14 +220,14 @@ int chmod(const char *path, mode_t mode) #ifdef L___syscall_lchown #include <unistd.h> #define __NR___syscall_lchown __NR_lchown -static inline -_syscall3(int, __syscall_lchown, const char *, path, __kernel_uid_t, owner, __kernel_gid_t, group); +static inline +_syscall3(int, __syscall_lchown, const char *, path, __kernel_uid_t, owner, + __kernel_gid_t, group); int lchown(const char *path, uid_t owner, gid_t group) { - if (((owner + 1) > (uid_t) ((__kernel_uid_t) -1U)) - || ((group + 1) > (gid_t) ((__kernel_gid_t) -1U))) - { - __set_errno (EINVAL); + if (((owner + 1) > (uid_t) ((__kernel_uid_t) - 1U)) + || ((group + 1) > (gid_t) ((__kernel_gid_t) - 1U))) { + __set_errno(EINVAL); return -1; } return __syscall_lchown(path, owner, group); @@ -232,8 +243,9 @@ int lchown(const char *path, uid_t owner, gid_t group) #ifdef L___libc_lseek #include <unistd.h> #define __NR___libc_lseek __NR_lseek -_syscall3(__off_t, __libc_lseek, int, fildes, __off_t, offset, int, whence); -weak_alias(__libc_lseek, lseek) +_syscall3(__off_t, __libc_lseek, int, fildes, __off_t, offset, int, + whence); +weak_alias(__libc_lseek, lseek); #endif //#define __NR_getpid 20 @@ -244,8 +256,8 @@ weak_alias(__libc_lseek, lseek) #endif #define __NR___libc_getpid __NR_getpid _syscall0(pid_t, __libc_getpid); -weak_alias(__libc_getpid, getpid) -weak_alias(__libc_getpid, __getpid) +weak_alias(__libc_getpid, getpid); +weak_alias(__libc_getpid, __getpid); #endif //#define __NR_mount 21 @@ -266,15 +278,14 @@ _syscall1(int, umount, const char *, specialfile); #ifdef L___syscall_setuid #define __NR___syscall_setuid __NR_setuid #include <unistd.h> -static inline -_syscall1(int, __syscall_setuid, __kernel_uid_t, uid); +static inline _syscall1(int, __syscall_setuid, __kernel_uid_t, uid); int setuid(uid_t uid) { - if (uid == (uid_t) ~0 || uid != (uid_t) ((__kernel_uid_t) uid)) { - __set_errno (EINVAL); + if (uid == (uid_t) ~ 0 || uid != (uid_t) ((__kernel_uid_t) uid)) { + __set_errno(EINVAL); return -1; } - return(__syscall_setuid(uid)); + return (__syscall_setuid(uid)); } #endif @@ -285,11 +296,10 @@ int setuid(uid_t uid) #define __NR_getuid __NR_getxuid #endif #define __NR___syscall_getuid __NR_getuid -static inline -_syscall0(int, __syscall_getuid); +static inline _syscall0(int, __syscall_getuid); uid_t getuid(void) { - return(__syscall_getuid()); + return (__syscall_getuid()); } #endif @@ -300,13 +310,17 @@ uid_t getuid(void) #ifdef __NR_stime _syscall1(int, stime, const time_t *, t); #else -int stime(const time_t *when) -{ +int stime(const time_t * when) +{ struct timeval tv; - if (when == NULL) { __set_errno (EINVAL); return -1; } + + if (when == NULL) { + __set_errno(EINVAL); + return -1; + } tv.tv_sec = *when; tv.tv_usec = 0; - return settimeofday (&tv, (struct timezone *) 0); + return settimeofday(&tv, (struct timezone *) 0); } #endif #endif @@ -322,17 +336,22 @@ int stime(const time_t *when) _syscall1(unsigned int, alarm, unsigned int, seconds); #else #include <sys/time.h> -unsigned int alarm (unsigned int seconds) +unsigned int alarm(unsigned int seconds) { struct itimerval old, new; unsigned int retval; + new.it_value.tv_usec = 0; new.it_interval.tv_sec = 0; new.it_interval.tv_usec = 0; new.it_value.tv_sec = (long int) seconds; - if (setitimer (ITIMER_REAL, &new, &old) < 0) { return 0; } + if (setitimer(ITIMER_REAL, &new, &old) < 0) { + return 0; + } retval = old.it_value.tv_sec; - if (old.it_value.tv_usec) { ++retval; } + if (old.it_value.tv_usec) { + ++retval; + } return retval; } #endif @@ -346,14 +365,15 @@ unsigned int alarm (unsigned int seconds) #ifdef __NR_pause #define __NR___libc_pause __NR_pause _syscall0(int, __libc_pause); -weak_alias(__libc_pause, pause) +weak_alias(__libc_pause, pause); #else #include <signal.h> -int __libc_pause (void) +int __libc_pause(void) { - return(__sigpause(sigblock(0), 0)); + return (__sigpause(sigblock(0), 0)); } -weak_alias(__libc_pause, pause) + +weak_alias(__libc_pause, pause); #endif #endif @@ -368,13 +388,16 @@ _syscall2(int, utime, const char *, file, const struct utimbuf *, times); int utime(const char *file, const struct utimbuf *times) { struct timeval timevals[2]; + if (times != NULL) { timevals[0].tv_usec = 0L; timevals[1].tv_usec = 0L; timevals[0].tv_sec = (long int) times->actime; timevals[1].tv_sec = (long int) times->modtime; } else { - if (gettimeofday (&timevals[0], NULL) < 0) { return -1; } + if (gettimeofday(&timevals[0], NULL) < 0) { + return -1; + } timevals[1] = timevals[0]; } return utimes(file, timevals); @@ -390,14 +413,17 @@ _syscall2(int, utimes, const char *, file, const struct timeval *, tvp); #else #include <stdlib.h> #include <sys/time.h> -int utimes (const char *file, const struct timeval tvp[2]) +int utimes(const char *file, const struct timeval tvp[2]) { struct utimbuf buf, *times; + if (tvp) { times = &buf; times->actime = tvp[0].tv_sec; times->modtime = tvp[1].tv_sec; - } else { times = NULL; } + } else { + times = NULL; + } return utime(file, times); } #endif @@ -406,7 +432,8 @@ int utimes (const char *file, const struct timeval tvp[2]) //#define __NR_stty 31 #ifdef L_stty #include <sgtty.h> -int stty (int __fd, __const struct sgttyb *__params); +int stty(int __fd, __const struct sgttyb *__params); + { __set_errno(ENOSYS); return -1; @@ -416,7 +443,7 @@ int stty (int __fd, __const struct sgttyb *__params); //#define __NR_gtty 32 #ifdef L_gtty #include <sgtty.h> -int gtty (int __fd, struct sgttyb *__params) +int gtty(int __fd, struct sgttyb *__params) { __set_errno(ENOSYS); return -1; @@ -436,18 +463,26 @@ _syscall2(int, access, const char *, pathname, int, mode); _syscall1(int, nice, int, inc); #else #include <sys/resource.h> -int nice (int incr) +int nice(int incr) { int save, prio, result; + save = errno; - __set_errno (0); - prio = getpriority (PRIO_PROCESS, 0); + __set_errno(0); + prio = getpriority(PRIO_PROCESS, 0); if (prio == -1) { - if (errno != 0) { return -1; } - else { __set_errno (save); } + if (errno != 0) { + return -1; + } else { + __set_errno(save); + } + } + result = setpriority(PRIO_PROCESS, 0, prio + incr); + if (result != -1) { + return prio + incr; + } else { + return -1; } - result = setpriority (PRIO_PROCESS, 0, prio + incr); - if (result != -1) { return prio + incr; } else { return -1; } } #endif #endif @@ -466,7 +501,7 @@ static inline _syscall2(int, __syscall_kill, __kernel_pid_t, pid, int, sig); int kill(pid_t pid, int sig) { - return(__syscall_kill(pid, sig)); + return (__syscall_kill(pid, sig)); } #endif @@ -478,19 +513,21 @@ int kill(pid_t pid, int sig) #include <sys/param.h> #include <stdio.h> static inline -_syscall2(int, __syscall_rename, const char *, oldpath, const char *, newpath); -weak_alias(__syscall_rename, rename) +_syscall2(int, __syscall_rename, const char *, oldpath, const char *, + newpath); +weak_alias(__syscall_rename, rename); #endif //#define __NR_mkdir 39 #ifdef L___syscall_mkdir #include <sys/stat.h> #define __NR___syscall_mkdir __NR_mkdir -static inline -_syscall2(int, __syscall_mkdir, const char *, pathname, __kernel_mode_t, mode); -int mkdir(const char * pathname, mode_t mode) +static inline +_syscall2(int, __syscall_mkdir, const char *, pathname, __kernel_mode_t, + mode); +int mkdir(const char *pathname, mode_t mode) { - return(__syscall_mkdir(pathname, mode)); + return (__syscall_mkdir(pathname, mode)); } #endif @@ -526,17 +563,14 @@ _syscall1(clock_t, times, struct tms *, buf); #ifdef L___syscall_setgid #include <unistd.h> #define __NR___syscall_setgid __NR_setgid -static inline -_syscall1(int, __syscall_setgid, __kernel_gid_t, gid); +static inline _syscall1(int, __syscall_setgid, __kernel_gid_t, gid); int setgid(gid_t gid) { - if (gid == (gid_t) ~0 - || gid != (gid_t) ((__kernel_gid_t) gid)) - { - __set_errno (EINVAL); + if (gid == (gid_t) ~ 0 || gid != (gid_t) ((__kernel_gid_t) gid)) { + __set_errno(EINVAL); return -1; } - return(__syscall_setgid(gid)); + return (__syscall_setgid(gid)); } #endif @@ -547,11 +581,10 @@ int setgid(gid_t gid) #if defined (__alpha__) #define __NR_getgid __NR_getxgid #endif -static inline -_syscall0(int, __syscall_getgid); +static inline _syscall0(int, __syscall_getgid); gid_t getgid(void) { - return(__syscall_getgid()); + return (__syscall_getgid()); } #endif @@ -562,17 +595,16 @@ gid_t getgid(void) #include <unistd.h> # ifdef __NR_geteuid #define __NR___syscall_geteuid __NR_geteuid - static inline - _syscall0(int, __syscall_geteuid); - uid_t geteuid(void) - { - return(__syscall_geteuid()); - } +static inline _syscall0(int, __syscall_geteuid); +uid_t geteuid(void) +{ + return (__syscall_geteuid()); +} # else - uid_t geteuid(void) - { - return (getuid()); - } +uid_t geteuid(void) +{ + return (getuid()); +} # endif #endif @@ -581,17 +613,16 @@ gid_t getgid(void) #include <unistd.h> # ifdef __NR_getegid #define __NR___syscall_getegid __NR_getegid -static inline -_syscall0(int, __syscall_getegid); +static inline _syscall0(int, __syscall_getegid); gid_t getegid(void) { - return(__syscall_getegid()); + return (__syscall_getegid()); } # else - gid_t getegid(void) - { - return (getgid()); - } +gid_t getegid(void) +{ + return (getgid()); +} # endif #endif @@ -603,15 +634,15 @@ _syscall1(int, acct, const char *, filename); //#define __NR_umount2 52 #ifdef L_umount2 -# ifdef __NR_umount2 /* Old kernels don't have umount2 */ +# ifdef __NR_umount2 /* Old kernels don't have umount2 */ # include <sys/mount.h> - _syscall2(int, umount2, const char *, special_file, int, flags); +_syscall2(int, umount2, const char *, special_file, int, flags); # else - int umount2(const char * special_file, int flags) - { - __set_errno(ENOSYS); - return -1; - } +int umount2(const char *special_file, int flags) +{ + __set_errno(ENOSYS); + return -1; +} # endif #endif @@ -624,6 +655,7 @@ _syscall1(int, acct, const char *, filename); #define __NR___syscall_ioctl __NR_ioctl extern int __syscall_ioctl(int fd, int request, void *arg); _syscall3(int, __syscall_ioctl, int, fd, int, request, void *, arg); + #if !defined (__powerpc__) #include "ioctl.c" /* Also see ioctl.c and powerpc/ioctl.c */ @@ -638,22 +670,23 @@ _syscall3(int, __syscall_ioctl, int, fd, int, request, void *, arg); #ifdef __UCLIBC_HAS_LFS__ static inline #endif -_syscall3(int, __syscall_fcntl, int, fd, int, cmd, long, arg); + _syscall3(int, __syscall_fcntl, int, fd, int, cmd, long, arg); int __libc_fcntl(int fd, int cmd, ...) { long arg; va_list list; - if (cmd == F_GETLK64 || cmd == F_SETLK64 || cmd == F_SETLKW64) - { - __set_errno(ENOSYS); - return -1; + + if (cmd == F_GETLK64 || cmd == F_SETLK64 || cmd == F_SETLKW64) { + __set_errno(ENOSYS); + return -1; } va_start(list, cmd); arg = va_arg(list, long); va_end(list); - return(__syscall_fcntl(fd, cmd, arg)); + return (__syscall_fcntl(fd, cmd, arg)); } -weak_alias(__libc_fcntl, fcntl) + +weak_alias(__libc_fcntl, fcntl); #if ! defined __NR_fcntl64 && defined __UCLIBC_HAS_LFS__ weak_alias(__libc_fcntl, fcntl64); #endif @@ -666,10 +699,11 @@ weak_alias(__libc_fcntl, fcntl64); #include <unistd.h> #define __NR___syscall_setpgid __NR_setpgid static inline -_syscall2(int, __syscall_setpgid, __kernel_pid_t, pid, __kernel_pid_t, pgid); +_syscall2(int, __syscall_setpgid, __kernel_pid_t, pid, + __kernel_pid_t, pgid); int setpgid(pid_t pid, pid_t pgid) { - return(__syscall_setpgid(pid, pgid)); + return (__syscall_setpgid(pid, pgid)); } #endif @@ -682,11 +716,11 @@ int setpgid(pid_t pid, pid_t pgid) #ifdef L___syscall_umask #include <sys/stat.h> #define __NR___syscall_umask __NR_umask -static inline +static inline _syscall1(__kernel_mode_t, __syscall_umask, __kernel_mode_t, mode); mode_t umask(mode_t mode) { - return(__syscall_umask(mode)); + return (__syscall_umask(mode)); } #endif @@ -696,9 +730,8 @@ mode_t umask(mode_t mode) #include <unistd.h> #include <string.h> #include <sys/param.h> -static inline -_syscall1(int, __syscall_chroot, const char *, path); -weak_alias(__syscall_chroot, chroot) +static inline _syscall1(int, __syscall_chroot, const char *, path); +weak_alias(__syscall_chroot, chroot); #endif //#define __NR_ustat 62 @@ -706,11 +739,13 @@ weak_alias(__syscall_chroot, chroot) #define __NR___syscall_ustat __NR_ustat #include <sys/ustat.h> static inline -_syscall2(int, __syscall_ustat, unsigned short int, kdev_t, struct ustat *, ubuf); +_syscall2(int, __syscall_ustat, unsigned short int, kdev_t, + struct ustat *, ubuf); int ustat(dev_t dev, struct ustat *ubuf) -{ +{ /* We must convert the dev_t value to a __kernel_dev_t */ __kernel_dev_t k_dev; + k_dev = ((major(dev) & 0xff) << 8) | (minor(dev) & 0xff); return __syscall_ustat(k_dev, ubuf); } @@ -727,12 +762,12 @@ _syscall2(int, dup2, int, oldfd, int, newfd); #ifdef L_getppid # include <unistd.h> # ifdef __NR_getppid - _syscall0(pid_t, getppid); +_syscall0(pid_t, getppid); # else - pid_t getppid(void) - { - return (getpid()); - } +pid_t getppid(void) +{ + return (getpid()); +} # endif #endif @@ -754,8 +789,8 @@ _syscall0(pid_t, setsid); #define __NR___syscall_sigaction __NR_sigaction #include <signal.h> #undef sigaction -_syscall3(int, __syscall_sigaction, int, signum, const struct sigaction *, act, - struct sigaction *, oldact); +_syscall3(int, __syscall_sigaction, int, signum, const struct sigaction *, + act, struct sigaction *, oldact); #endif #endif @@ -768,16 +803,16 @@ _syscall3(int, __syscall_sigaction, int, signum, const struct sigaction *, act, #include <unistd.h> #define __NR___syscall_setreuid __NR_setreuid static inline -_syscall2(int, __syscall_setreuid, __kernel_uid_t, ruid, __kernel_uid_t, euid); +_syscall2(int, __syscall_setreuid, __kernel_uid_t, ruid, + __kernel_uid_t, euid); int setreuid(uid_t ruid, uid_t euid) { - if (((ruid + 1) > (uid_t) ((__kernel_uid_t) -1U)) - || ((euid + 1) > (uid_t) ((__kernel_uid_t) -1U))) - { + if (((ruid + 1) > (uid_t) ((__kernel_uid_t) - 1U)) + || ((euid + 1) > (uid_t) ((__kernel_uid_t) - 1U))) { __set_errno(EINVAL); return -1; } - return(__syscall_setreuid(ruid, euid)); + return (__syscall_setreuid(ruid, euid)); } #endif @@ -786,16 +821,16 @@ int setreuid(uid_t ruid, uid_t euid) #include <unistd.h> #define __NR___syscall_setregid __NR_setregid static inline -_syscall2(int, __syscall_setregid, __kernel_gid_t, rgid, __kernel_gid_t, egid); +_syscall2(int, __syscall_setregid, __kernel_gid_t, rgid, + __kernel_gid_t, egid); int setregid(gid_t rgid, gid_t egid) { - if (((rgid + 1) > (gid_t) ((__kernel_gid_t) -1U)) - || ((egid + 1) > (gid_t) ((__kernel_gid_t) -1U))) - { - __set_errno (EINVAL); + if (((rgid + 1) > (gid_t) ((__kernel_gid_t) - 1U)) + || ((egid + 1) > (gid_t) ((__kernel_gid_t) - 1U))) { + __set_errno(EINVAL); return -1; } - return(__syscall_setregid(rgid, egid)); + return (__syscall_setregid(rgid, egid)); } #endif @@ -805,9 +840,10 @@ int setregid(gid_t rgid, gid_t egid) #ifdef L___sigsuspend #include <signal.h> #undef sigsuspend -_syscall3(int, __sigsuspend, int, a, unsigned long int, b, unsigned long int, c); +_syscall3(int, __sigsuspend, int, a, unsigned long int, b, + unsigned long int, c); -int sigsuspend (const sigset_t *set) +int sigsuspend(const sigset_t * set) { return __sigsuspend(0, 0, set->__val[0]); } @@ -831,45 +867,49 @@ _syscall2(int, sethostname, const char *, name, size_t, len); //#define __NR_setrlimit 75 #ifndef __NR_ugetrlimit -/* Only wrap setrlimit if the new ugetrlimit is not present */ +/* Only wrap setrlimit if the new ugetrlimit is not present */ #ifdef L___setrlimit #define __NR___setrlimit __NR_setrlimit #include <unistd.h> #include <sys/resource.h> #define RMIN(x, y) ((x) < (y) ? (x) : (y)) _syscall2(int, __setrlimit, int, resource, const struct rlimit *, rlim); -int setrlimit (__rlimit_resource_t resource, const struct rlimit *rlimits) +int setrlimit(__rlimit_resource_t resource, const struct rlimit *rlimits) { struct rlimit rlimits_small; + /* We might have to correct the limits values. Since the old values * were signed the new values might be too large. */ - rlimits_small.rlim_cur = RMIN ((unsigned long int) rlimits->rlim_cur, - RLIM_INFINITY >> 1); - rlimits_small.rlim_max = RMIN ((unsigned long int) rlimits->rlim_max, - RLIM_INFINITY >> 1); - return(__setrlimit(resource, &rlimits_small)); + rlimits_small.rlim_cur = RMIN((unsigned long int) rlimits->rlim_cur, + RLIM_INFINITY >> 1); + rlimits_small.rlim_max = RMIN((unsigned long int) rlimits->rlim_max, + RLIM_INFINITY >> 1); + return (__setrlimit(resource, &rlimits_small)); } + #undef RMIN #endif -#else /* We don't need to wrap setrlimit */ +#else /* We don't need to wrap setrlimit */ #ifdef L_setrlimit #include <unistd.h> struct rlimit; -_syscall2(int, setrlimit, unsigned int, resource, const struct rlimit *, rlim); +_syscall2(int, setrlimit, unsigned int, resource, + const struct rlimit *, rlim); #endif -#endif /* __NR_setrlimit */ +#endif /* __NR_setrlimit */ //#define __NR_getrlimit 76 #ifdef L___getrlimit -/* Only include the old getrlimit if the new one (ugetrlimit) is not around */ +/* Only include the old getrlimit if the new one (ugetrlimit) is not around */ #ifndef __NR_ugetrlimit #define __NR___getrlimit __NR_getrlimit #include <unistd.h> #include <sys/resource.h> _syscall2(int, __getrlimit, int, resource, struct rlimit *, rlim); -int getrlimit (__rlimit_resource_t resource, struct rlimit *rlimits) +int getrlimit(__rlimit_resource_t resource, struct rlimit *rlimits) { int result; + result = __getrlimit(resource, rlimits); if (result == -1) @@ -884,7 +924,7 @@ int getrlimit (__rlimit_resource_t resource, struct rlimit *rlimits) return result; } #endif -#endif /* __NR_getrlimit */ +#endif /* __NR_getrlimit */ //#define __NR_getrusage 77 #ifdef L_getrusage @@ -913,7 +953,7 @@ _syscall2(int, settimeofday, const struct timeval *, tv, static inline _syscall2(int, __syscall_getgroups, int, size, __kernel_gid_t *, list); #define MIN(a,b) (((a)<(b))?(a):(b)) -int getgroups(int n, gid_t *groups) +int getgroups(int n, gid_t * groups) { if (unlikely(n < 0)) { __set_errno(EINVAL); @@ -921,6 +961,7 @@ int getgroups(int n, gid_t *groups) } else { int i, ngids; __kernel_gid_t kernel_groups[n = MIN(n, sysconf(_SC_NGROUPS_MAX))]; + ngids = __syscall_getgroups(n, kernel_groups); if (n != 0 && ngids > 0) { for (i = 0; i < ngids; i++) { @@ -938,23 +979,25 @@ int getgroups(int n, gid_t *groups) #include <grp.h> #define __NR___syscall_setgroups __NR_setgroups static inline -_syscall2(int, __syscall_setgroups, size_t, size, const __kernel_gid_t *, list); -int setgroups (size_t n, const gid_t *groups) +_syscall2(int, __syscall_setgroups, size_t, size, + const __kernel_gid_t *, list); +int setgroups(size_t n, const gid_t * groups) { - if (n > (size_t)sysconf(_SC_NGROUPS_MAX)) { - __set_errno (EINVAL); + if (n > (size_t) sysconf(_SC_NGROUPS_MAX)) { + __set_errno(EINVAL); return -1; } else { size_t i; __kernel_gid_t kernel_groups[n]; + for (i = 0; i < n; i++) { kernel_groups[i] = (groups)[i]; - if (groups[i] != (gid_t) ((__kernel_gid_t)groups[i])) { - __set_errno (EINVAL); + if (groups[i] != (gid_t) ((__kernel_gid_t) groups[i])) { + __set_errno(EINVAL); return -1; } } - return(__syscall_setgroups(n, kernel_groups)); + return (__syscall_setgroups(n, kernel_groups)); } } #endif @@ -964,10 +1007,10 @@ int setgroups (size_t n, const gid_t *groups) //Used as a fallback if _newselect isn't available... #ifndef __NR__newselect #include <unistd.h> -extern int select(int n, fd_set *readfds, fd_set *writefds, - fd_set *exceptfds, struct timeval *timeout); +extern int select(int n, fd_set * readfds, fd_set * writefds, + fd_set * exceptfds, struct timeval *timeout); _syscall5(int, select, int, n, fd_set *, readfds, fd_set *, writefds, - fd_set *, exceptfds, struct timeval *, timeout); + fd_set *, exceptfds, struct timeval *, timeout); #endif #endif @@ -1000,10 +1043,8 @@ _syscall2(int, swapon, const char *, path, int, swapflags); //#define __NR_reboot 88 #ifdef L__reboot #define __NR__reboot __NR_reboot -extern int _reboot(int magic, int magic2, int flag); - +static inline _syscall3(int, _reboot, int, magic, int, magic2, int, flag); - int reboot(int flag) { return (_reboot((int) 0xfee1dead, 672274793, flag)); @@ -1018,9 +1059,7 @@ int reboot(int flag) #include <unistd.h> #include <sys/mman.h> extern __ptr_t _mmap(unsigned long *buffer); - _syscall1(__ptr_t, _mmap, unsigned long *, buffer); - __ptr_t mmap(__ptr_t addr, size_t len, int prot, int flags, int fd, __off_t offset) { @@ -1059,11 +1098,11 @@ _syscall2(int, ftruncate, int, fd, __off_t, length); #ifdef L___syscall_fchmod #include <sys/stat.h> #define __NR___syscall_fchmod __NR_fchmod -static inline +static inline _syscall2(int, __syscall_fchmod, int, fildes, __kernel_mode_t, mode); int fchmod(int fildes, mode_t mode) { - return(__syscall_fchmod(fildes, mode)); + return (__syscall_fchmod(fildes, mode)); } #endif @@ -1072,16 +1111,16 @@ int fchmod(int fildes, mode_t mode) #include <unistd.h> #define __NR___syscall_fchown __NR_fchown static inline -_syscall3(int, __syscall_fchown, int, fd, __kernel_uid_t, owner, __kernel_gid_t, group); +_syscall3(int, __syscall_fchown, int, fd, __kernel_uid_t, owner, + __kernel_gid_t, group); int fchown(int fd, uid_t owner, gid_t group) { - if (((owner + 1) > (uid_t) ((__kernel_uid_t) -1U)) - || ((group + 1) > (gid_t) ((__kernel_gid_t) -1U))) - { - __set_errno (EINVAL); + if (((owner + 1) > (uid_t) ((__kernel_uid_t) - 1U)) + || ((group + 1) > (gid_t) ((__kernel_gid_t) - 1U))) { + __set_errno(EINVAL); return -1; } - return(__syscall_fchown(fd, owner, group)); + return (__syscall_fchown(fd, owner, group)); } #endif @@ -1089,11 +1128,12 @@ int fchown(int fd, uid_t owner, gid_t group) #ifdef L___syscall_getpriority #include <sys/resource.h> #define __NR___syscall_getpriority __NR_getpriority -_syscall2(int, __syscall_getpriority, __priority_which_t, which, id_t, who); +_syscall2(int, __syscall_getpriority, __priority_which_t, which, id_t, + who); /* The return value of __syscall_getpriority is biased by this value * to avoid returning negative values. */ #define PZERO 20 -int getpriority (enum __priority_which which, id_t who) +int getpriority(enum __priority_which which, id_t who) { int res; @@ -1107,7 +1147,8 @@ int getpriority (enum __priority_which which, id_t who) //#define __NR_setpriority 97 #ifdef L_setpriority #include <sys/resource.h> -_syscall3(int, setpriority, __priority_which_t, which, id_t, who, int, prio); +_syscall3(int, setpriority, __priority_which_t, which, + id_t, who, int, prio); #endif //#define __NR_profil 98 @@ -1120,7 +1161,7 @@ _syscall3(int, setpriority, __priority_which_t, which, id_t, who, int, prio); #include <sys/vfs.h> static inline _syscall2(int, __syscall_statfs, const char *, path, struct statfs *, buf); -weak_alias(__syscall_statfs, statfs) +weak_alias(__syscall_statfs, statfs); #endif //#define __NR_fstatfs 100 @@ -1132,13 +1173,14 @@ _syscall2(int, fstatfs, int, fd, struct statfs *, buf); //#define __NR_ioperm 101 #ifdef L_ioperm # if defined __ARCH_HAS_MMU__ && defined __NR_ioperm - _syscall3(int, ioperm, unsigned long, from, unsigned long, num, int, turn_on); +_syscall3(int, ioperm, unsigned long, from, unsigned long, num, + int, turn_on); # else - int ioperm(unsigned long from, unsigned long num, int turn_on) - { - __set_errno(ENOSYS); - return -1; - } +int ioperm(unsigned long from, unsigned long num, int turn_on) +{ + __set_errno(ENOSYS); + return -1; +} # endif #endif @@ -1154,10 +1196,8 @@ _syscall2(int, __socketcall, int, call, unsigned long *, args); #ifdef L__syslog #include <unistd.h> #define __NR__syslog __NR_syslog -extern int _syslog(int type, char *buf, int len); - +static inline _syscall3(int, _syslog, int, type, char *, buf, int, len); - int klogctl(int type, char *buf, int len) { return (_syslog(type, buf, len)); @@ -1175,7 +1215,8 @@ _syscall3(int, setitimer, __itimer_which_t, which, //#define __NR_getitimer 105 #ifdef L_getitimer #include <sys/time.h> -_syscall2(int, getitimer, __itimer_which_t, which, struct itimerval *, value); +_syscall2(int, getitimer, __itimer_which_t, which, + struct itimerval *, value); #endif //#define __NR_stat 106 @@ -1185,17 +1226,20 @@ _syscall2(int, getitimer, __itimer_which_t, which, struct itimerval *, value); #define _SYS_STAT_H #include <bits/stat.h> #include "xstatconv.h" -_syscall2(int, __syscall_stat, const char *, file_name, struct kernel_stat *, buf); -int stat(const char * file_name, struct stat * buf) +_syscall2(int, __syscall_stat, const char *, file_name, + struct kernel_stat *, buf); +int stat(const char *file_name, struct stat *buf) { int result; struct kernel_stat kbuf; + result = __syscall_stat(file_name, &kbuf); if (result == 0) { __xstat_conv(&kbuf, buf); } return result; } + #if ! defined __NR_stat64 && defined __UCLIBC_HAS_LFS__ weak_alias(stat, stat64); #endif @@ -1209,17 +1253,20 @@ weak_alias(stat, stat64); #include <bits/stat.h> #include <bits/kernel_stat.h> #include "xstatconv.h" -_syscall2(int, __syscall_lstat, const char *, file_name, struct kernel_stat *, buf); -int lstat(const char * file_name, struct stat * buf) +_syscall2(int, __syscall_lstat, const char *, file_name, + struct kernel_stat *, buf); +int lstat(const char *file_name, struct stat *buf) { int result; struct kernel_stat kbuf; + result = __syscall_lstat(file_name, &kbuf); if (result == 0) { __xstat_conv(&kbuf, buf); } return result; } + #if ! defined __NR_lstat64 && defined __UCLIBC_HAS_LFS__ weak_alias(lstat, lstat64); #endif @@ -1234,16 +1281,18 @@ weak_alias(lstat, lstat64); #include <bits/kernel_stat.h> #include "xstatconv.h" _syscall2(int, __syscall_fstat, int, fd, struct kernel_stat *, buf); -int fstat(int fd, struct stat * buf) +int fstat(int fd, struct stat *buf) { int result; struct kernel_stat kbuf; + result = __syscall_fstat(fd, &kbuf); if (result == 0) { __xstat_conv(&kbuf, buf); } return result; } + #if ! defined __NR_fstat64 && defined __UCLIBC_HAS_LFS__ weak_alias(fstat, fstat64); #endif @@ -1257,13 +1306,13 @@ weak_alias(fstat, fstat64); #if !defined(__arm__) /* Tuns out the m68k unistd.h kernel header is broken */ # if defined __ARCH_HAS_MMU__ && defined __NR_iopl && ( !defined(__mc68000__)) - _syscall1(int, iopl, int, level); +_syscall1(int, iopl, int, level); # else - int iopl(int level) - { - __set_errno(ENOSYS); - return -1; - } +int iopl(int level) +{ + __set_errno(ENOSYS); + return -1; +} # endif # endif #endif @@ -1283,10 +1332,11 @@ _syscall0(int, vhangup); #ifdef L___syscall_wait4 #define __NR___syscall_wait4 __NR_wait4 static inline -_syscall4(int, __syscall_wait4, __kernel_pid_t, pid, int *, status, int, opts, void *, rusage); -int wait4(pid_t pid, int * status, int opts, void * rusage) +_syscall4(int, __syscall_wait4, __kernel_pid_t, pid, int *, status, int, + opts, void *, rusage); +int wait4(pid_t pid, int *status, int opts, void *rusage) { - return(__syscall_wait4(pid, status, opts, rusage)); + return (__syscall_wait4(pid, status, opts, rusage)); } #endif @@ -1306,7 +1356,8 @@ _syscall1(int, sysinfo, struct sysinfo *, info); #ifdef L___ipc #ifdef __NR_ipc #define __NR___ipc __NR_ipc -_syscall5(int, __ipc, unsigned int, call, int, first, int, second, int, third, void *, ptr); +_syscall5(int, __ipc, unsigned int, call, int, first, int, second, int, + third, void *, ptr); #endif #endif @@ -1315,7 +1366,7 @@ _syscall5(int, __ipc, unsigned int, call, int, first, int, second, int, third, v #include <unistd.h> #define __NR___libc_fsync __NR_fsync _syscall1(int, |