revised patch from gaby
[official-gcc/constexpr.git] / libgfortran / intrinsics / system.c
blob831823ffc4cdfb99a2c98e6e2fc0c60789a380bf
1 /* Implementation of the SYSTEM intrinsic.
2 Copyright (C) 2004, 2007, 2009 Free Software Foundation, Inc.
3 Contributed by Tobias Schlüter.
5 This file is part of the GNU Fortran 95 runtime library (libgfortran).
7 Libgfortran is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
10 version.
12 Libgfortran is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 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 <string.h>
29 #ifdef HAVE_STDLIB_H
30 #include <stdlib.h>
31 #endif
33 extern void system_sub (const char *fcmd, GFC_INTEGER_4 * status,
34 gfc_charlen_type cmd_len);
35 iexport_proto(system_sub);
37 void
38 system_sub (const char *fcmd, GFC_INTEGER_4 *status, gfc_charlen_type cmd_len)
40 char cmd[cmd_len + 1];
41 int stat;
43 /* Flush all I/O units before executing the command. */
44 flush_all_units();
46 memcpy (cmd, fcmd, cmd_len);
47 cmd[cmd_len] = '\0';
49 stat = system (cmd);
50 if (status)
51 *status = stat;
53 iexport(system_sub);
55 extern GFC_INTEGER_4 PREFIX(system) (const char *, gfc_charlen_type);
56 export_proto_np(PREFIX(system));
58 GFC_INTEGER_4
59 PREFIX(system) (const char *fcmd, gfc_charlen_type cmd_len)
61 GFC_INTEGER_4 stat;
62 system_sub (fcmd, &stat, cmd_len);
63 return stat;