1 // Copyright (c) 2007, Google Inc.
2 // All rights reserved.
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above
11 // copyright notice, this list of conditions and the following disclaimer
12 // in the documentation and/or other materials provided with the
14 // * Neither the name of Google Inc. nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 // This file just provides storage for FLAGS_verbose.
34 #include "base/logging.h"
35 #include "base/commandlineflags.h"
37 DEFINE_int32(verbose
, EnvToInt("PERFTOOLS_VERBOSE", 0),
38 "Set to numbers >0 for more verbose output, or <0 for less. "
39 "--verbose == -4 means we log fatal errors only.");
42 #if defined(_WIN32) || defined(__CYGWIN__) || defined(__CYGWIN32__)
44 // While windows does have a POSIX-compatible API
45 // (_open/_write/_close), it acquires memory. Using this lower-level
46 // windows API is the closest we can get to being "raw".
47 RawFD
RawOpenForWriting(const char* filename
) {
48 // CreateFile allocates memory if file_name isn't absolute, so if
49 // that ever becomes a problem then we ought to compute the absolute
50 // path on its behalf (perhaps the ntdll/kernel function isn't aware
51 // of the working directory?)
52 RawFD fd
= CreateFileA(filename
, GENERIC_WRITE
, 0, NULL
,
53 CREATE_ALWAYS
, 0, NULL
);
54 if (fd
!= kIllegalRawFD
&& GetLastError() == ERROR_ALREADY_EXISTS
)
55 SetEndOfFile(fd
); // truncate the existing file
59 void RawWrite(RawFD handle
, const char* buf
, size_t len
) {
62 BOOL ok
= WriteFile(handle
, buf
, len
, &wrote
, NULL
);
63 // We do not use an asynchronous file handle, so ok==false means an error
70 void RawClose(RawFD handle
) {
74 #else // _WIN32 || __CYGWIN__ || __CYGWIN32__
76 #ifdef HAVE_SYS_TYPES_H
77 #include <sys/types.h>
86 // Re-run fn until it doesn't cause EINTR.
87 #define NO_INTR(fn) do {} while ((fn) < 0 && errno == EINTR)
89 RawFD
RawOpenForWriting(const char* filename
) {
90 return open(filename
, O_WRONLY
|O_CREAT
|O_TRUNC
, 0664);
93 void RawWrite(RawFD fd
, const char* buf
, size_t len
) {
96 NO_INTR(r
= write(fd
, buf
, len
));
103 void RawClose(RawFD fd
) {
107 #endif // _WIN32 || __CYGWIN__ || __CYGWIN32__