if_mach.c 991 B

1234567891011121314151617181920212223242526272829303132
  1. /* Conditionally execute a command based on machine and OS from gcconfig.h */
  2. # include "private/gc_priv.h"
  3. # include <stdio.h>
  4. # include <string.h>
  5. # include <unistd.h>
  6. #ifdef __cplusplus
  7. # define EXECV_ARGV_T char**
  8. #else
  9. /* The 2nd argument of execvp() prototype may be either char**, or */
  10. /* char* const*, or const char* const*. */
  11. # define EXECV_ARGV_T void*
  12. #endif
  13. int main(int argc, char **argv)
  14. {
  15. if (argc < 4) goto Usage;
  16. if (strcmp(MACH_TYPE, argv[1]) != 0) return(0);
  17. if (strlen(OS_TYPE) > 0 && strlen(argv[2]) > 0
  18. && strcmp(OS_TYPE, argv[2]) != 0) return(0);
  19. fprintf(stderr, "^^^^Starting command^^^^\n");
  20. fflush(stdout);
  21. execvp(TRUSTED_STRING(argv[3]), (EXECV_ARGV_T)(argv + 3));
  22. perror("Couldn't execute");
  23. Usage:
  24. fprintf(stderr, "Usage: %s mach_type os_type command\n", argv[0]);
  25. fprintf(stderr, "Currently mach_type = %s, os_type = %s\n",
  26. MACH_TYPE, OS_TYPE);
  27. return(1);
  28. }