]> pd.if.org Git - pdclib/blob - platform/example/functions/stdlib/system.c
Moving files to new dir structure.
[pdclib] / platform / example / functions / stdlib / system.c
1 /* $Id$ */
2
3 /* Release $Name$ */
4
5 /* system( const char * )
6
7    This file is part of the Public Domain C Library (PDCLib).
8    Permission is granted to use, modify, and / or redistribute at will.
9 */
10
11 /* This is an example implementation of system() fit for use with POSIX kernels.
12 */
13
14 #include <unistd.h>
15 #include <sys/wait.h>
16
17 int system( const char * string )
18 {
19     char * const argv[] = { "sh", "-c", (char * const)string, NULL };
20     if ( string != NULL )
21     {
22         int pid = fork();
23         if ( pid == 0 )
24         {
25             execve( "/bin/sh", argv, NULL );
26         }
27         else if ( pid > 0 )
28         {
29             while( wait( NULL ) != pid );
30         }
31     }
32     return -1;
33 }
34
35 #ifdef TEST
36 #include <_PDCLIB_test.h>
37 #include <_PDCLIB_config.h>
38
39 #define SHELLCOMMAND "echo 'SUCCESS testing system()'"
40
41 int main()
42 {
43     BEGIN_TESTS;
44     TESTCASE( system( SHELLCOMMAND ) );
45     return TEST_RESULTS;
46 }
47
48 #endif