prog_limit.c
author Markus Bröker <mbroeker@largo.dyndns.tv>
Thu, 16 Apr 2009 12:49:13 +0200
changeset 61 4b4c97f179da
parent 60 47c13ca8c4d0
child 64 993b97c4ad2d
permissions -rw-r--r--
Lazy BNF / EBNF Help Messages committer: Markus Bröker <mbroeker@largo.homelinux.org>

/**
 * test/demos/prog_limit.c
 * Copyright (C) 2008 Markus Broeker
 */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int set_limit (int);

int main (int argc, char **argv)
{
    int i;

    char **args;

    if (argc < 3) {
        printf ("Usage: %s <mem> <cmd> [args]...\n", argv[0]);
        printf ("Report bugs to mbroeker@largo.homelinux.org\n");
        return EXIT_FAILURE;
    }

    if ((args = calloc ((argc - 1), sizeof (char *))) == NULL) {
        perror ("calloc");
        return EXIT_FAILURE;
    }

    for (i = 2; i < argc; i++)
        args[i - 2] = argv[i];

    args[i - 2] = NULL;

    if (set_limit (atoi (argv[1])) == 0) {
        i = execvp (argv[2], args);
    } else {
        perror ("Limit Error");
        return EXIT_FAILURE;
    }

    if (args != NULL)
        free (args);

    return i;
}