diff options
Diffstat (limited to 'community/mini-sendmail/sh.c')
-rw-r--r-- | community/mini-sendmail/sh.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/community/mini-sendmail/sh.c b/community/mini-sendmail/sh.c new file mode 100644 index 0000000000..7feea6d7d1 --- /dev/null +++ b/community/mini-sendmail/sh.c @@ -0,0 +1,30 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#define MAXARG 64 + +int main( int argc, char* const argv[] ) { + char* args[ MAXARG ] = {}; + + if( argc < 3 || strcmp( argv[1], "-c" ) != 0 ) { + fprintf( stderr, "Usage: %s -c <cmd>\n", argv[0] ); + return 1; + } + + { + char* token; + int i = 0; + char* argStr = strdup( argv[2] ); + while( ( token = strsep( &argStr, " " ) ) != NULL ) { + if( token && strlen( token ) ) + args[ i++ ] = token; + if( i >= MAXARG ) + return 2; + } + } + + return execvp( args[0], args ); +} + |