annotate Resources/Patches/glog-visual-studio-port.h @ 1675:131136aeeaa7 db-changes

improved exception handling in the main program
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 02 Oct 2015 13:57:54 +0200
parents 929bf8c2123d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1059
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /* Copyright (c) 2008, Google Inc.
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * All rights reserved.
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 *
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Redistribution and use in source and binary forms, with or without
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 * modification, are permitted provided that the following conditions are
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 * met:
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 *
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * * Redistributions of source code must retain the above copyright
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * notice, this list of conditions and the following disclaimer.
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * * Redistributions in binary form must reproduce the above
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * copyright notice, this list of conditions and the following disclaimer
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * in the documentation and/or other materials provided with the
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * distribution.
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * * Neither the name of Google Inc. nor the names of its
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * contributors may be used to endorse or promote products derived from
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * this software without specific prior written permission.
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 *
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 *
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 * ---
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 * Author: Craig Silverstein
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 * Copied from google-perftools and modified by Shinichiro Hamaji
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 *
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 * These are some portability typedefs and defines to make it a bit
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 * easier to compile this code under VC++.
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 *
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 * Several of these are taken from glib:
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 * http://developer.gnome.org/doc/API/glib/glib-windows-compatability-functions.html
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 */
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 #ifndef CTEMPLATE_WINDOWS_PORT_H_
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 #define CTEMPLATE_WINDOWS_PORT_H_
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 #include "config.h"
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 #ifdef _WIN32
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 #define WIN32_LEAN_AND_MEAN /* We always want minimal includes */
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 #include <windows.h>
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 #include <winsock.h> /* for gethostname */
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 #include <io.h> /* because we so often use open/close/etc */
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 #include <direct.h> /* for _getcwd() */
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 #include <process.h> /* for _getpid() */
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 #include <stdio.h> /* read in vsnprintf decl. before redifining it */
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 #include <stdarg.h> /* template_dictionary.cc uses va_copy */
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 #include <string.h> /* for _strnicmp(), strerror_s() */
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 #include <time.h> /* for localtime_s() */
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 /* Note: the C++ #includes are all together at the bottom. This file is
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 * used by both C and C++ code, so we put all the C++ together.
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 */
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61
1111
929bf8c2123d Fixes for Visual Studio 2013 64bit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1059
diff changeset
62 // Fix by Sebastien Jodogne for Visual Studio 2013
929bf8c2123d Fixes for Visual Studio 2013 64bit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1059
diff changeset
63 // https://code.google.com/p/google-glog/issues/detail?id=212
929bf8c2123d Fixes for Visual Studio 2013 64bit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1059
diff changeset
64 #if defined(_MSC_VER) && (_MSC_VER >= 1800)
929bf8c2123d Fixes for Visual Studio 2013 64bit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1059
diff changeset
65 #include <algorithm>
929bf8c2123d Fixes for Visual Studio 2013 64bit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1059
diff changeset
66 #endif
929bf8c2123d Fixes for Visual Studio 2013 64bit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1059
diff changeset
67
1059
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 /* 4244: otherwise we get problems when substracting two size_t's to an int
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 * 4251: it's complaining about a private struct I've chosen not to dllexport
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 * 4355: we use this in a constructor, but we do it safely
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 * 4715: for some reason VC++ stopped realizing you can't return after abort()
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 * 4800: we know we're casting ints/char*'s to bools, and we're ok with that
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 * 4996: Yes, we're ok using "unsafe" functions like fopen() and strerror()
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 */
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 #pragma warning(disable:4244 4251 4355 4715 4800 4996)
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 /* file I/O */
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 #define PATH_MAX 1024
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 #define access _access
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 #define getcwd _getcwd
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 #define open _open
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 #define read _read
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 #define write _write
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 #define lseek _lseek
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 #define close _close
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 #define popen _popen
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 #define pclose _pclose
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 #define R_OK 04 /* read-only (for access()) */
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 #define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR)
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 #ifndef __MINGW32__
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 enum { STDIN_FILENO = 0, STDOUT_FILENO = 1, STDERR_FILENO = 2 };
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 #endif
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 #define S_IRUSR S_IREAD
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 #define S_IWUSR S_IWRITE
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 /* Not quite as lightweight as a hard-link, but more than good enough for us. */
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 #define link(oldpath, newpath) CopyFileA(oldpath, newpath, false)
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 #define strcasecmp _stricmp
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 #define strncasecmp _strnicmp
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 /* In windows-land, hash<> is called hash_compare<> (from xhash.h) */
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 #if _MSC_VER < 1700
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 #define hash hash_compare
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 #endif
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 /* Sleep is in ms, on windows */
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 #define sleep(secs) Sleep((secs) * 1000)
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 /* We can't just use _vsnprintf and _snprintf as drop-in-replacements,
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 * because they don't always NUL-terminate. :-( We also can't use the
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 * name vsnprintf, since windows defines that (but not snprintf (!)).
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 */
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 extern int snprintf(char *str, size_t size,
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 const char *format, ...);
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 extern int safe_vsnprintf(char *str, size_t size,
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 const char *format, va_list ap);
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 #define vsnprintf(str, size, format, ap) safe_vsnprintf(str, size, format, ap)
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 #define va_copy(dst, src) (dst) = (src)
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 /* Windows doesn't support specifying the number of buckets as a
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 * hash_map constructor arg, so we leave this blank.
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 */
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 #define CTEMPLATE_SMALL_HASHTABLE
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 #define DEFAULT_TEMPLATE_ROOTDIR ".."
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 // ----------------------------------- SYSTEM/PROCESS
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 typedef int pid_t;
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 #define getpid _getpid
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 // ----------------------------------- THREADS
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 typedef DWORD pthread_t;
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 typedef DWORD pthread_key_t;
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 typedef LONG pthread_once_t;
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 enum { PTHREAD_ONCE_INIT = 0 }; // important that this be 0! for SpinLock
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 #define pthread_self GetCurrentThreadId
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 #define pthread_equal(pthread_t_1, pthread_t_2) ((pthread_t_1)==(pthread_t_2))
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 #if defined(__MINGW32__)
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 inline int localtime_s(tm * _tm, const time_t * time)
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 {
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 tm * posix_local_time_struct = localtime(time);
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 if (posix_local_time_struct == NULL)
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 {
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 return 1;
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 }
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 *_tm = *posix_local_time_struct;
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 return 0;
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 }
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 inline char* strerror_s(char* buf, size_t buflen, int errnum)
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 {
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 const char* str = strerror(errnum);
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 return strncpy(buf, str, buflen - 1);
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 }
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 #endif
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 inline struct tm* localtime_r(const time_t* timep, struct tm* result) {
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 localtime_s(result, timep);
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 return result;
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 }
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 inline char* strerror_r(int errnum, char* buf, size_t buflen) {
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 strerror_s(buf, buflen, errnum);
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 return buf;
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 }
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 #ifndef __cplusplus
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 /* I don't see how to get inlining for C code in MSVC. Ah well. */
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 #define inline
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 #endif
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 #endif /* _WIN32 */
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177
f25c79497739 patch glog for visual studio >= 11.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 #endif /* CTEMPLATE_WINDOWS_PORT_H_ */