Back to index

glibc  2.9
init-first.c
Go to the documentation of this file.
00001 /* Initialization code run first thing by the ELF startup code.  Stub version.
00002    Copyright (C) 1995, 1997, 1998, 2001, 2002 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #include <unistd.h>
00021 #include <sys/types.h>
00022 
00023 /* Set nonzero if we have to be prepared for more then one libc being
00024    used in the process.  Safe assumption if initializer never runs.  */
00025 int __libc_multiple_libcs attribute_hidden = 1;
00026 
00027 extern void __libc_init (int, char **, char **);
00028 #ifdef USE_NONOPTION_FLAGS
00029 extern void __getopt_clean_environment (char **);
00030 #endif
00031 
00032 #ifdef SHARED
00033 void
00034 __libc_init_first (void)
00035 {
00036 }
00037 #endif
00038 
00039 #ifdef SHARED
00040 /* NOTE!  The linker notices the magical name `_init' and sets the DT_INIT
00041    pointer in the dynamic section based solely on that.  It is convention
00042    for this function to be in the `.init' section, but the symbol name is
00043    the only thing that really matters!!  */
00044 void _init
00045 #else
00046 void __libc_init_first
00047 #endif
00048 (int argc, char *arg0, ...)
00049 {
00050   char **argv = &arg0, **envp = &argv[argc + 1];
00051 
00052   __environ = envp;
00053   __libc_init (argc, argv, envp);
00054 
00055 #ifdef USE_NONOPTION_FLAGS
00056   /* This is a hack to make the special getopt in GNU libc working.  */
00057   __getopt_clean_environment (envp);
00058 #endif
00059 }