add __progname global variable
authorKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Sat, 13 Feb 1993 09:51:54 +0000 (01:51 -0800)
committerKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Sat, 13 Feb 1993 09:51:54 +0000 (01:51 -0800)
SCCS-vsn: lib/csu/hp300/crt0.c 5.8
SCCS-vsn: lib/csu/i386/crt0.c 5.9
SCCS-vsn: lib/csu/sparc/crt0.c 5.2
SCCS-vsn: lib/csu/tahoe/crt0.c 5.5
SCCS-vsn: lib/csu/vax/crt0.c 5.12

usr/src/lib/csu/hp300/crt0.c
usr/src/lib/csu/i386/crt0.c
usr/src/lib/csu/sparc/crt0.c
usr/src/lib/csu/tahoe/crt0.c
usr/src/lib/csu/vax/crt0.c

index 3bb786e..ac8b000 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)crt0.c     5.7 (Berkeley) %G%";
+static char sccsid[] = "@(#)crt0.c     5.8 (Berkeley) %G%";
 #endif /* not lint */
 
 /*
 #endif /* not lint */
 
 /*
@@ -29,7 +29,13 @@ static char sccsid[] = "@(#)crt0.c   5.7 (Berkeley) %G%";
  *     allocated.
  */
 
  *     allocated.
  */
 
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+
 char **environ = (char **)0;
 char **environ = (char **)0;
+static char empty[1];
+char *__progname = empty;
 static int fd;
 
 extern unsigned char   etext;
 static int fd;
 
 extern unsigned char   etext;
@@ -58,9 +64,9 @@ start()
 #ifdef lint
        kfp = 0;
        initcode = initcode = 0;
 #ifdef lint
        kfp = 0;
        initcode = initcode = 0;
-#else not lint
+#else
        asm("lea a6@(4),%0" : "=r" (kfp));      /* catch it quick */
        asm("lea a6@(4),%0" : "=r" (kfp));      /* catch it quick */
-#endif not lint
+#endif
        for (argv = targv = &kfp->kargv[0]; *targv++; /* void */)
                /* void */ ;
        if (targv >= (char **)(*argv))
        for (argv = targv = &kfp->kargv[0]; *targv++; /* void */)
                /* void */ ;
        if (targv >= (char **)(*argv))
@@ -81,13 +87,18 @@ asm("eprol:");
                fd = open("/dev/null", 2);
        } while (fd >= 0 && fd < 3);
        close(fd);
                fd = open("/dev/null", 2);
        } while (fd >= 0 && fd < 3);
        close(fd);
-#endif paranoid
+#endif
 
 #ifdef MCRT0
        atexit(_mcleanup);
        monstartup(&eprol, &etext);
 
 #ifdef MCRT0
        atexit(_mcleanup);
        monstartup(&eprol, &etext);
-#endif MCRT0
+#endif
        errno = 0;
        errno = 0;
+       if (argv[0])
+               if ((__progname = strrchr(argv[0], '/')) == NULL)
+                       __progname = argv[0];
+               else
+                       ++__progname;
        exit(main(kfp->kargc, argv, environ));
 }
 
        exit(main(kfp->kargc, argv, environ));
 }
 
@@ -100,4 +111,4 @@ moncontrol(val)
 {
 
 }
 {
 
 }
-#endif /* CRT0 */
+#endif
index 71caa61..11bfcdf 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)crt0.c     5.8 (Berkeley) %G%";
+static char sccsid[] = "@(#)crt0.c     5.9 (Berkeley) %G%";
 #endif /* not lint */
 
 /*
 #endif /* not lint */
 
 /*
@@ -18,7 +18,13 @@ static char sccsid[] = "@(#)crt0.c   5.8 (Berkeley) %G%";
  *     which points to the base of the kernel calling frame.
  */
 
  *     which points to the base of the kernel calling frame.
  */
 
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+
 char **environ = (char **)0;
 char **environ = (char **)0;
