]> git.ipfire.org Git - thirdparty/gcc.git/blame - libgfortran/runtime/minimal.c
No libstdc++ for nvptx.
[thirdparty/gcc.git] / libgfortran / runtime / minimal.c
CommitLineData
5624e564 1/* Copyright (C) 2002-2015 Free Software Foundation, Inc.
ee95f928
BS
2 Contributed by Andy Vaught and Paul Brook <paul@nowt.org>
3
4This file is part of the GNU Fortran runtime library (libgfortran).
5
6Libgfortran is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 3, or (at your option)
9any later version.
10
11Libgfortran is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16Under Section 7 of GPL version 3, you are granted additional
17permissions described in the GCC Runtime Library Exception, version
183.1, as published by the Free Software Foundation.
19
20You should have received a copy of the GNU General Public License and
21a copy of the GCC Runtime Library Exception along with this program;
22see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23<http://www.gnu.org/licenses/>. */
24
25#include "libgfortran.h"
26#include <stdlib.h>
27#include <string.h>
28#include <limits.h>
29#include <errno.h>
30
31
32#ifdef HAVE_UNISTD_H
33#include <unistd.h>
34#endif
35
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. */
38void
39stupid_function_name_for_static_linking (void)
40{
41 return;
42}
43
44options_t options;
45
46/* This will be 0 for little-endian
47 machines and 1 for big-endian machines.
48
49 Currently minimal libgfortran only runs on little-endian devices
50 which don't support constructors so this is just a constant. */
51int big_endian = 0;
52
53static int argc_save;
54static char **argv_save;
55
56static const char *exe_path;
57
58/* recursion_check()-- It's possible for additional errors to occur
59 * during fatal error processing. We detect this condition here and
60 * exit with code 4 immediately. */
61
62#define MAGIC 0x20DE8101
63
64static void
65recursion_check (void)
66{
67 static int magic = 0;
68
69 /* Don't even try to print something at this point */
70 if (magic == MAGIC)
71 sys_abort ();
72
73 magic = MAGIC;
74}
75
76#define STRERR_MAXSZ 256
77
78void
79os_error (const char *message)
80{
81 recursion_check ();
82 printf ("Operating system error: ");
83 printf ("%s\n", message);
84 exit (1);
85}
86iexport(os_error);
87
88void
89runtime_error (const char *message, ...)
90{
91 va_list ap;
92
93 recursion_check ();
94 printf ("Fortran runtime error: ");
95 va_start (ap, message);
96 vprintf (message, ap);
97 va_end (ap);
98 printf ("\n");
99 exit (2);
100}
101iexport(runtime_error);
102
103/* void runtime_error_at()-- These are errors associated with a
104 * run time error generated by the front end compiler. */
105
106void
107runtime_error_at (const char *where, const char *message, ...)
108{
109 va_list ap;
110
111 recursion_check ();
112 printf ("Fortran runtime error: ");
113 va_start (ap, message);
114 vprintf (message, ap);
115 va_end (ap);
116 printf ("\n");
117 exit (2);
118}
119iexport(runtime_error_at);
120
121/* Return the full path of the executable. */
122char *
123full_exe_path (void)
124{
125 return (char *) exe_path;
126}
127
128
129/* Set the saved values of the command line arguments. */
130
131void
132set_args (int argc, char **argv)
133{
134 argc_save = argc;
135 argv_save = argv;
136 exe_path = argv[0];
137}
138iexport(set_args);
139
140
141/* Retrieve the saved values of the command line arguments. */
142
143void
144get_args (int *argc, char ***argv)
145{
146 *argc = argc_save;
147 *argv = argv_save;
148}
149
150/* sys_abort()-- Terminate the program showing backtrace and dumping
151 core. */
152
153void
154sys_abort (void)
155{
156 printf ("Abort called.\n");
157 abort();
158}