if_mach.c raw

   1  /*
   2   * A build-time utility used by `Makefile.direct` file.  Conditionally
   3   * execute a command based on machine and OS from `gcconfig.h` file.
   4   */
   5  
   6  #define NOT_GCBUILD
   7  #include "private/gc_priv.h"
   8  
   9  #include <string.h>
  10  #include <unistd.h>
  11  
  12  #ifdef __cplusplus
  13  #  define EXECV_ARGV_T char **
  14  #else
  15  /*
  16   * The 2nd argument of `execvp()` prototype may be either `char **`, or
  17   * `char *const *`, or `const char *const *`.
  18   */
  19  #  define EXECV_ARGV_T void *
  20  #endif
  21  
  22  int
  23  main(int argc, char **argv)
  24  {
  25    if (argc < 4)
  26      goto Usage;
  27    if (strcmp(MACH_TYPE, argv[1]) != 0)
  28      return 0;
  29    if (strlen(OS_TYPE) > 0 && strlen(argv[2]) > 0
  30        && strcmp(OS_TYPE, argv[2]) != 0)
  31      return 0;
  32    fprintf(stderr, "^^^^Starting command^^^^\n");
  33    fflush(stdout);
  34    execvp(TRUSTED_STRING(argv[3]), (EXECV_ARGV_T)(argv + 3));
  35    perror("Couldn't execute");
  36  
  37  Usage:
  38    fprintf(stderr, "Usage: %s mach_type os_type command\n", argv[0]);
  39    fprintf(stderr, "Currently mach_type = %s, os_type = %s\n", MACH_TYPE,
  40            OS_TYPE);
  41    return 1;
  42  }
  43