FreeBASIC  0.91.0
sys_hshell.c
Go to the documentation of this file.
1 /* SHELL command */
2 
3 #include "../fb.h"
4 #include "fb_private_console.h"
5 #include <sys/wait.h>
6 
7 int fb_hShell( char *program )
8 {
9  int errcode;
10 
11  FB_LOCK( );
13  FB_UNLOCK( );
14 
15  errcode = system( program );
16 
17  /* system() result uses same format as the status
18  returned by waitpid(), or -1 on error */
19  if( errcode != -1 && WIFEXITED( errcode ) ) {
20  errcode = WEXITSTATUS( errcode );
21  if( errcode == 127 ) {
22  /* /bin/sh could not be executed */
23  /* FIXME: can't tell difference if /bin/sh returned 127 */
24  errcode = -1;
25  }
26  }
27 
28  FB_LOCK( );
30  FB_UNLOCK( );
31 
32  return errcode;
33 }