PIPS
system.c
Go to the documentation of this file.
1 /*
2 
3  $Id: system.c 23065 2016-03-02 09:05:50Z coelho $
4 
5  Copyright 1989-2016 MINES ParisTech
6 
7  This file is part of PIPS.
8 
9  PIPS is free software: you can redistribute it and/or modify it
10  under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  any later version.
13 
14  PIPS is distributed in the hope that it will be useful, but WITHOUT ANY
15  WARRANTY; without even the implied warranty of MERCHANTABILITY or
16  FITNESS FOR A PARTICULAR PURPOSE.
17 
18  See the GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with PIPS. If not, see <http://www.gnu.org/licenses/>.
22 
23 */
24 #ifdef HAVE_CONFIG_H
25  #include "pips_config.h"
26 #endif
27 /*
28  * a safe system call. abort if fails.
29  * FC 09/95
30  */
31 
32 #include <stdio.h>
33 #include <stdlib.h>
34 
35 #include "genC.h"
36 #include "misc.h"
37 
38 void safe_system(string command) /* the command to be executed */
39 {
40  int status = system(command);
41 
42  if (status)
43  pips_internal_error("Failed (ret: %d, sig: %d) for %s",
44  (status/0x100) & 0xff, status & 0xff, command);
45 }
46 
47 int safe_system_no_abort(string command) /* the command to be executed */
48 {
49  int status = system(command);
50 
51  if (status == 127)
52  pips_internal_error("Could not execute : '%s'", command);
53 
54  if (status) {
55  /* For portability reasons, do not use pips_user_warning() here */
56  pips_user_warning("Failed (ret: %d, sig: %d) for '%s'\n",
57  (status/0x100) & 0xff, status & 0xff, command);
58  }
59 
60  return (status / 256) & 255;
61 }
62 
63 int safe_system_no_abort_no_warning(string command) /* the command to be executed */
64 {
65  int status = system(command);
66 
67  if (status == 127)
68  pips_internal_error("Could not execute : '%s'", command);
69 
70  return (status / 256) & 255;
71 }
72 
73 /* that is all
74  */
#define pips_user_warning
Definition: misc-local.h:146
#define pips_internal_error
Definition: misc-local.h:149
int safe_system_no_abort_no_warning(string command)
the command to be executed
Definition: system.c:63
int safe_system_no_abort(string command)
the command to be executed
Definition: system.c:47
void safe_system(string command)
a safe system call.
Definition: system.c:38