| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2014 The Native Client Authors. All rights reserved. | 2 * Copyright (c) 2014 The Native Client Authors. All rights reserved. |
| 3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
| 4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
| 5 */ | 5 */ |
| 6 | 6 |
| 7 /* Define a typical entry point for command line tools spawned by bash | 7 /* Define a typical entry point for command line tools spawned by bash |
| 8 * (e.g., ls, objdump, and objdump). */ | 8 * (e.g., ls, objdump, and objdump). */ |
| 9 | 9 |
| 10 #define _GNU_SOURCE | 10 #define _GNU_SOURCE |
| 11 | 11 |
| 12 #include <stdio.h> | 12 #include <stdio.h> |
| 13 #include <errno.h> | 13 #include <errno.h> |
| 14 #include <string.h> | 14 #include <string.h> |
| 15 #include <stdbool.h> |
| 15 | 16 |
| 16 #include "nacl_io/nacl_io.h" | 17 #include "nacl_io/nacl_io.h" |
| 17 #include "nacl_main.h" | 18 #include "nacl_main.h" |
| 18 #include "ppapi_simple/ps.h" | 19 #include "ppapi_simple/ps.h" |
| 19 #include "ppapi_simple/ps_main.h" | 20 #include "ppapi_simple/ps_main.h" |
| 20 | 21 |
| 22 bool _cli_main_init = false; |
| 23 |
| 21 #ifdef _NEWLIB_VERSION | 24 #ifdef _NEWLIB_VERSION |
| 22 void setprogname(const char *progname) __attribute__((weak)); | 25 void setprogname(const char *progname) __attribute__((weak)); |
| 23 #endif | 26 #endif |
| 24 | 27 |
| 25 void nacl_setprogname(char* argv0) { | 28 void nacl_setprogname(char* argv0) { |
| 26 #if defined(_NEWLIB_VERSION) | 29 #if defined(_NEWLIB_VERSION) |
| 27 /* If setprogname exists at runtime then call it to set the program name */ | 30 /* If setprogname exists at runtime then call it to set the program name */ |
| 28 if (setprogname) | 31 if (setprogname) |
| 29 setprogname(argv0); | 32 setprogname(argv0); |
| 30 #elif defined(__GLIBC__) | 33 #elif defined(__GLIBC__) |
| 31 char *p = strrchr (argv0, '/'); | 34 char *p = strrchr (argv0, '/'); |
| 32 if (p == NULL) | 35 if (p == NULL) |
| 33 program_invocation_short_name = argv0; | 36 program_invocation_short_name = argv0; |
| 34 else | 37 else |
| 35 program_invocation_short_name = p + 1; | 38 program_invocation_short_name = p + 1; |
| 36 program_invocation_name = argv0; | 39 program_invocation_name = argv0; |
| 37 #endif | 40 #endif |
| 38 } | 41 } |
| 39 | 42 |
| 43 int main(int argc, char* argv[]); |
| 44 |
| 40 int cli_main(int argc, char* argv[]) { | 45 int cli_main(int argc, char* argv[]) { |
| 46 _cli_main_init = true; |
| 41 if (argv && argv[0]) | 47 if (argv && argv[0]) |
| 42 nacl_setprogname(argv[0]); | 48 nacl_setprogname(argv[0]); |
| 43 | 49 |
| 44 int rtn = nacl_setup_env(); | 50 int rtn = nacl_setup_env(); |
| 45 if (rtn != 0) { | 51 if (rtn != 0) { |
| 46 fprintf(stderr, "nacl_setup_env failed: %d\n", rtn); | 52 fprintf(stderr, "nacl_setup_env failed: %d\n", rtn); |
| 47 return 1; | 53 return 1; |
| 48 } | 54 } |
| 49 return nacl_main(argc, argv); | 55 |
| 56 return main(argc, argv); |
| 50 } | 57 } |
| 51 | 58 |
| 52 PPAPI_SIMPLE_REGISTER_MAIN(cli_main) | 59 PPAPI_SIMPLE_REGISTER_MAIN(cli_main) |
| OLD | NEW |