+static char empty[1];
+char *__progname = empty;
 static int fd;
 
 asm(".text");
 static int fd;
 
 asm(".text");
@@ -48,9 +54,9 @@ start()
 #ifdef lint
        kfp = 0;
        initcode = initcode = 0;
 #ifdef lint
        kfp = 0;
        initcode = initcode = 0;
-#else not lint
+#else
        asm("lea 4(%ebp),%ebx");        /* catch it quick */
        asm("lea 4(%ebp),%ebx");        /* catch it quick */
-#endif not lint
+#endif
        for (argv = targv = &kfp->kargv[0]; *targv++; /* void */)
                /* void */ ;
        if (targv >= (char **)(*argv))
        for (argv = targv = &kfp->kargv[0]; *targv++; /* void */)
                /* void */ ;
        if (targv >= (char **)(*argv))
@@ -71,13 +77,18 @@ asm("eprol:");
                fd = open("/dev/null", 2);
        } while (fd >= 0 && fd < 3);
        close(fd);
                fd = open("/dev/null", 2);
        } while (fd >= 0 && fd < 3);
        close(fd);
-#endif paranoid
+#endif
 
 #ifdef MCRT0
        atexit(_mcleanup);
        monstartup(&eprol, &etext);
 
 #ifdef MCRT0
        atexit(_mcleanup);
        monstartup(&eprol, &etext);
-#endif MCRT0
+#endif
        errno = 0;
        errno = 0;
+       if (argv[0])
+               if ((__progname = strrchr(argv[0], '/')) == NULL)
+                       __progname = argv[0];
+               else
+                       ++__progname;
        exit(main(kfp->kargc, argv, environ));
 }
 
        exit(main(kfp->kargc, argv, environ));
 }
 
@@ -90,4 +101,4 @@ moncontrol(val)
 {
 
 }
 {
 
 }
-#endif /* CRT0 */
+#endif
index dad2ef9..9d4cf79 100644 (file)
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)crt0.c     5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)crt0.c     5.2 (Berkeley) %G%";
 #endif /* not lint */
 
 /*
  *     C start up routine.
  */
 
 #endif /* not lint */
 
 /*
  *     C start up routine.
  */
 
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+
 char **environ = (char **)0;
 char **environ = (char **)0;
+static char empty[1];
+char *__progname = empty;
 
 extern unsigned char etext[];
 extern volatile void start() asm("start0");
 extern unsigned char eprol[] asm("eprol");
 extern void _mcleanup(void);
 
 extern unsigned char etext[];
 extern volatile void start() asm("start0");
 extern unsigned char eprol[] asm("eprol");
 extern void _mcleanup(void);
-volatile void exit(int);
 
 volatile void
 start(void)
 
 volatile void
 start(void)
@@ -69,8 +74,12 @@ asm("eprol:");
        atexit(_mcleanup);
        errno = 0;
 #endif
        atexit(_mcleanup);
        errno = 0;
 #endif
+       if (argv[0])
+               if ((__progname = strrchr(argv[0], '/')) == NULL)
+                       __progname = argv[0];
+               else
+                       ++__progname;
        exit(main(argc, argv, envp));
        exit(main(argc, argv, envp));
-       /* NOTREACHED */
 }
 
 #ifdef CRT0
 }
 
 #ifdef CRT0
@@ -81,4 +90,4 @@ asm("eprol:");
 asm(".globl mcount");
 asm(".globl _moncontrol");
 asm("mcount: _moncontrol: retl; nop");
 asm(".globl mcount");
 asm(".globl _moncontrol");
 asm("mcount: _moncontrol: retl; nop");
