/* vi: set sw=4 ts=4: */
/*
* Syscalls for uClibc
*
* Copyright (C) 2000 by Lineo, inc
* Copyright (C) 2001 by Erik Andersen
* Written by Erik Andersen <andersen@codpoet.org>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Library General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program 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 Library General Public License
* for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include <errno.h>
#include <features.h>
#include <sys/types.h>
#include <sys/syscall.h>
//#define __NR_exit 1
#ifdef L__exit
/* Do not include unistd.h, so gcc doesn't whine about
* _exit returning. It really doesn't return... */
#define __NR__exit __NR_exit
#ifdef __STR_NR_exit
#define __STR_NR__exit __STR_NR_exit
#endif
_syscall1(void, _exit, int, status);
#endif
//#define __NR_fork 2
#ifdef L_fork
#include <unistd.h>
# ifdef __UCLIBC_HAS_MMU__
_syscall0(pid_t, fork);
# else
pid_t fork(void)
{
__set_errno(ENOSYS);
return -1;
}
# endif
#endif
//#define __NR_read 3
#ifdef L_read
#include <unistd.h>
_syscall3(ssize_t, read, int, fd, __ptr_t, buf, size_t, count);
#endif
//#define __NR_write 4
#ifdef L_write
#include <unistd.h>
_syscall3(ssize_t, write, int, fd, const __ptr_t, buf, size_t, count);
weak_alias(write, __write);
#endif
//#define __NR_open 5
#ifdef L___open
#include <stdarg.h>
#include <fcntl.h>
#define __NR___open __NR_open
#ifdef __STR_NR_open
#define __STR_NR___open __STR_NR_open
#endif
_syscall3(int, __open, const char *, fn, int, flags, mode_t, mode);
int open(const char *file, int oflag, ...)
{
int mode = 0;
if (oflag & O_CREAT) {
va_list args;
va_start(args, oflag);
mode = va_arg(args, int);
va_end(args);
}
return __open(file, oflag, mode);
}
#endif
//#define __NR_close 6
#ifdef L_close
#include <unistd.h>
_syscall1(int, close, int, fd);
#endif
//#define __NR_waitpid 7
// Implemented using wait4
//#define __NR_creat 8
#ifdef L_creat
#include <fcntl.h>
_syscall2(int, creat, const char *, file, mode_t, mode);
#endif
//#define __NR_link 9
#ifdef L_link
#include <unistd.h>
_syscall2(int, link, const char *, oldpath, const char *, newpath);
#endif
//#define __NR_unlink 10
#ifdef L_unlink
#include <unistd.h>
_syscall1(int, unlink, const char *, pathname);
#endif
//#define __NR_execve 11
#ifdef L_execve
#include <unistd.h>
_syscall3(int, execve, const char *, filename, char *const *, argv,
char *const *, envp);
#endif
//#define __NR_chdir 12
#ifdef L_chdir
#include <unistd.h>
_syscall1(int, chdir, const char *, path);
#endif
//#define __NR_time 13
#ifdef L_time
#include <time.h>
_syscall1(time_t, time, time_t *, t);
#endif
//#define __NR_mknod 14
#ifdef L_mknod
#include <unistd.h>
extern int mknod(const char *pathname, mode_t mode, dev_t dev);
_syscall3(int, mknod, const char *, pathname, mode_t, mode, dev_t, dev);
int __xmknod (int version, const char * path, mode_t mode, dev_t *dev)
{
switch(version)
{
case 1:
return mknod (path, mode, *dev);
default:
__set_errno(EINVAL);
return -1;
}
}
#endif
//#define __NR_chmod 15
#ifdef L_chmod
#include <sys/stat.h>
_syscall2(int, chmod, const char *, path, mode_t, mode);
#endif
/* Old kernels don't have lchown -- do chown instead. This
* is sick and wrong, but at least things will compile.
* They may not follow links when they should though... */
#ifndef __NR_lchown
#define __NR_lchown __NR_chown
#endif
//#define __NR_lchown 16
#ifdef L_lchown
#include <unistd.h>
_syscall3(int, lchown, const char *, path, uid_t, owner, gid_t, group);
#endif
//#define __NR_break 17
//#define __NR_oldstat 18
//#define __NR_lseek 19
#ifdef L_lseek
#include <unistd.h>
_syscall3(off_t, lseek, int, fildes, off_t, offset, int, whence);
#endif
//#define __NR_getpid 20
#ifdef L_getpid
#include <unistd.h>
_syscall0(pid_t, getpid);
#endif
//#define __NR_mount 21
#ifdef L_mount
#include <sys/mount.h>
_syscall5(int, mount, const char *, specialfile, const char *, dir,
const char *, filesystemtype, unsigned long, rwflag,
const void *, data);
#endif
//#define __NR_umount 22
#ifdef L_umount
#include <sys/mount.h>
_syscall1(int, umount, const char *, specialfile);
#endif
//#define __NR_setuid 23
#ifdef L_setuid
#include <unistd.h>
_syscall1(int, setuid, uid_t, uid);
#endif
//#define __NR_getuid 24
#ifdef L_getuid
#include <unistd.h>
_syscall0(gid_t, getuid);
#endif
//#define __NR_stime 25
#ifdef L_stime
#include <time.h>
_syscall1(int, stime, const time_t *, t);
#endif
//#define __NR_ptrace 26
#ifdef L___ptrace
#include <sys/ptrace.h>
#define __NR___ptrace __NR_ptrace
#ifdef __STR_NR_ptrace
#define __STR_NR___ptrace __STR_NR_ptrace
#endif
_syscall4(long, __ptrace, enum __ptrace_request, request, pid_t, pid,
void*, addr, void*, data);
#endif
//#define __NR_alarm 27
#ifdef L_alarm
#include <unistd.h>
_syscall1(unsigned int, alarm, unsigned int, seconds);
#endif
//#define __NR_oldfstat 28
//#define __NR_pause 29
#ifdef L_pause
#include <unistd.h>
_syscall0(int, pause);
#endif
//#define __NR_utime 30
#ifdef L_utime
#include <utime.h>
_syscall2(int, utime, const char *, filename, const struct utimbuf *, buf);
#endif
//#define __NR_stty 31
//#define __NR_gtty 32
//#define __NR_access 33
#ifdef L_access
#include <unistd.h>
_syscall2(int, access, const char *, pathname, int, mode);
#endif
//#define __NR_nice 34
#ifdef L_nice
#include <unistd.h>
_syscall1(int, nice, int, inc);
#endif
//#define __NR_ftime 35
//#define __NR_sync 36
#ifdef L_sync
#include <unistd.h>
_syscall0(void, sync);
#endif
//#define __NR_kill 37
#ifdef L_kill
#include <signal.h>
#undef kill
_syscall2(int, kill, pid_t, pid, int, sig);
#endif
//#define __NR_rename 38
#ifdef L_rename
#include <stdio.h>
_syscall2(int, rename, const char *, oldpath, const char *, newpath);
#endif
//#define __NR_mkdir 39
#ifdef L_mkdir
#include <sys/stat.h>
_syscall2(int, mkdir, const char *, pathname, mode_t, mode);
#endif
//#define __NR_rmdir 40
#ifdef L_rmdir
#include <unistd.h>
_syscall1(int, rmdir, const char *, pathname);
#endif
//#define __NR_dup 41
#ifdef L_dup
#include <unistd.h>
_syscall1(int, dup, int, oldfd);
#endif
//#define __NR_pipe 42
#ifdef L_pipe
#include <unistd.h>
/*
* SH has a weird register calling mechanism for pipe, see pipe.c
*/
#if !defined(__sh__)
_syscall1(int, pipe, int *, filedes);
#endif
#endif
//#define __NR_times 43
#ifdef L_times
#include <sys/times.h>
_syscall1(clock_t, times, struct tms *, buf);
#endif
//#define __NR_prof 44
//#define __NR_brk 45
//#define __NR_setgid 46
#ifdef L_setgid
#include <unistd.h>
_syscall1(int, setgid, gid_t, gid);
#endif
//#define __NR_getgid 47
#ifdef L_getgid
#include <unistd.h>
_syscall0(gid_t, getgid);
#endif
//#define __NR_signal 48
//#define __NR_geteuid 49
#ifdef L_geteuid
# ifdef __NR_geteuid
# include <unistd.h>
_syscall0(uid_t, geteuid);
# else
uid_t geteuid(void)
{
return (getuid());
}
# endif
#endif
//#define __NR_getegid 50
#ifdef L_getegid
# ifdef __NR_getegid
# include <unistd.h>
_syscall0(gid_t, getegid);
# else
gid_t getegid(void)
{
return (getgid());
}
# endif
#endif
//#define __NR_acct 51
#ifdef L_acct
#include <
|