This source file includes following definitions.
- NaClPluginPrintLog
- NaClPluginLogFileEnv
- NaClPluginDebugPrintCheckEnv
- IsValidIdentifierString
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include "native_client/src/include/portability_io.h"
#include "native_client/src/include/portability_process.h"
#include "ppapi/native_client/src/trusted/plugin/utility.h"
namespace plugin {
int gNaClPluginDebugPrintEnabled = -1;
FILE* gNaClPluginLogFile = NULL;
int NaClPluginPrintLog(const char *format, ...) {
if (NULL == gNaClPluginLogFile) {
return 0;
}
va_list arg;
int done;
va_start(arg, format);
done = vfprintf(gNaClPluginLogFile, format, arg);
va_end(arg);
fflush(gNaClPluginLogFile);
return done;
}
FILE* NaClPluginLogFileEnv() {
char* file = getenv("NACL_PLUGIN_LOG");
if (NULL != file) {
int pid = GETPID();
size_t filename_length = strlen(file) + 32;
char* filename = new char[filename_length];
int ret = SNPRINTF(filename, filename_length, "%s.%d.log", file, pid);
if (ret <= 0 || static_cast<size_t>(ret) >= filename_length) {
delete[] filename;
return stdout;
}
FILE* log_file = fopen(filename, "w+");
delete[] filename;
if (NULL == log_file) {
return stdout;
}
return log_file;
}
return stdout;
}
int NaClPluginDebugPrintCheckEnv() {
char* env = getenv("NACL_PLUGIN_DEBUG");
return (NULL != env);
}
bool IsValidIdentifierString(const char* strval, uint32_t* length) {
if (NULL != length) {
*length = 0;
}
if (NULL == strval) {
return false;
}
static const char* kValidFirstChars =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz$_";
static const char* kValidOtherChars =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz$_"
"0123456789";
if (NULL == strchr(kValidFirstChars, strval[0])) {
return false;
}
uint32_t pos;
for (pos = 1; ; ++pos) {
if (0 == pos) {
return false;
}
int c = strval[pos];
if (0 == c) {
break;
}
if (NULL == strchr(kValidOtherChars, c)) {
return false;
}
}
if (NULL != length) {
*length = pos;
}
return true;
}
}