/* Glue for passing arguments to a simulator that can't pass command-line arguments to the target, yet can do file I/O. Copyright (c) 2005 Free Software Foundation, Inc. This file is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. For a copy of the GNU General Public License, write the the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include #include #include #include const char _argfile[] = _ARGFILE; /* We know we won't be passed more than this many/long parameters. */ static char args[1024]; static char *argv[32]; static char *envp[] = {"", NULL}; #undef main extern int _main_wrapped (int, char *[], char *[]); int main (void) { char *argp; FILE *argfile = fopen (_argfile, "r"); unsigned int i; if (argfile == NULL) abort (); for (argp = args, i = 0;; i++) { /* Need room for NULL too. */ if (i >= sizeof (argv) / sizeof (argv[0]) - 1) abort (); if (fgets (argp, sizeof (args) - (argp - args), argfile) == NULL) break; argv[i] = argp; argp += strlen (argp); argp[-1] = 0; } argv[i] = NULL; fclose (argfile); exit (_main_wrapped (i, argv, envp)); }