aboutsummaryrefslogtreecommitdiffstats
path: root/community/mini-sendmail/sh.c
blob: 7feea6d7d1ef7dd6ee9dcb4ac35573ca56c58965 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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 );
}