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

Side by Side Diff: src/trusted/plugin/utility.cc

Issue 7799028: Remove src/trusted/plugin (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client
Patch Set: fix gyp file for necessary -I Created 9 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « src/trusted/plugin/utility.h ('k') | src/trusted/plugin/var_utils.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2011 The Native Client Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file.
5 */
6
7 #include <stdarg.h>
8 #include <stdlib.h>
9 #include <string.h>
10
11 #include "native_client/src/trusted/plugin/utility.h"
12
13 namespace plugin {
14
15 int gNaClPluginDebugPrintEnabled = -1;
16 FILE* gNaClPluginLogFile = NULL;
17
18 /*
19 * Prints formatted message to the log.
20 */
21 int NaClPluginPrintLog(const char *format, ...) {
22 if (NULL == gNaClPluginLogFile) {
23 return 0;
24 }
25 va_list arg;
26 int done;
27 va_start(arg, format);
28 done = vfprintf(gNaClPluginLogFile, format, arg);
29 va_end(arg);
30 fflush(gNaClPluginLogFile);
31 return done;
32 }
33
34 /*
35 * Opens file where plugin log should be written. The file name is
36 * taken from NACL_PLUGIN_LOG environment variable.
37 * If environment variable doesn't exist or file can't be opened,
38 * the function returns stdout.
39 */
40 FILE* NaClPluginLogFileEnv() {
41 char* file = getenv("NACL_PLUGIN_LOG");
42 if (NULL != file) {
43 FILE* log_file = fopen(file, "w+");
44 if (NULL == log_file) {
45 return stdout;
46 }
47 return log_file;
48 }
49 return stdout;
50 }
51
52 /*
53 * Currently looks for presence of NACL_PLUGIN_DEBUG and returns
54 * 0 if absent and 1 if present. In the future we may include notions
55 * of verbosity level.
56 */
57 int NaClPluginDebugPrintCheckEnv() {
58 char* env = getenv("NACL_PLUGIN_DEBUG");
59 return (NULL != env);
60 }
61
62 bool IsValidIdentifierString(const char* strval, uint32_t* length) {
63 // This function is supposed to recognize valid ECMAScript identifiers,
64 // as described in
65 // http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-262.pdf
66 // It is currently restricted to only the ASCII subset.
67 // TODO(sehr): Recognize the full Unicode formulation of identifiers.
68 // TODO(sehr): Make this table-driven if efficiency becomes a problem.
69 if (NULL != length) {
70 *length = 0;
71 }
72 if (NULL == strval) {
73 return false;
74 }
75 static const char* kValidFirstChars =
76 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz$_";
77 static const char* kValidOtherChars =
78 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz$_"
79 "0123456789";
80 if (NULL == strchr(kValidFirstChars, strval[0])) {
81 return false;
82 }
83 uint32_t pos;
84 for (pos = 1; ; ++pos) {
85 if (0 == pos) {
86 // Unsigned overflow.
87 return false;
88 }
89 int c = strval[pos];
90 if (0 == c) {
91 break;
92 }
93 if (NULL == strchr(kValidOtherChars, c)) {
94 return false;
95 }
96 }
97 if (NULL != length) {
98 *length = pos;
99 }
100 return true;
101 }
102
103 } // namespace plugin
OLDNEW
« no previous file with comments | « src/trusted/plugin/utility.h ('k') | src/trusted/plugin/var_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698