OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include <dlfcn.h> | 8 #include <dlfcn.h> |
9 #include <stdio.h> | 9 #include <stdio.h> |
10 | 10 |
11 #ifdef SK_BUILD_FOR_WIN | |
12 #define SNPRINTF _snprintf | |
mtklein
2014/04/09 20:49:40
Or just, #define snprintf _snprintf, with no else?
hal.canary
2014/04/09 21:38:50
Done.
| |
13 #else | |
14 #define SNPRINTF snprintf | |
15 #endif | |
16 | |
11 void usage() { | 17 void usage() { |
12 printf("[USAGE] skia_launcher program_name [options]\n"); | 18 printf("[USAGE] skia_launcher program_name [options]\n"); |
13 printf(" program_name: the skia program you want to launch (e.g. tests, ben ch)\n"); | 19 printf(" program_name: the skia program you want to launch (e.g. tests, ben ch)\n"); |
14 printf(" options: options specific to the program you are launching\n"); | 20 printf(" options: options specific to the program you are launching\n"); |
15 } | 21 } |
16 | 22 |
17 bool file_exists(const char* fileName) { | 23 bool file_exists(const char* fileName) { |
18 FILE* file = fopen(fileName, "r"); | 24 FILE* file = fopen(fileName, "r"); |
19 if (file) { | 25 if (file) { |
20 fclose(file); | 26 fclose(file); |
21 return true; | 27 return true; |
22 } | 28 } |
23 return false; | 29 return false; |
24 } | 30 } |
25 | 31 |
26 int launch_app(int (*app_main)(int, const char**), int argc, | 32 int launch_app(int (*app_main)(int, const char**), int argc, |
27 const char** argv) { | 33 const char** argv) { |
28 return (*app_main)(argc, argv); | 34 return (*app_main)(argc, argv); |
29 } | 35 } |
30 | 36 |
31 void* load_library(const char* appLocation, const char* libraryName) | 37 void* load_library(const char* appLocation, const char* libraryName) |
32 { | 38 { |
33 // attempt to lookup the location of the shared libraries | 39 // attempt to lookup the location of the shared libraries |
34 char libraryLocation[100]; | 40 char libraryLocation[100]; |
35 sprintf(libraryLocation, "%s/lib%s.so", appLocation, libraryName); | 41 SNPRINTF(libraryLocation, 100, "%s/lib%s.so", appLocation, libraryName); |
mtklein
2014/04/09 20:49:40
SK_ARRAY_COUNT(libraryLocation) instead of 100?
hal.canary
2014/04/09 21:38:50
Done.
| |
36 if (!file_exists(libraryLocation)) { | 42 if (!file_exists(libraryLocation)) { |
37 printf("ERROR: Unable to find the '%s' library in the Skia App.\n", libr aryName); | 43 printf("ERROR: Unable to find the '%s' library in the Skia App.\n", libr aryName); |
38 printf("ERROR: Did you provide the correct program_name?\n"); | 44 printf("ERROR: Did you provide the correct program_name?\n"); |
39 usage(); | 45 usage(); |
40 return NULL; | 46 return NULL; |
41 } | 47 } |
42 | 48 |
43 // load the appropriate library | 49 // load the appropriate library |
44 void* appLibrary = dlopen(libraryLocation, RTLD_LOCAL | RTLD_LAZY); | 50 void* appLibrary = dlopen(libraryLocation, RTLD_LOCAL | RTLD_LAZY); |
45 if (!appLibrary) { | 51 if (!appLibrary) { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
105 if (app_SkDebugToStdOut) { | 111 if (app_SkDebugToStdOut) { |
106 (*app_SkDebugToStdOut)(true); | 112 (*app_SkDebugToStdOut)(true); |
107 } else { | 113 } else { |
108 printf("WARNING: Unable to redirect output to the console.\n"); | 114 printf("WARNING: Unable to redirect output to the console.\n"); |
109 printf("WARNING: %s\n", dlerror()); | 115 printf("WARNING: %s\n", dlerror()); |
110 } | 116 } |
111 | 117 |
112 // pass all additional arguments to the main function | 118 // pass all additional arguments to the main function |
113 return launch_app(app_main, argc - 1, ++argv); | 119 return launch_app(app_main, argc - 1, ++argv); |
114 } | 120 } |
OLD | NEW |