Add C++11 header <cuchar>.
[official-gcc.git] / libgfortran / runtime / main.c
blob07e31d20acd1b603b2fb3a63207563a63bd81f15
1 /* Copyright (C) 2002-2015 Free Software Foundation, Inc.
2 Contributed by Andy Vaught and Paul Brook <paul@nowt.org>
4 This file is part of the GNU Fortran runtime library (libgfortran).
6 Libgfortran is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
9 any later version.
11 Libgfortran is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 Under Section 7 of GPL version 3, you are granted additional
17 permissions described in the GCC Runtime Library Exception, version
18 3.1, as published by the Free Software Foundation.
20 You should have received a copy of the GNU General Public License and
21 a copy of the GCC Runtime Library Exception along with this program;
22 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 <http://www.gnu.org/licenses/>. */
25 #include "libgfortran.h"
26 #include <stdlib.h>
27 #include <string.h>
28 #include <limits.h>
29 #include <errno.h>
32 #ifdef HAVE_UNISTD_H
33 #include <unistd.h>
34 #endif
36 /* Stupid function to be sure the constructor is always linked in, even
37 in the case of static linking. See PR libfortran/22298 for details. */
38 void
39 stupid_function_name_for_static_linking (void)
41 return;
44 /* This will be 0 for little-endian
45 machines and 1 for big-endian machines. */
46 int big_endian = 0;
49 /* Figure out endianness for this machine. */
51 static void
52 determine_endianness (void)
54 union
56 GFC_LOGICAL_8 l8;
57 GFC_LOGICAL_4 l4[2];
58 } u;
60 u.l8 = 1;
61 if (u.l4[0])
62 big_endian = 0;
63 else if (u.l4[1])
64 big_endian = 1;
65 else
66 runtime_error ("Unable to determine machine endianness");
70 static int argc_save;
71 static char **argv_save;
74 void
75 store_exe_path (const char * argv0 __attribute__ ((unused)))
77 /* This function is now useless, but is retained due to ABI compatibility.
78 Remove when bumping the library ABI. */
83 /* Set the saved values of the command line arguments. */
85 void
86 set_args (int argc, char **argv)
88 argc_save = argc;
89 argv_save = argv;
91 iexport(set_args);
94 /* Retrieve the saved values of the command line arguments. */
96 void
97 get_args (int *argc, char ***argv)
99 *argc = argc_save;
100 *argv = argv_save;
104 /* Initialize the runtime library. */
106 static void __attribute__((constructor))
107 init (void)
109 /* Figure out the machine endianness. */
110 determine_endianness ();
112 /* Must be first */
113 init_variables ();
115 init_units ();
117 /* If (and only if) the user asked for it, set up the FPU state. */
118 if (options.fpe != 0)
119 set_fpu ();
121 init_compile_options ();
123 random_seed_i4 (NULL, NULL, NULL);
127 /* Cleanup the runtime library. */
129 static void __attribute__((destructor))
130 cleanup (void)
132 close_units ();