; /*
dcc -r -v minstack.c -o minstack
quit
*   ^^ This is PURE code!
*/

/*
 * Minstack.c
 * (C) Copyright 1992 by Olaf Seibert. All rights reserved.
 *
 * Ensures a minimum stacksize by only upping the stack size to the
 * required amount.
 */

#include <exec/types.h>
#include <libraries/dosextens.h>
#include "functions.h"
#include <stddef.h>

__stkargs int _main(int len, char *cmdline)
/* int main(int argc, char **argv) */
{
    long stack;
    struct Process *proc;
    struct CommandLineInterface *cli;

    stack = atoi(cmdline);
    stack = (stack + 3) / 4;
    proc = (struct Process *)FindTask(NULL);
    if (proc->pr_Task.tc_Node.ln_Type == NT_PROCESS) {
	cli = BADDR(proc->pr_CLI);
	if (cli) {
	    if (cli->cli_DefaultStack < stack)
		cli->cli_DefaultStack = stack;
	}
    }
}
