summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/config.h.in9
-rw-r--r--src/googletest.h2
-rw-r--r--src/logging.cc39
-rw-r--r--src/signalhandler.cc9
-rw-r--r--src/utilities.cc3
-rwxr-xr-xsrc/windows/config.h115
-rwxr-xr-xsrc/windows/port.h4
7 files changed, 64 insertions, 117 deletions
diff --git a/src/config.h.in b/src/config.h.in
index 0c5e8b0..8190f23 100644
--- a/src/config.h.in
+++ b/src/config.h.in
@@ -48,15 +48,24 @@
/* define if the compiler implements namespaces */
#undef HAVE_NAMESPACES
+/* Define if you have the 'pread' function */
+#undef HAVE_PREAD
+
/* Define if you have POSIX threads libraries and header files. */
#undef HAVE_PTHREAD
/* Define to 1 if you have the <pwd.h> header file. */
#undef HAVE_PWD_H
+/* Define if you have the 'pwrite' function */
+#undef HAVE_PWRITE
+
/* define if the compiler implements pthread_rwlock_* */
#undef HAVE_RWLOCK
+/* Define if you have the 'sigaction' function */
+#undef HAVE_SIGACTION
+
/* Define if you have the `sigaltstack' function */
#undef HAVE_SIGALTSTACK
diff --git a/src/googletest.h b/src/googletest.h
index b3e26c4..21e4f64 100644
--- a/src/googletest.h
+++ b/src/googletest.h
@@ -81,7 +81,7 @@ static inline string GetTempDir() {
#endif
}
-#ifdef OS_WINDOWS
+#if defined(OS_WINDOWS) && defined(_MSC_VER)
// The test will run in glog/vsproject/<project name>
// (e.g., glog/vsproject/logging_unittest).
static const char TEST_SRC_DIR[] = "../..";
diff --git a/src/logging.cc b/src/logging.cc
index ec334a9..12330b0 100644
--- a/src/logging.cc
+++ b/src/logging.cc
@@ -179,6 +179,38 @@ GLOG_DEFINE_string(log_backtrace_at, "",
// TODO(hamaji): consider windows
#define PATH_SEPARATOR '/'
+#ifndef HAVE_PREAD
+static ssize_t pread(int fd, void* buf, size_t count, off_t offset) {
+ off_t orig_offset = lseek(fd, 0, SEEK_CUR);
+ if (orig_offset == (off_t)-1)
+ return -1;
+ if (lseek(fd, offset, SEEK_CUR) == (off_t)-1)
+ return -1;
+ ssize_t len = read(fd, buf, count);
+ if (len < 0)
+ return len;
+ if (lseek(fd, orig_offset, SEEK_SET) == (off_t)-1)
+ return -1;
+ return len;
+}
+#endif // !HAVE_PREAD
+
+#ifndef HAVE_PWRITE
+static ssize_t pwrite(int fd, void* buf, size_t count, off_t offset) {
+ off_t orig_offset = lseek(fd, 0, SEEK_CUR);
+ if (orig_offset == (off_t)-1)
+ return -1;
+ if (lseek(fd, offset, SEEK_CUR) == (off_t)-1)
+ return -1;
+ ssize_t len = write(fd, buf, count);
+ if (len < 0)
+ return len;
+ if (lseek(fd, orig_offset, SEEK_SET) == (off_t)-1)
+ return -1;
+ return len;
+}
+#endif // !HAVE_PWRITE
+
static void GetHostName(string* hostname) {
#if defined(HAVE_SYS_UTSNAME_H)
struct utsname buf;
@@ -887,8 +919,10 @@ bool LogFileObject::CreateLogfile(const string& time_pid_string) {
linkpath += linkname;
unlink(linkpath.c_str()); // delete old one if it exists
+#if defined(OS_WINDOWS)
+ // TODO(hamaji): Create lnk file on Windows?
+#elif defined(HAVE_UNISTD_H)
// We must have unistd.h.
-#ifdef HAVE_UNISTD_H
// Make the symlink be relative (in the same dir) so that if the
// entire log directory gets relocated the link is still valid.
const char *linkdest = slash ? (slash + 1) : filename;
@@ -1824,8 +1858,11 @@ void TruncateLogFile(const char *path, int64 limit, int64 keep) {
int64 read_offset, write_offset;
// Don't follow symlinks unless they're our own fd symlinks in /proc
int flags = O_RDWR;
+ // TODO(hamaji): Support other environments.
+#ifdef OS_LINUX
const char *procfd_prefix = "/proc/self/fd/";
if (strncmp(procfd_prefix, path, strlen(procfd_prefix))) flags |= O_NOFOLLOW;
+#endif
int fd = open(path, flags);
if (fd == -1) {
diff --git a/src/signalhandler.cc b/src/signalhandler.cc
index d6c203b..cccd800 100644
--- a/src/signalhandler.cc
+++ b/src/signalhandler.cc
@@ -48,6 +48,9 @@
_START_GOOGLE_NAMESPACE_
+// TOOD(hamaji): Use signal instead of sigaction?
+#ifdef HAVE_SIGACTION
+
namespace {
// We'll install the failure signal handler for these signals. We could
@@ -330,7 +333,10 @@ void FailureSignalHandler(int signal_number,
} // namespace
+#endif // HAVE_SIGACTION
+
void InstallFailureSignalHandler() {
+#ifdef HAVE_SIGACTION
// Build the sigaction struct.
struct sigaction sig_action;
memset(&sig_action, 0, sizeof(sig_action));
@@ -341,10 +347,13 @@ void InstallFailureSignalHandler() {
for (size_t i = 0; i < ARRAYSIZE(kFailureSignals); ++i) {
CHECK_ERR(sigaction(kFailureSignals[i].number, &sig_action, NULL));
}
+#endif // HAVE_SIGACTION
}
void InstallFailureWriter(void (*writer)(const char* data, int size)) {
+#ifdef HAVE_SIGACTION
g_failure_writer = writer;
+#endif // HAVE_SIGACTION
}
_END_GOOGLE_NAMESPACE_
diff --git a/src/utilities.cc b/src/utilities.cc
index a6d1961..f31c7c7 100644
--- a/src/utilities.cc
+++ b/src/utilities.cc
@@ -136,6 +136,8 @@ static void DumpStackTrace(int skip_count, DebugWriter *writerfn, void *arg) {
static void DumpStackTraceAndExit() {
DumpStackTrace(1, DebugWriteToStderr, NULL);
+ // TOOD(hamaji): Use signal instead of sigaction?
+#ifdef HAVE_SIGACTION
// Set the default signal handler for SIGABRT, to avoid invoking our
// own signal handler installed by InstallFailedSignalHandler().
struct sigaction sig_action;
@@ -143,6 +145,7 @@ static void DumpStackTraceAndExit() {
sigemptyset(&sig_action.sa_mask);
sig_action.sa_handler = SIG_DFL;
sigaction(SIGABRT, &sig_action, NULL);
+#endif // HAVE_SIGACTION
abort();
}
diff --git a/src/windows/config.h b/src/windows/config.h
index 114762e..2d23fb0 100755
--- a/src/windows/config.h
+++ b/src/windows/config.h
@@ -3,121 +3,6 @@
/* Namespace for Google classes */
#define GOOGLE_NAMESPACE google
-/* Define if you have the `dladdr' function */
-#undef HAVE_DLADDR
-
-/* Define to 1 if you have the <dlfcn.h> header file. */
-#undef HAVE_DLFCN_H
-
-/* Define to 1 if you have the <execinfo.h> header file. */
-#undef HAVE_EXECINFO_H
-
-/* Define to 1 if you have the <inttypes.h> header file. */
-#undef HAVE_INTTYPES_H
-
-/* Define to 1 if you have the <libunwind.h> header file. */
-#undef HAVE_LIBUNWIND_H
-
-/* define if you have google gflags library */
-#undef HAVE_LIB_GFLAGS
-
-/* define if you have libunwind */
-#undef HAVE_LIB_UNWIND
-
-/* Define to 1 if you have the <memory.h> header file. */
-#undef HAVE_MEMORY_H
-
-/* define if the compiler implements namespaces */
-#undef HAVE_NAMESPACES
-
-/* Define if you have POSIX threads libraries and header files. */
-#undef HAVE_PTHREAD
-
-/* define if the compiler implements pthread_rwlock_* */
-#undef HAVE_RWLOCK
-
-/* Define if you have the `sigaltstack' function */
-#undef HAVE_SIGALTSTACK
-
-/* Define to 1 if you have the <stdint.h> header file. */
-#undef HAVE_STDINT_H
-
-/* Define to 1 if you have the <stdlib.h> header file. */
-#undef HAVE_STDLIB_H
-
-/* Define to 1 if you have the <strings.h> header file. */
-#undef HAVE_STRINGS_H
-
-/* Define to 1 if you have the <string.h> header file. */
-#undef HAVE_STRING_H
-
-/* Define to 1 if you have the <syscall.h> header file. */
-#undef HAVE_SYSCALL_H
-
-/* Define to 1 if you have the <sys/stat.h> header file. */
-#undef HAVE_SYS_STAT_H
-
-/* Define to 1 if you have the <sys/syscall.h> header file. */
-#undef HAVE_SYS_SYSCALL_H
-
-/* Define to 1 if you have the <sys/types.h> header file. */
-#undef HAVE_SYS_TYPES_H
-
-/* Define to 1 if you have the <ucontext.h> header file. */
-#undef HAVE_UCONTEXT_H
-
-/* Define to 1 if you have the <unistd.h> header file. */
-#undef HAVE_UNISTD_H
-
-/* define if the compiler supports using expression for operator */
-#undef HAVE_USING_OPERATOR
-
-/* define if your compiler has __attribute__ */
-#undef HAVE___ATTRIBUTE__
-
-/* define if your compiler has __builtin_expect */
-#undef HAVE___BUILTIN_EXPECT
-
-/* define if your compiler has __sync_val_compare_and_swap */
-#undef HAVE___SYNC_VAL_COMPARE_AND_SWAP
-
-/* Name of package */
-#undef PACKAGE
-
-/* Define to the address where bug reports for this package should be sent. */
-#undef PACKAGE_BUGREPORT
-
-/* Define to the full name of this package. */
-#undef PACKAGE_NAME
-
-/* Define to the full name and version of this package. */
-#undef PACKAGE_STRING
-
-/* Define to the one symbol short name of this package. */
-#undef PACKAGE_TARNAME
-
-/* Define to the version of this package. */
-#undef PACKAGE_VERSION
-
-/* How to access the PC from a struct ucontext */
-#undef PC_FROM_UCONTEXT
-
-/* Define to necessary symbol if this constant uses a non-standard name on
- your system. */
-#undef PTHREAD_CREATE_JOINABLE
-
-/* The size of `void *', as computed by sizeof. */
-#undef SIZEOF_VOID_P
-
-/* Define to 1 if you have the ANSI C header files. */
-#undef STDC_HEADERS
-
-/* the namespace where STL code like vector<> is defined */
-#undef STL_NAMESPACE
-
-/* Version number of package */
-#undef VERSION
-
/* Stops putting the code inside the Google namespace */
#define _END_GOOGLE_NAMESPACE_ }
diff --git a/src/windows/port.h b/src/windows/port.h
index c9be748..24d7677 100755
--- a/src/windows/port.h
+++ b/src/windows/port.h
@@ -62,6 +62,8 @@
* used by both C and C++ code, so we put all the C++ together.
*/
+#ifdef _MSC_VER
+
/* 4244: otherwise we get problems when substracting two size_t's to an int
* 4251: it's complaining about a private struct I've chosen not to dllexport
* 4355: we use this in a constructor, but we do it safely
@@ -127,6 +129,8 @@ extern int safe_vsnprintf(char *str, size_t size,
typedef int pid_t;
#define getpid _getpid
+#endif // _MSC_VER
+
// ----------------------------------- THREADS
typedef DWORD pthread_t;
typedef DWORD pthread_key_t;