OSDN Git Service

* libc/sys/sh/sys/syscall.h (SYS_get_argc, SYS_get_argN_len,
authoraoliva <aoliva>
Thu, 1 Feb 2001 21:25:56 +0000 (21:25 +0000)
committeraoliva <aoliva>
Thu, 1 Feb 2001 21:25:56 +0000 (21:25 +0000)
SYS_get_argN):
* libc/sys/sh/syscalls.c (__setup_argv_for_main,
__setup_argv_and_call_main): New.

newlib/ChangeLog
newlib/libc/sys/sh/sys/syscall.h
newlib/libc/sys/sh/syscalls.c

index 741fd7b..d626c26 100644 (file)
@@ -1,3 +1,10 @@
+2001-02-01  Alexandre Oliva  <aoliva@redhat.com>
+
+       * libc/sys/sh/sys/syscall.h (SYS_get_argc, SYS_get_argN_len,
+       SYS_get_argN):
+       * libc/sys/sh/syscalls.c (__setup_argv_for_main,
+       __setup_argv_and_call_main): New.
+
 2001-01-31  Jeff Johnston  <jjohnstn@redhat.com>
 
        * libc/include/stdio.h (FILENAME_MAX): Changed to use __FILENAME_MAX__
index f141df7..fd9ee7c 100644 (file)
@@ -27,5 +27,9 @@
 #define        SYS_pipe        42
 #define        SYS_execve      59
 
+#define SYS_argc       172 /* == 0xAC, for Argument Count :-) */
+#define SYS_argnlen    173
+#define SYS_argn       174
+
 #define SYS_utime       201 /* not really a system call */
 #define SYS_wait        202 /* nor is this */
index 8380c70..f0e9242 100644 (file)
@@ -191,3 +191,31 @@ _gettimeofday (struct timeval *tv, struct timezone *tz)
   tv->tv_sec = __trap34 (SYS_time);
   return 0;
 }
+
+static inline int
+__setup_argv_for_main (int argc)
+{
+  char **argv;
+  int i = argc;
+
+  argv = __builtin_alloca ((1 + argc) * sizeof (*argv));
+
+  argv[i] = NULL;
+  while (i--) {
+    argv[i] = __builtin_alloca (1 + __trap34 (SYS_argnlen, i));
+    __trap34 (SYS_argn, i, argv[i]);
+  }
+
+  return main (argc, argv);
+}
+
+int
+__setup_argv_and_call_main ()
+{
+  int argc = __trap34 (SYS_argc);
+
+  if (argc <= 0)
+    return main (argc, NULL);
+  else
+    return __setup_argv_for_main (argc);
+}