diff --git a/libc/Makefile b/libc/Makefile index fef266f7..82029fbd 100644 --- a/libc/Makefile +++ b/libc/Makefile @@ -171,6 +171,7 @@ linkat.o \ link.o \ localeconv.o \ lseek.o \ +lstat.o \ memstat.o \ mkdirat.o \ mkdir.o \ diff --git a/libc/access.cpp b/libc/access.cpp index 6886e233..ccdbed51 100644 --- a/libc/access.cpp +++ b/libc/access.cpp @@ -22,12 +22,10 @@ *******************************************************************************/ -#include +#include #include -DEFN_SYSCALL2(int, SysAccess, SYSCALL_ACCESS, const char*, int); - extern "C" int access(const char* pathname, int mode) { - return SysAccess(pathname, mode); + return faccessat(AT_FDCWD, pathname, mode, 0); } diff --git a/libc/chmod.cpp b/libc/chmod.cpp index 75991b89..9a05e562 100644 --- a/libc/chmod.cpp +++ b/libc/chmod.cpp @@ -24,12 +24,10 @@ #include #include -#include -#include -DEFN_SYSCALL2(int, sys_chmod, SYSCALL_CHMOD, const char*, mode_t); +#include extern "C" int chmod(const char* path, mode_t mode) { - return sys_chmod(path, mode); + return fchmodat(AT_FDCWD, path, mode, 0); } diff --git a/libc/chown.cpp b/libc/chown.cpp index 399d6131..68fe342a 100644 --- a/libc/chown.cpp +++ b/libc/chown.cpp @@ -23,12 +23,11 @@ *******************************************************************************/ #include -#include -#include -DEFN_SYSCALL3(int, sys_chown, SYSCALL_CHOWN, const char*, uid_t, gid_t); +#include +#include extern "C" int chown(const char* path, uid_t owner, gid_t group) { - return sys_chown(path, owner, group); + return fchownat(AT_FDCWD, path, owner, group, 0); } diff --git a/libc/link.cpp b/libc/link.cpp index b1826542..196f0fff 100644 --- a/libc/link.cpp +++ b/libc/link.cpp @@ -22,12 +22,10 @@ *******************************************************************************/ -#include +#include #include -DEFN_SYSCALL2(int, sys_link, SYSCALL_LINK, const char*, const char*); - extern "C" int link(const char* oldpath, const char* newpath) { - return sys_link(oldpath, newpath); + return linkat(AT_FDCWD, oldpath, AT_FDCWD, newpath, 0); } diff --git a/libc/lstat.cpp b/libc/lstat.cpp new file mode 100644 index 00000000..19e42cbf --- /dev/null +++ b/libc/lstat.cpp @@ -0,0 +1,32 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013. + + This file is part of the Sortix C Library. + + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your + option) any later version. + + The Sortix C Library is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with the Sortix C Library. If not, see . + + lstat.cpp + Retrieves status of a file. + +*******************************************************************************/ + +#include + +#include + +extern "C" int lstat(const char* path, struct stat* st) +{ + return fstatat(AT_FDCWD, path, st, AT_SYMLINK_NOFOLLOW); +} diff --git a/libc/mkdir.cpp b/libc/mkdir.cpp index cf72aa05..6cbbfcf9 100644 --- a/libc/mkdir.cpp +++ b/libc/mkdir.cpp @@ -23,11 +23,10 @@ *******************************************************************************/ #include -#include -DEFN_SYSCALL2(int, SysMkDir, SYSCALL_MKDIR, const char*, mode_t); +#include extern "C" int mkdir(const char* pathname, mode_t mode) { - return SysMkDir(pathname, mode); + return mkdirat(AT_FDCWD, pathname, mode); } diff --git a/libc/open.cpp b/libc/open.cpp index f6052d29..51372040 100644 --- a/libc/open.cpp +++ b/libc/open.cpp @@ -22,12 +22,12 @@ *******************************************************************************/ -#include +#include +#include + #include #include -DEFN_SYSCALL3(int, sys_open, SYSCALL_OPEN, const char*, int, mode_t); - extern "C" int open(const char* path, int flags, ...) { mode_t mode = 0; @@ -38,5 +38,5 @@ extern "C" int open(const char* path, int flags, ...) mode = va_arg(ap, mode_t); va_end(ap); } - return sys_open(path, flags, mode); + return openat(AT_FDCWD, path, flags, mode); } diff --git a/libc/rmdir.cpp b/libc/rmdir.cpp index 02cbca98..7f53f37d 100644 --- a/libc/rmdir.cpp +++ b/libc/rmdir.cpp @@ -22,12 +22,10 @@ *******************************************************************************/ -#include +#include #include -DEFN_SYSCALL1(int, SysRmDir, SYSCALL_RMDIR, const char*); - extern "C" int rmdir(const char* pathname) { - return SysRmDir(pathname); + return unlinkat(AT_FDCWD, pathname, AT_REMOVEDIR); } diff --git a/libc/stat.cpp b/libc/stat.cpp index c568f58e..5c70d412 100644 --- a/libc/stat.cpp +++ b/libc/stat.cpp @@ -23,17 +23,10 @@ *******************************************************************************/ #include -#include -DEFN_SYSCALL2(int, SysStat, SYSCALL_STAT, const char*, struct stat*); +#include extern "C" int stat(const char* path, struct stat* st) { - return SysStat(path, st); -} - -// TODO: Hack! -extern "C" int lstat(const char* path, struct stat* st) -{ - return SysStat(path, st); + return fstatat(AT_FDCWD, path, st, 0); } diff --git a/libc/truncate.cpp b/libc/truncate.cpp index 93ee3bcd..a986d692 100644 --- a/libc/truncate.cpp +++ b/libc/truncate.cpp @@ -22,12 +22,12 @@ *******************************************************************************/ -#include -#include +#include -DEFN_SYSCALL2(int, SysTruncate, SYSCALL_TRUNCATE, const char*, off_t); +#include +#include extern "C" int truncate(const char* pathname, off_t length) { - return SysTruncate(pathname, length); + return truncateat(AT_FDCWD, pathname, length); } diff --git a/libc/unlink.cpp b/libc/unlink.cpp index 6d8db80d..7f9ddd4c 100644 --- a/libc/unlink.cpp +++ b/libc/unlink.cpp @@ -22,12 +22,10 @@ *******************************************************************************/ -#include +#include #include -DEFN_SYSCALL1(int, SysUnlink, SYSCALL_UNLINK, const char*); - extern "C" int unlink(const char* pathname) { - return SysUnlink(pathname); + return unlinkat(AT_FDCWD, pathname, 0); } diff --git a/sortix/io.cpp b/sortix/io.cpp index 6da35eda..30db8f38 100644 --- a/sortix/io.cpp +++ b/sortix/io.cpp @@ -152,6 +152,7 @@ static int sys_openat(int dirfd, const char* path, int flags, mode_t mode) return dtable->Allocate(desc, fdflags); } +// TODO: This system call is replaced by openat, will be removed soon. static int sys_open(const char* path, int flags, mode_t mode) { return sys_openat(AT_FDCWD, path, flags, mode); @@ -174,6 +175,7 @@ static int sys_faccessat(int dirfd, const char* path, int /*mode*/, int flags) return desc ? 0 : -1; } +// TODO: This system call is replaced by faccessat, will be removed soon. static int sys_access(const char* path, int mode) { return sys_faccessat(AT_FDCWD, path, mode, 0); @@ -197,6 +199,7 @@ static int sys_unlinkat(int dirfd, const char* path, int flags) return ret; } +// TODO: This system call is replaced by unlinkat, will be removed soon. static int sys_unlink(const char* path) { return sys_unlinkat(AT_FDCWD, path, 0); @@ -216,11 +219,13 @@ static int sys_mkdirat(int dirfd, const char* path, mode_t mode) return ret; } +// TODO: This system call is replaced by mkdirat, will be removed soon. static int sys_mkdir(const char* path, mode_t mode) { return sys_mkdirat(AT_FDCWD, path, mode); } +// TODO: This system call is replaced by unlinkat, will be removed soon. static int sys_rmdir(const char* path) { return sys_unlinkat(AT_FDCWD, path, AT_REMOVEDIR); @@ -242,6 +247,7 @@ static int sys_truncateat(int dirfd, const char* path, off_t length) return desc->truncate(&ctx, length); } +// TODO: This system call is replaced by truncateat, will be removed soon. static int sys_truncate(const char* path, off_t length) { return sys_truncateat(AT_FDCWD, path, length); @@ -272,6 +278,7 @@ static int sys_fstatat(int dirfd, const char* path, struct stat* st, int /*flags return desc->stat(&ctx, st); } +// TODO: This system call is replaced by fstatat, will be removed soon. static int sys_stat(const char* path, struct stat* st) { return sys_fstatat(AT_FDCWD, path, st, 0); @@ -379,6 +386,7 @@ static int sys_fchownat(int dirfd, const char* path, uid_t owner, gid_t group, i return desc->chown(&ctx, owner, group); } +// TODO: This system call is replaced by fchownat, will be removed soon. static int sys_chown(const char* path, uid_t owner, gid_t group) { return sys_fchownat(AT_FDCWD, path, owner, group, 0); @@ -412,6 +420,7 @@ static int sys_fchmodat(int dirfd, const char* path, mode_t mode, int flags) return desc->chmod(&ctx, mode); } +// TODO: This system call is replaced by fchmodat, will be removed soon. static int sys_chmod(const char* path, mode_t mode) { return sys_fchmodat(AT_FDCWD, path, mode, 0); @@ -455,6 +464,7 @@ static int sys_linkat(int olddirfd, const char* oldpath, return ret; } +// TODO: This system call is replaced by linkat, will be removed soon. static int sys_link(const char* oldpath, const char* newpath) { return sys_linkat(AT_FDCWD, oldpath, AT_FDCWD, newpath, 0);