mirror of
				https://gitlab.com/sortix/sortix.git
				synced 2023-02-13 20:55:38 -05:00 
			
		
		
		
	Replace system calls that accept a path with *at versions.
This commit is contained in:
		
							parent
							
								
									921deb6eeb
								
							
						
					
					
						commit
						1fa2df3e6a
					
				
					 13 changed files with 68 additions and 44 deletions
				
			
		| 
						 | 
				
			
			@ -171,6 +171,7 @@ linkat.o \
 | 
			
		|||
link.o \
 | 
			
		||||
localeconv.o \
 | 
			
		||||
lseek.o \
 | 
			
		||||
lstat.o \
 | 
			
		||||
memstat.o \
 | 
			
		||||
mkdirat.o \
 | 
			
		||||
mkdir.o \
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -22,12 +22,10 @@
 | 
			
		|||
 | 
			
		||||
*******************************************************************************/
 | 
			
		||||
 | 
			
		||||
#include <sys/syscall.h>
 | 
			
		||||
#include <fcntl.h>
 | 
			
		||||
#include <unistd.h>
 | 
			
		||||
 | 
			
		||||
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);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -24,12 +24,10 @@
 | 
			
		|||
 | 
			
		||||
#include <sys/types.h>
 | 
			
		||||
#include <sys/stat.h>
 | 
			
		||||
#include <sys/syscall.h>
 | 
			
		||||
#include <unistd.h>
 | 
			
		||||
 | 
			
		||||
DEFN_SYSCALL2(int, sys_chmod, SYSCALL_CHMOD, const char*, mode_t);
 | 
			
		||||
#include <fcntl.h>
 | 
			
		||||
 | 
			
		||||
extern "C" int chmod(const char* path, mode_t mode)
 | 
			
		||||
{
 | 
			
		||||
	return sys_chmod(path, mode);
 | 
			
		||||
	return fchmodat(AT_FDCWD, path, mode, 0);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -23,12 +23,11 @@
 | 
			
		|||
*******************************************************************************/
 | 
			
		||||
 | 
			
		||||
#include <sys/types.h>
 | 
			
		||||
#include <sys/syscall.h>
 | 
			
		||||
#include <unistd.h>
 | 
			
		||||
 | 
			
		||||
DEFN_SYSCALL3(int, sys_chown, SYSCALL_CHOWN, const char*, uid_t, gid_t);
 | 
			
		||||
#include <fcntl.h>
 | 
			
		||||
#include <unistd.h>
 | 
			
		||||
 | 
			
		||||
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);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -22,12 +22,10 @@
 | 
			
		|||
 | 
			
		||||
*******************************************************************************/
 | 
			
		||||
 | 
			
		||||
#include <sys/syscall.h>
 | 
			
		||||
#include <fcntl.h>
 | 
			
		||||
#include <unistd.h>
 | 
			
		||||
 | 
			
		||||
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);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										32
									
								
								libc/lstat.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								libc/lstat.cpp
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -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 <http://www.gnu.org/licenses/>.
 | 
			
		||||
 | 
			
		||||
    lstat.cpp
 | 
			
		||||
    Retrieves status of a file.
 | 
			
		||||
 | 
			
		||||
*******************************************************************************/
 | 
			
		||||
 | 
			
		||||
#include <sys/stat.h>
 | 
			
		||||
 | 
			
		||||
#include <fcntl.h>
 | 
			
		||||
 | 
			
		||||
extern "C" int lstat(const char* path, struct stat* st)
 | 
			
		||||
{
 | 
			
		||||
	return fstatat(AT_FDCWD, path, st, AT_SYMLINK_NOFOLLOW);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -23,11 +23,10 @@
 | 
			
		|||
*******************************************************************************/
 | 
			
		||||
 | 
			
		||||
#include <sys/stat.h>
 | 
			
		||||
#include <sys/syscall.h>
 | 
			
		||||
 | 
			
		||||
DEFN_SYSCALL2(int, SysMkDir, SYSCALL_MKDIR, const char*, mode_t);
 | 
			
		||||
#include <fcntl.h>
 | 
			
		||||
 | 
			
		||||
extern "C" int mkdir(const char* pathname, mode_t mode)
 | 
			
		||||
{
 | 
			
		||||
	return SysMkDir(pathname, mode);
 | 
			
		||||
	return mkdirat(AT_FDCWD, pathname, mode);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -22,12 +22,12 @@
 | 
			
		|||
 | 
			
		||||
*******************************************************************************/
 | 
			
		||||
 | 
			
		||||
#include <sys/syscall.h>
 | 
			
		||||
#include <sys/types.h>
 | 
			
		||||
#include <sys/stat.h>
 | 
			
		||||
 | 
			
		||||
#include <fcntl.h>
 | 
			
		||||
#include <stdarg.h>
 | 
			
		||||
 | 
			
		||||
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);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -22,12 +22,10 @@
 | 
			
		|||
 | 
			
		||||
*******************************************************************************/
 | 
			
		||||
 | 
			
		||||
#include <sys/syscall.h>
 | 
			
		||||
#include <fcntl.h>
 | 
			
		||||
#include <unistd.h>
 | 
			
		||||
 | 
			
		||||
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);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -23,17 +23,10 @@
 | 
			
		|||
*******************************************************************************/
 | 
			
		||||
 | 
			
		||||
#include <sys/stat.h>
 | 
			
		||||
#include <sys/syscall.h>
 | 
			
		||||
 | 
			
		||||
DEFN_SYSCALL2(int, SysStat, SYSCALL_STAT, const char*, struct stat*);
 | 
			
		||||
#include <fcntl.h>
 | 
			
		||||
 | 
			
		||||
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);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -22,12 +22,12 @@
 | 
			
		|||
 | 
			
		||||
*******************************************************************************/
 | 
			
		||||
 | 
			
		||||
#include <sys/syscall.h>
 | 
			
		||||
#include <unistd.h>
 | 
			
		||||
#include <sys/types.h>
 | 
			
		||||
 | 
			
		||||
DEFN_SYSCALL2(int, SysTruncate, SYSCALL_TRUNCATE, const char*, off_t);
 | 
			
		||||
#include <fcntl.h>
 | 
			
		||||
#include <unistd.h>
 | 
			
		||||
 | 
			
		||||
extern "C" int truncate(const char* pathname, off_t length)
 | 
			
		||||
{
 | 
			
		||||
	return SysTruncate(pathname, length);
 | 
			
		||||
	return truncateat(AT_FDCWD, pathname, length);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -22,12 +22,10 @@
 | 
			
		|||
 | 
			
		||||
*******************************************************************************/
 | 
			
		||||
 | 
			
		||||
#include <sys/syscall.h>
 | 
			
		||||
#include <fcntl.h>
 | 
			
		||||
#include <unistd.h>
 | 
			
		||||
 | 
			
		||||
DEFN_SYSCALL1(int, SysUnlink, SYSCALL_UNLINK, const char*);
 | 
			
		||||
 | 
			
		||||
extern "C" int unlink(const char* pathname)
 | 
			
		||||
{
 | 
			
		||||
	return SysUnlink(pathname);
 | 
			
		||||
	return unlinkat(AT_FDCWD, pathname, 0);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue