2 meinOS - A unix-like x86 microkernel operating system
3 Copyright (C) 2008 Janosch Gräf <janosch.graef@gmx.net>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include <sys/types.h>
30 #define NULL ((void*)0)
33 #define _POSIX_VERSION 200112L
34 #define _POSIX2_VERSION 200112L
36 #define SEEK_SET 0 // Seek from beginning of file
37 #define SEEK_CUR 1 // Seek from current position
38 #define SEEK_END 2 // Seek from end of file
40 #define STDIN_FILENO 0
41 #define STDOUT_FILENO 1
42 #define STDERR_FILENO 2
44 #define _exit(r) _Exit(r)
45 #define getpid() syscall_call(SYSCALL_PROC_GETPID,0)
46 #define getppid() getppidbypid(getpid())
48 #define dup(fildes) dup2(fildes,0)
50 /// @todo When symlinks are (completely) implemented, this has to be rewritten
51 #define lstat(path,buf) stat(path,buf)
54 int optind
,opterr
,optopt
;
57 int chown(const char *file
,uid_t uid
,gid_t gid
);
58 int fchown(int fildes
,uid_t uid
,gid_t gid
);
59 int symlink(const char *path1
,const char *path2
);
60 ssize_t
readlink(const char *path
,char *buf
,size_t bufsize
);
61 int symlink(const char *src
,const char *dest
);
62 int link(const char *src
, const char *dest
);
63 int access(const char *path
,int amode
);
64 int chdir(const char *dir
);
65 int fchdir(int fildes
);
66 char *getcwd(char *, size_t);
67 int dup2(int fildes
,int fildes2
);
68 int close(int fildes
);
69 ssize_t
read(int fildes
,void *buf
,size_t nbyte
);
70 ssize_t
write(int fildes
,const void *buf
,size_t count
);
71 ssize_t
pread(int fildes
,void *buf
,size_t count
,off_t offset
);
72 ssize_t
pwrite(int fildes
,const void *buf
,size_t count
,off_t offset
);
73 off_t
lseek(int fildes
,off_t offset
,int whence
);
74 int unlink(const char *path
);
75 int rmdir(const char *path
);
76 int ftruncate(int fildes
,off_t length
);
77 int truncate(const char *path
,off_t length
);
78 int pipe(int fildes
[2]);
79 char *ttyname(int fildes
);
80 int isatty(int fildes
);
82 int gethostname(char *, size_t);
83 void swab(const void *buf1
,void *buf2
,ssize_t size
);
84 unsigned sleep(unsigned sec
);
85 int usleep(useconds_t usec
);
87 int getopt(int argc
, char *const *argv
, const char *optstring
);
89 int execl(const char *path
, ... /*, (char *)0 */);
90 int execv(const char *path
, char *const argv
[]);
91 int execle(const char *path
, ... /*, (char *)0, char *const envp[]*/);
92 int execve(const char *path
, char *const argv
[], char *const envp
[]);
93 int execlp(const char *file
, ... /*, (char *)0 */);
94 int execvp(const char *file
, char *const argv
[]);
102 static __inline__
getuid(void) {
103 return syscall_call(SYSCALL_PROC_GETUID
,1,1);
105 static __inline__
geteuid(void) {
106 return syscall_call(SYSCALL_PROC_GETUID
,2,1);
108 static __inline__
getgid(void) {
109 return syscall_call(SYSCALL_PROC_GETGID
,1,1);
111 static __inline__
getegid(void) {
112 return syscall_call(SYSCALL_PROC_GETGID
,2,1);
114 static __inline__
setuid(uid_t uid
) {
115 syscall_call(SYSCALL_PROC_SETUID
,2,1,uid
);
116 syscall_call(SYSCALL_PROC_SETUID
,2,2,uid
);
117 syscall_call(SYSCALL_PROC_SETUID
,2,3,uid
);
119 static __inline__
seteuid(uid_t uid
) {
120 syscall_call(SYSCALL_PROC_SETUID
,2,2,uid
);
122 static __inline__
setreuid(uid_t ruid
,uid_t euid
) {
123 syscall_call(SYSCALL_PROC_SETUID
,2,1,ruid
);
124 syscall_call(SYSCALL_PROC_SETUID
,2,2,euid
);
126 static __inline__
setgid(gid_t gid
) {
127 syscall_call(SYSCALL_PROC_SETGID
,2,1,gid
);
128 syscall_call(SYSCALL_PROC_SETGID
,2,2,gid
);
129 syscall_call(SYSCALL_PROC_SETGID
,2,3,gid
);
131 static __inline__
setegid(gid_t gid
) {
132 syscall_call(SYSCALL_PROC_SETGID
,2,2,gid
);
134 static __inline__
setregid(gid_t rgid
,gid_t egid
) {
135 syscall_call(SYSCALL_PROC_SETGID
,2,1,rgid
);
136 syscall_call(SYSCALL_PROC_SETGID
,2,2,egid
);