home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / glibc-1.06 / sysdeps / unix / start.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-21  |  2.6 KB  |  101 lines

  1. /* Copyright (C) 1991, 1993 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3.  
  4. The GNU C Library is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8.  
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. GNU General Public License for more details.
  13.  
  14. You should have received a copy of the GNU General Public License
  15. along with the GNU C Library; see the file COPYING.  If not, write to
  16. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  17.  
  18. #include <ansidecl.h>
  19. #include <errno.h>
  20. #include <stdlib.h>
  21. #include <unistd.h>
  22.  
  23. /* The first piece of initialized data.  */
  24. int __data_start = 0;
  25.  
  26. #ifdef    DUMMIES
  27. #define    ARG_DUMMIES    DUMMIES,
  28. #define    DECL_DUMMIES    int DUMMIES;
  29. #else
  30. #define    ARG_DUMMIES
  31. #define    DECL_DUMMIES
  32. #endif
  33.  
  34. VOLATILE int errno;
  35.  
  36. #ifndef    HAVE_GNU_LD
  37. #undef    environ
  38. #define    __environ    environ
  39. #endif
  40.  
  41. char **__environ;
  42.  
  43. extern void EXFUN(__libc_init, (int argc, char **argv, char **envp));
  44. extern int EXFUN(main, (int argc, char **argv, char **envp));
  45.  
  46.  
  47. /* Not a prototype because it gets called strangely.  */
  48. static void start1();
  49.  
  50. #ifndef    HAVE__start
  51.  
  52. #ifdef __GNUC__
  53. /* Declare _start with an explicit assembly symbol name of `start'
  54.    (note no leading underscore).  This is the name vendor crt0.o's
  55.    tend to use, and thus the name most linkers expect.  */
  56. void _start (void) asm ("start");
  57. #endif
  58.  
  59. /* N.B.: It is important that this be the first function.
  60.    This file is the first thing in the text section.  */
  61. void
  62. DEFUN_VOID(_start)
  63. {
  64.   start1();
  65. }
  66.  
  67. #if !defined (NO_UNDERSCORES) && defined (HAVE_GNU_LD) && !defined (__GNUC__)
  68. /* Make an alias called `start' (no leading underscore,
  69.    so it can't conflict with C symbols) for `_start'.  */
  70. asm(".stabs \"start\",11,0,0,0");
  71. asm(".stabs \"__start\",1,0,0,0");
  72. #endif
  73.  
  74. #endif
  75.  
  76. /* ARGSUSED */
  77. static void
  78. start1(ARG_DUMMIES argc, argp)
  79.      DECL_DUMMIES
  80.      int argc;
  81.      char *argp;
  82. {
  83.   char **argv = &argp;
  84.  
  85.   /* The environment starts just after ARGV.  */
  86.   __environ = &argv[argc + 1];
  87.  
  88.   /* If the first thing after ARGV is the arguments
  89.      themselves, there is no environment.  */
  90.   if ((char *) __environ == *argv)
  91.     /* The environment is empty.  Make __environ
  92.        point at ARGV[ARGC], which is NULL.  */
  93.     --__environ;
  94.  
  95.   /* Do C library initializations.  */
  96.   __libc_init (argc, argv, __environ);
  97.  
  98.   /* Call the user program.  */
  99.   exit(main(argc, argv, __environ));
  100. }
  101.