* runtime/environ.c: Include unistd.h.
[official-gcc.git] / libgfortran / runtime / stop.c
blob4805412e761e930521ad1c3f4bf75f1a70306cb1
1 /* Implementation of the STOP statement.
2 Copyright (C) 2002-2013 Free Software Foundation, Inc.
3 Contributed by Paul Brook <paul@nowt.org>
5 This file is part of the GNU Fortran runtime library (libgfortran).
7 Libgfortran is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public
9 License as published by the Free Software Foundation; either
10 version 3 of the License, or (at your option) any later version.
12 Libgfortran is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 Under Section 7 of GPL version 3, you are granted additional
18 permissions described in the GCC Runtime Library Exception, version
19 3.1, as published by the Free Software Foundation.
21 You should have received a copy of the GNU General Public License and
22 a copy of the GCC Runtime Library Exception along with this program;
23 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 <http://www.gnu.org/licenses/>. */
26 #include "libgfortran.h"
27 #include <stdlib.h>
28 #include <string.h>
30 #ifdef HAVE_UNISTD_H
31 #include <unistd.h>
32 #endif
35 /* A numeric STOP statement. */
37 extern void stop_numeric (GFC_INTEGER_4)
38 __attribute__ ((noreturn));
39 export_proto(stop_numeric);
41 void
42 stop_numeric (GFC_INTEGER_4 code)
44 if (code == -1)
45 code = 0;
46 else
47 st_printf ("STOP %d\n", (int)code);
49 exit (code);
53 /* A Fortran 2008 numeric STOP statement. */
55 extern void stop_numeric_f08 (GFC_INTEGER_4)
56 __attribute__ ((noreturn));
57 export_proto(stop_numeric_f08);
59 void
60 stop_numeric_f08 (GFC_INTEGER_4 code)
62 st_printf ("STOP %d\n", (int)code);
63 exit (code);
67 /* A character string or blank STOP statement. */
69 void
70 stop_string (const char *string, GFC_INTEGER_4 len)
72 if (string)
74 estr_write ("STOP ");
75 (void) write (STDERR_FILENO, string, len);
76 estr_write ("\n");
78 exit (0);
82 /* Per Fortran 2008, section 8.4: "Execution of a STOP statement initiates
83 normal termination of execution. Execution of an ERROR STOP statement
84 initiates error termination of execution." Thus, error_stop_string returns
85 a nonzero exit status code. */
87 extern void error_stop_string (const char *, GFC_INTEGER_4)
88 __attribute__ ((noreturn));
89 export_proto(error_stop_string);
91 void
92 error_stop_string (const char *string, GFC_INTEGER_4 len)
94 estr_write ("ERROR STOP ");
95 (void) write (STDERR_FILENO, string, len);
96 estr_write ("\n");
98 exit (1);
102 /* A numeric ERROR STOP statement. */
104 extern void error_stop_numeric (GFC_INTEGER_4)
105 __attribute__ ((noreturn));
106 export_proto(error_stop_numeric);
108 void
109 error_stop_numeric (GFC_INTEGER_4 code)
111 st_printf ("ERROR STOP %d\n", (int) code);
112 exit (code);