mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Added access(2).
This commit is contained in:
parent
cd350620f2
commit
4b2c22d480
6 changed files with 73 additions and 2 deletions
|
@ -30,6 +30,7 @@
|
|||
|
||||
#include <features.h>
|
||||
#include <sortix/seek.h>
|
||||
#include <sortix/unistd.h>
|
||||
|
||||
#define _SORTIX_ALWAYS_SBRK
|
||||
|
||||
|
@ -79,7 +80,6 @@ __BEGIN_DECLS
|
|||
|
||||
/* TODO: These are not implemented in libmaxsi/sortix yet. */
|
||||
#if defined(__SORTIX_SHOW_UNIMPLEMENTED)
|
||||
int access(const char*, int);
|
||||
unsigned alarm(unsigned);
|
||||
int chown(const char*, uid_t, gid_t);
|
||||
size_t confstr(int, char*, size_t);
|
||||
|
@ -150,6 +150,7 @@ extern char* optarg;
|
|||
extern int opterr, optind, optopt;
|
||||
#endif
|
||||
|
||||
int access(const char*, int);
|
||||
int chdir(const char*);
|
||||
int close(int);
|
||||
int dup(int);
|
||||
|
|
|
@ -58,6 +58,7 @@ namespace Maxsi
|
|||
DEFN_SYSCALL2(int, SysStat, SYSCALL_STAT, const char*, struct stat*);
|
||||
DEFN_SYSCALL2(int, SysFStat, SYSCALL_FSTAT, int, struct stat*);
|
||||
DEFN_SYSCALL3(int, SysFCntl, SYSCALL_FCNTL, int, int, unsigned long);
|
||||
DEFN_SYSCALL2(int, SysAccess, SYSCALL_ACCESS, const char*, int);
|
||||
|
||||
size_t Print(const char* string)
|
||||
{
|
||||
|
@ -299,6 +300,11 @@ namespace Maxsi
|
|||
return SysFCntl(fd, cmd, arg);
|
||||
}
|
||||
|
||||
extern "C" int access(const char* pathname, int mode)
|
||||
{
|
||||
return SysAccess(pathname, mode);
|
||||
}
|
||||
|
||||
// TODO: Implement these in the kernel.
|
||||
extern "C" int chmod(const char* path, mode_t mode)
|
||||
{
|
||||
|
|
|
@ -90,6 +90,7 @@ termmode.h \
|
|||
syscallnum.h \
|
||||
stat.h \
|
||||
timeval.h \
|
||||
unistd.h \
|
||||
|
||||
OBJS=$(CPUOBJS) \
|
||||
kernel.o \
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include "directory.h"
|
||||
#include "mount.h"
|
||||
#include <sortix/fcntl.h>
|
||||
#include <sortix/unistd.h>
|
||||
|
||||
using namespace Maxsi;
|
||||
|
||||
|
@ -83,6 +84,26 @@ namespace Sortix
|
|||
return fd;
|
||||
}
|
||||
|
||||
int SysAccess(const char* pathname, int mode)
|
||||
{
|
||||
int oflags = 0;
|
||||
bool exec = mode & X_OK;
|
||||
bool read = mode & R_OK;
|
||||
bool write = mode & W_OK;
|
||||
if ( mode == F_OK ) { oflags = O_RDONLY; }
|
||||
if ( exec && !read && !write ) { oflags = O_EXEC; }
|
||||
if ( exec && read && !write ) { oflags = O_EXEC; }
|
||||
if ( exec && !read && write ) { oflags = O_EXEC; }
|
||||
if ( exec && read && write ) { oflags = O_EXEC; }
|
||||
if ( !exec && read && write ) { oflags = O_RDWR; }
|
||||
if ( !exec && !read && write ) { oflags = O_WRONLY; }
|
||||
if ( !exec && read && !write ) { oflags = O_RDONLY; }
|
||||
Device* dev = Open(pathname, oflags, 0);
|
||||
if ( !dev ) { return -1; }
|
||||
dev->Unref();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SysUnlink(const char* path)
|
||||
{
|
||||
return Unlink(path) ? 0 : -1;
|
||||
|
@ -156,6 +177,7 @@ namespace Sortix
|
|||
Syscall::Register(SYSCALL_STAT, (void*) SysStat);
|
||||
Syscall::Register(SYSCALL_FSTAT, (void*) SysFStat);
|
||||
Syscall::Register(SYSCALL_FCNTL, (void*) SysFCntl);
|
||||
Syscall::Register(SYSCALL_ACCESS, (void*) SysAccess);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -71,7 +71,8 @@
|
|||
#define SYSCALL_STAT 44
|
||||
#define SYSCALL_FSTAT 45
|
||||
#define SYSCALL_FCNTL 46
|
||||
#define SYSCALL_MAX_NUM 47 /* index of highest constant + 1 */
|
||||
#define SYSCALL_ACCESS 47
|
||||
#define SYSCALL_MAX_NUM 48 /* index of highest constant + 1 */
|
||||
|
||||
#endif
|
||||
|
||||
|
|
40
sortix/unistd.h
Normal file
40
sortix/unistd.h
Normal file
|
@ -0,0 +1,40 @@
|
|||
/*******************************************************************************
|
||||
|
||||
COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2012.
|
||||
|
||||
This file is part of Sortix.
|
||||
|
||||
Sortix is free software: you can redistribute it and/or modify it under the
|
||||
terms of the GNU General Public License as published by the Free Software
|
||||
Foundation, either version 3 of the License, or (at your option) any later
|
||||
version.
|
||||
|
||||
Sortix 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 General Public License for more
|
||||
details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with
|
||||
Sortix. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
unistd.h
|
||||
Standard symbolic constants and types.
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef SORTIX_UNISTD_H
|
||||
#define SORTIX_UNISTD_H
|
||||
|
||||
#include <features.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
#define R_OK 4 /* Test for read permission. */
|
||||
#define W_OK 2 /* Test for write permission. */
|
||||
#define X_OK 1 /* Test for execute permission. */
|
||||
#define F_OK 0 /* Test for existence. */
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif
|
||||
|
Loading…
Add table
Reference in a new issue