mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Add symlink(2) and symlinkat(2) stub.
This commit is contained in:
parent
a0e2934c8c
commit
500d3bb38b
6 changed files with 103 additions and 3 deletions
|
@ -481,6 +481,8 @@ unistd/setpgid.o \
|
|||
unistd/setuid.o \
|
||||
unistd/sfork.o \
|
||||
unistd/sleep.o \
|
||||
unistd/symlinkat.o \
|
||||
unistd/symlink.o \
|
||||
unistd/sysconf.o \
|
||||
unistd/tcgetpgrp.o \
|
||||
unistd/tcsetpgrp.o \
|
||||
|
|
|
@ -285,8 +285,6 @@ int setregid(gid_t, gid_t);
|
|||
int setreuid(uid_t, uid_t);
|
||||
pid_t setsid(void);
|
||||
void swab(const void* __restrict, void* __restrict, ssize_t);
|
||||
int symlink(const char*, const char*);
|
||||
int symlinkat(const char*, int, const char*);
|
||||
void sync(void);
|
||||
int ttyname_r(int, char*, size_t);
|
||||
#endif
|
||||
|
@ -349,6 +347,8 @@ int setgid(gid_t);
|
|||
int setpgid(pid_t, pid_t);
|
||||
int setuid(uid_t);
|
||||
unsigned sleep(unsigned);
|
||||
int symlink(const char*, const char*);
|
||||
int symlinkat(const char*, int, const char*);
|
||||
long sysconf(int);
|
||||
pid_t tcgetpgrp(int);
|
||||
int tcsetpgrp(int, pid_t);
|
||||
|
|
31
libc/unistd/symlink.cpp
Normal file
31
libc/unistd/symlink.cpp
Normal file
|
@ -0,0 +1,31 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Copyright(C) Jonas 'Sortie' Termansen 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/>.
|
||||
|
||||
unistd/symlink.cpp
|
||||
Create a symbolic link.
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
extern "C" int symlink(const char* oldpath, const char* newpath)
|
||||
{
|
||||
return symlinkat(oldpath, AT_FDCWD, newpath);
|
||||
}
|
35
libc/unistd/symlinkat.cpp
Normal file
35
libc/unistd/symlinkat.cpp
Normal file
|
@ -0,0 +1,35 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Copyright(C) Jonas 'Sortie' Termansen 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/>.
|
||||
|
||||
unistd/symlinkat.cpp
|
||||
Create a symbolic link.
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#include <sys/syscall.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
DEFN_SYSCALL3(int, sys_symlinkat, SYSCALL_LINKAT, const char*, int, const char*);
|
||||
|
||||
extern "C" int symlinkat(const char* oldpath, int newdirfd, const char* newpath)
|
||||
{
|
||||
return sys_symlinkat(oldpath, newdirfd, newpath);
|
||||
}
|
|
@ -144,6 +144,7 @@
|
|||
#define SYSCALL_SETPRIORITY 120
|
||||
#define SYSCALL_PRLIMIT 121
|
||||
#define SYSCALL_DUP3 122
|
||||
#define SYSCALL_MAX_NUM 123 /* index of highest constant + 1 */
|
||||
#define SYSCALL_SYMLINKAT 123
|
||||
#define SYSCALL_MAX_NUM 124 /* index of highest constant + 1 */
|
||||
|
||||
#endif
|
||||
|
|
|
@ -595,6 +595,36 @@ static int sys_link(const char* oldpath, const char* newpath)
|
|||
return sys_linkat(AT_FDCWD, oldpath, AT_FDCWD, newpath, 0);
|
||||
}
|
||||
|
||||
static int sys_symlinkat(const char* oldpath, int newdirfd, const char* newpath)
|
||||
{
|
||||
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
||||
|
||||
char* newpathcopy = GetStringFromUser(newpath);
|
||||
if ( !newpathcopy )
|
||||
return -1;
|
||||
const char* newrelpath = newpathcopy;
|
||||
Ref<Descriptor> newfrom(PrepareLookup(&newrelpath, newdirfd));
|
||||
if ( !newfrom ) { delete[] newpathcopy; return -1; }
|
||||
|
||||
char* final_elem;
|
||||
Ref<Descriptor> dir = OpenDirContainingPath(&ctx, newfrom, newpathcopy,
|
||||
&final_elem);
|
||||
delete[] newpathcopy;
|
||||
if ( !dir )
|
||||
return -1;
|
||||
|
||||
char* oldpathcopy = GetStringFromUser(oldpath);
|
||||
if ( !oldpathcopy ) { delete[] final_elem; return -1; }
|
||||
|
||||
int ret = (errno = EPERM, -1);
|
||||
|
||||
delete[] oldpathcopy;
|
||||
delete[] final_elem;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static int sys_settermmode(int fd, unsigned mode)
|
||||
{
|
||||
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
|
||||
|
@ -1019,6 +1049,7 @@ void Init()
|
|||
Syscall::Register(SYSCALL_SEND, (void*) sys_send);
|
||||
Syscall::Register(SYSCALL_SETTERMMODE, (void*) sys_settermmode);
|
||||
Syscall::Register(SYSCALL_STAT, (void*) sys_stat);
|
||||
Syscall::Register(SYSCALL_SYMLINKAT, (void*) sys_symlinkat);
|
||||
Syscall::Register(SYSCALL_TCGETPGRP, (void*) sys_tcgetpgrp);
|
||||
Syscall::Register(SYSCALL_TCGETWINSIZE, (void*) sys_tcgetwinsize);
|
||||
Syscall::Register(SYSCALL_TCSETPGRP, (void*) sys_tcsetpgrp);
|
||||
|
|
Loading…
Reference in a new issue