Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Side by Side Diff: platform_tools/android/launcher/skia_launcher.cpp

Issue 230413005: remove sprintf (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: AnotherPatchSet Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/core/SkError.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
13 #endif
14
11 void usage() { 15 void usage() {
12 printf("[USAGE] skia_launcher program_name [options]\n"); 16 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"); 17 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"); 18 printf(" options: options specific to the program you are launching\n");
15 } 19 }
16 20
17 bool file_exists(const char* fileName) { 21 bool file_exists(const char* fileName) {
18 FILE* file = fopen(fileName, "r"); 22 FILE* file = fopen(fileName, "r");
19 if (file) { 23 if (file) {
20 fclose(file); 24 fclose(file);
21 return true; 25 return true;
22 } 26 }
23 return false; 27 return false;
24 } 28 }
25 29
26 int launch_app(int (*app_main)(int, const char**), int argc, 30 int launch_app(int (*app_main)(int, const char**), int argc,
27 const char** argv) { 31 const char** argv) {
28 return (*app_main)(argc, argv); 32 return (*app_main)(argc, argv);
29 } 33 }
30 34
31 void* load_library(const char* appLocation, const char* libraryName) 35 void* load_library(const char* appLocation, const char* libraryName)
32 { 36 {
33 // attempt to lookup the location of the shared libraries 37 // attempt to lookup the location of the shared libraries
34 char libraryLocation[100]; 38 char libraryLocation[100];
35 sprintf(libraryLocation, "%s/lib%s.so", appLocation, libraryName); 39 snprintf(libraryLocation, sizeof(libraryLocation),
40 "%s/lib%s.so", appLocation, libraryName);
36 if (!file_exists(libraryLocation)) { 41 if (!file_exists(libraryLocation)) {
37 printf("ERROR: Unable to find the '%s' library in the Skia App.\n", libr aryName); 42 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"); 43 printf("ERROR: Did you provide the correct program_name?\n");
39 usage(); 44 usage();
40 return NULL; 45 return NULL;
41 } 46 }
42 47
43 // load the appropriate library 48 // load the appropriate library
44 void* appLibrary = dlopen(libraryLocation, RTLD_LOCAL | RTLD_LAZY); 49 void* appLibrary = dlopen(libraryLocation, RTLD_LOCAL | RTLD_LAZY);
45 if (!appLibrary) { 50 if (!appLibrary) {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 if (app_SkDebugToStdOut) { 110 if (app_SkDebugToStdOut) {
106 (*app_SkDebugToStdOut)(true); 111 (*app_SkDebugToStdOut)(true);
107 } else { 112 } else {
108 printf("WARNING: Unable to redirect output to the console.\n"); 113 printf("WARNING: Unable to redirect output to the console.\n");
109 printf("WARNING: %s\n", dlerror()); 114 printf("WARNING: %s\n", dlerror());
110 } 115 }
111 116
112 // pass all additional arguments to the main function 117 // pass all additional arguments to the main function
113 return launch_app(app_main, argc - 1, ++argv); 118 return launch_app(app_main, argc - 1, ++argv);
114 } 119 }
OLDNEW
« no previous file with comments | « no previous file | src/core/SkError.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698