fixed bash/dash/sh issue (Ubuntu)
[zpugcc/jano.git] / toolchain / gcc / newlib / libc / sys / sh / syscalls.c
blobf0e924297322ec73adf0ac8781a2e699c745e18c
1 #include <_ansi.h>
2 #include <sys/types.h>
3 #include <sys/stat.h>
4 #include <sys/time.h>
5 #include "sys/syscall.h"
6 int errno;
8 /* This is used by _sbrk. */
9 register char *stack_ptr asm ("r15");
11 int
12 _read (int file,
13 char *ptr,
14 int len)
16 return __trap34 (SYS_read, file, ptr, len);
19 int
20 _lseek (int file,
21 int ptr,
22 int dir)
24 return __trap34 (SYS_lseek, file, ptr, dir);
27 int
28 _write ( int file,
29 char *ptr,
30 int len)
32 return __trap34 (SYS_write, file, ptr, len);
35 int
36 _close (int file)
38 return __trap34 (SYS_close, file, 0, 0);
41 int
42 _link (char *old, char *new)
44 return -1;
47 caddr_t
48 _sbrk (int incr)
50 extern char end; /* Defined by the linker */
51 static char *heap_end;
52 char *prev_heap_end;
54 if (heap_end == 0)
56 heap_end = &end;
58 prev_heap_end = heap_end;
59 if (heap_end + incr > stack_ptr)
61 _write (1, "Heap and stack collision\n", 25);
62 abort ();
64 heap_end += incr;
65 return (caddr_t) prev_heap_end;
68 int
69 _fstat (int file,
70 struct stat *st)
72 st->st_mode = S_IFCHR;
73 return 0;
76 int
77 _open (const char *path,
78 int flags)
80 return __trap34 (SYS_open, path, flags, 0);
83 int
84 _creat (const char *path,
85 int mode)
87 return __trap34 (SYS_creat, path, mode, 0);
90 int
91 _unlink ()
93 return -1;
96 isatty (fd)
97 int fd;
99 return 1;
102 _exit (n)
104 return __trap34 (SYS_exit, n, 0, 0);
107 _kill (n, m)
109 return __trap34 (SYS_exit, 0xdead, 0, 0);
112 _getpid (n)
114 return 1;
117 _raise ()
122 _stat (const char *path, struct stat *st)
125 return __trap34 (SYS_stat, path, st, 0);
129 _chmod (const char *path, short mode)
131 return __trap34 (SYS_chmod, path, mode);
135 _chown (const char *path, short owner, short group)
137 return __trap34 (SYS_chown, path, owner, group);
141 _utime (path, times)
142 const char *path;
143 char *times;
145 return __trap34 (SYS_utime, path, times);
149 _fork ()
151 return __trap34 (SYS_fork);
155 _wait (statusp)
156 int *statusp;
158 return __trap34 (SYS_wait);
162 _execve (const char *path, char *const argv[], char *const envp[])
164 return __trap34 (SYS_execve, path, argv, envp);
168 _execv (const char *path, char *const argv[])
170 return __trap34 (SYS_execv, path, argv);
174 _pipe (int *fd)
176 return __trap34 (SYS_pipe, fd);
179 /* This is only provided because _gettimeofday_r and _times_r are
180 defined in the same module, so we avoid a link error. */
181 clock_t
182 _times (struct tms *tp)
184 return -1;
188 _gettimeofday (struct timeval *tv, struct timezone *tz)
190 tv->tv_usec = 0;
191 tv->tv_sec = __trap34 (SYS_time);
192 return 0;
195 static inline int
196 __setup_argv_for_main (int argc)
198 char **argv;
199 int i = argc;
201 argv = __builtin_alloca ((1 + argc) * sizeof (*argv));
203 argv[i] = NULL;
204 while (i--) {
205 argv[i] = __builtin_alloca (1 + __trap34 (SYS_argnlen, i));
206 __trap34 (SYS_argn, i, argv[i]);
209 return main (argc, argv);
213 __setup_argv_and_call_main ()
215 int argc = __trap34 (SYS_argc);
217 if (argc <= 0)
218 return main (argc, NULL);
219 else
220 return __setup_argv_for_main (argc);