-#endif CRT0
+#endif
index 007d204..dfe2ac3 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)crt0.c     5.4 (Berkeley) %G%";
+static char sccsid[] = "@(#)crt0.c     5.5 (Berkeley) %G%";
 #endif /* not lint */
 
 /*
 #endif /* not lint */
 
 /*
@@ -21,7 +21,13 @@ static char sccsid[] = "@(#)crt0.c   5.4 (Berkeley) %G%";
  *     which points to the base of the kernel calling frame.
  */
 
  *     which points to the base of the kernel calling frame.
  */
 
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+
 char **environ = (char **)0;
 char **environ = (char **)0;
+static char empty[1];
+char *__progname = empty;
 static int fd;
 
 extern unsigned char   etext;
 static int fd;
 
 extern unsigned char   etext;
@@ -63,8 +69,13 @@ asm("eprol:");
 
 #ifdef MCRT0
        monstartup(&eprol, &etext);
 
 #ifdef MCRT0
        monstartup(&eprol, &etext);
-#endif MCRT0
+#endif
        errno = 0;
        errno = 0;
+       if (argv[0])
+               if ((__progname = strrchr(argv[0], '/')) == NULL)
+                       __progname = argv[0];
+               else
+                       ++__progname;
        exit(main(kfp->kargc, argv, environ));
 }
 
        exit(main(kfp->kargc, argv, environ));
 }
 
@@ -77,7 +88,7 @@ exit(code)
        _cleanup();
        _exit(code);
 }
        _cleanup();
        _exit(code);
 }
-#endif MCRT0
+#endif
 
 #ifdef CRT0
 /*
 
 #ifdef CRT0
 /*
@@ -88,4 +99,4 @@ moncontrol(val)
 {
 
 }
 {
 
 }
-#endif CRT0
+#endif
index 002106a..042591b 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)crt0.c     5.11 (Berkeley) %G%";
+static char sccsid[] = "@(#)crt0.c     5.12 (Berkeley) %G%";
 #endif /* not lint */
 
 /*
 #endif /* not lint */
 
 /*
@@ -23,7 +23,13 @@ static char sccsid[] = "@(#)crt0.c   5.11 (Berkeley) %G%";
  *     values of fp and ap.
  */
 
  *     values of fp and ap.
  */
 
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+
 char **environ = (char **)0;
 char **environ = (char **)0;
+static char empty[1];
+char *__progname = empty;
 static int fd;
 
 extern unsigned char   etext;
 static int fd;
 
 extern unsigned char   etext;
@@ -55,9 +61,9 @@ start()
 #ifdef lint
        kfp = 0;
        initcode = initcode = 0;
 #ifdef lint
        kfp = 0;
        initcode = initcode = 0;
-#else not lint
+#else
        kfp = (struct kframe *) environ;
        kfp = (struct kframe *) environ;
-#endif not lint
+#endif
        for (argv = targv = &kfp->kargv[0]; *targv++; /* void */)
                /* void */ ;
        if (targv >= (char **)(*argv))
        for (argv = targv = &kfp->kargv[0]; *targv++; /* void */)
                /* void */ ;
        if (targv >= (char **)(*argv))
@@ -78,13 +84,18 @@ asm("eprol:");
                fd = open("/dev/null", 2);
        } while (fd >= 0 && fd < 3);
        close(fd);
                fd = open("/dev/null", 2);
        } while (fd >= 0 && fd < 3);
        close(fd);
-#endif paranoid
+#endif
 
 #ifdef MCRT0
        atexit(_mcleanup);
        monstartup(&eprol, &etext);
 
 #ifdef MCRT0
        atexit(_mcleanup);
        monstartup(&eprol, &etext);
-#endif MCRT0
+#endif
        errno = 0;
        errno = 0;
+       if (argv[0])
+               if ((__progname = strrchr(argv[0], '/')) == NULL)
+                       __progname = argv[0];
+               else
+                       ++__progname;
        exit(main(kfp->kargc, argv, environ));
 }
 
        exit(main(kfp->kargc, argv, environ));
 }
 
@@ -97,4 +108,4 @@ moncontrol(val)
 {
 
 }
 {
 
 }
-#endif CRT0
+#endif