зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1614814 - Stop using fopen in ipc/chromium/src/base/process_util.h on Windows. r=gsvelto
Differential Revision: https://phabricator.services.mozilla.com/D62507 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
32b5d4c391
Коммит
aedbf36959
|
@ -9,6 +9,8 @@
|
|||
# include <process.h>
|
||||
# include <dwrite.h>
|
||||
# include "mozilla/WinDllServices.h"
|
||||
#else
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "mozilla/Assertions.h"
|
||||
|
|
|
@ -59,6 +59,8 @@
|
|||
# include "mozilla/WindowsVersion.h"
|
||||
# include <process.h>
|
||||
# include <dwrite.h>
|
||||
#else
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
#ifdef MOZ_WIDGET_GTK
|
||||
# include <gtk/gtk.h>
|
||||
|
|
|
@ -15,10 +15,6 @@
|
|||
#if defined(OS_WIN)
|
||||
# include <windows.h>
|
||||
# include <tlhelp32.h>
|
||||
# include <io.h>
|
||||
# ifndef STDOUT_FILENO
|
||||
# define STDOUT_FILENO 1
|
||||
# endif
|
||||
#elif defined(OS_LINUX) || defined(__GLIBC__)
|
||||
# include <dirent.h>
|
||||
# include <limits.h>
|
||||
|
@ -31,11 +27,6 @@
|
|||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#ifndef OS_WIN
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "base/command_line.h"
|
||||
#include "base/process.h"
|
||||
|
@ -256,36 +247,22 @@ namespace mozilla {
|
|||
|
||||
class EnvironmentLog {
|
||||
public:
|
||||
explicit EnvironmentLog(const char* varname) {
|
||||
const char* e = getenv(varname);
|
||||
if (e && *e) {
|
||||
fname_ = e;
|
||||
}
|
||||
}
|
||||
template <size_t N>
|
||||
explicit EnvironmentLog(const char (&varname)[N])
|
||||
: EnvironmentLog(varname, N) {}
|
||||
|
||||
~EnvironmentLog() {}
|
||||
|
||||
void print(const char* format, ...) {
|
||||
if (!fname_.size()) return;
|
||||
|
||||
FILE* f;
|
||||
if (fname_.compare("-") == 0) {
|
||||
f = fdopen(dup(STDOUT_FILENO), "a");
|
||||
} else {
|
||||
f = fopen(fname_.c_str(), "a");
|
||||
}
|
||||
|
||||
if (!f) return;
|
||||
|
||||
va_list a;
|
||||
va_start(a, format);
|
||||
vfprintf(f, format, a);
|
||||
va_end(a);
|
||||
fclose(f);
|
||||
}
|
||||
void print(const char* format, ...);
|
||||
|
||||
private:
|
||||
explicit EnvironmentLog(const char* varname, size_t len);
|
||||
|
||||
#if defined(OS_WIN)
|
||||
std::wstring fname_;
|
||||
#else
|
||||
std::string fname_;
|
||||
#endif
|
||||
|
||||
DISALLOW_EVIL_CONSTRUCTORS(EnvironmentLog);
|
||||
};
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/resource.h>
|
||||
#include <sys/time.h>
|
||||
|
@ -300,3 +301,33 @@ EnvironmentArray BuildEnvironmentArray(const environment_map& env_vars_to_set) {
|
|||
}
|
||||
|
||||
} // namespace base
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
EnvironmentLog::EnvironmentLog(const char* varname, size_t len) {
|
||||
const char* e = getenv(varname);
|
||||
if (e && *e) {
|
||||
fname_ = e;
|
||||
}
|
||||
}
|
||||
|
||||
void EnvironmentLog::print(const char* format, ...) {
|
||||
if (!fname_.size()) return;
|
||||
|
||||
FILE* f;
|
||||
if (fname_.compare("-") == 0) {
|
||||
f = fdopen(dup(STDOUT_FILENO), "a");
|
||||
} else {
|
||||
f = fopen(fname_.c_str(), "a");
|
||||
}
|
||||
|
||||
if (!f) return;
|
||||
|
||||
va_list a;
|
||||
va_start(a, format);
|
||||
vfprintf(f, format, a);
|
||||
va_end(a);
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
} // namespace mozilla
|
||||
|
|
|
@ -13,12 +13,18 @@
|
|||
#include <windows.h>
|
||||
#include <winternl.h>
|
||||
#include <psapi.h>
|
||||
#include <io.h>
|
||||
#ifndef STDOUT_FILENO
|
||||
# define STDOUT_FILENO 1
|
||||
#endif
|
||||
|
||||
#include "base/histogram.h"
|
||||
#include "base/logging.h"
|
||||
#include "base/win_util.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
namespace {
|
||||
|
||||
|
@ -439,3 +445,35 @@ bool DidProcessCrash(bool* child_exited, ProcessHandle handle) {
|
|||
}
|
||||
|
||||
} // namespace base
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
EnvironmentLog::EnvironmentLog(const char* varname, size_t len) {
|
||||
wchar_t wvarname[len];
|
||||
std::copy(varname, varname + len, wvarname);
|
||||
const wchar_t* e = _wgetenv(wvarname);
|
||||
if (e && *e) {
|
||||
fname_ = e;
|
||||
}
|
||||
}
|
||||
|
||||
void EnvironmentLog::print(const char* format, ...) {
|
||||
if (!fname_.size()) return;
|
||||
|
||||
FILE* f;
|
||||
if (fname_.compare(L"-") == 0) {
|
||||
f = fdopen(dup(STDOUT_FILENO), "a");
|
||||
} else {
|
||||
f = _wfopen(fname_.c_str(), L"a");
|
||||
}
|
||||
|
||||
if (!f) return;
|
||||
|
||||
va_list a;
|
||||
va_start(a, format);
|
||||
vfprintf(f, format, a);
|
||||
va_end(a);
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
} // namespace mozilla
|
||||
|
|
Загрузка…
Ссылка в новой задаче