LibC: Implement umask()
This commit is contained in:
parent
fc6c39e670
commit
5fca5c774a
|
@ -6,7 +6,7 @@
|
|||
|
||||
int creat(const char* path, mode_t mode)
|
||||
{
|
||||
return syscall(SYS_CREATE, path, S_IFREG | mode);
|
||||
return syscall(SYS_CREATE, path, S_IFREG | __UMASKED_MODE(mode));
|
||||
}
|
||||
|
||||
int open(const char* path, int oflag, ...)
|
||||
|
@ -16,7 +16,7 @@ int open(const char* path, int oflag, ...)
|
|||
mode_t mode = va_arg(args, mode_t);
|
||||
va_end(args);
|
||||
|
||||
return syscall(SYS_OPEN, path, oflag, mode);
|
||||
return syscall(SYS_OPEN, path, oflag, __UMASKED_MODE(mode));
|
||||
}
|
||||
|
||||
int openat(int fd, const char* path, int oflag, ...)
|
||||
|
@ -26,7 +26,7 @@ int openat(int fd, const char* path, int oflag, ...)
|
|||
mode_t mode = va_arg(args, mode_t);
|
||||
va_end(args);
|
||||
|
||||
return syscall(SYS_OPENAT, fd, path, oflag, mode);
|
||||
return syscall(SYS_OPENAT, fd, path, oflag, __UMASKED_MODE(mode));
|
||||
}
|
||||
|
||||
int fcntl(int fildes, int cmd, ...)
|
||||
|
|
|
@ -42,6 +42,9 @@ struct stat
|
|||
#define st_ctime st_ctim.tv_sec
|
||||
#define st_mtime st_mtim.tv_sec
|
||||
|
||||
extern mode_t __umask;
|
||||
#define __UMASKED_MODE(mode) ((mode) & ~__umask)
|
||||
|
||||
#define S_IRWXU 00700
|
||||
#define S_IRUSR 00400
|
||||
#define S_IWUSR 00200
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
#include <sys/syscall.h>
|
||||
#include <unistd.h>
|
||||
|
||||
mode_t __umask = 0;
|
||||
|
||||
int chmod(const char* path, mode_t mode)
|
||||
{
|
||||
return syscall(SYS_CHMOD, path, mode);
|
||||
|
@ -29,7 +31,14 @@ int stat(const char* __restrict path, struct stat* __restrict buf)
|
|||
return syscall(SYS_STAT, path, buf, 0);
|
||||
}
|
||||
|
||||
mode_t umask(mode_t cmask)
|
||||
{
|
||||
mode_t old = __umask;
|
||||
__umask = cmask;
|
||||
return old;
|
||||
}
|
||||
|
||||
int mkdir(const char* path, mode_t mode)
|
||||
{
|
||||
return syscall(SYS_CREATE_DIR, path, mode);
|
||||
return syscall(SYS_CREATE_DIR, path, __UMASKED_MODE(mode));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue