/src/logging-log4cxx/src/main/cpp/consolewriter.cpp
Line | Count | Source |
1 | | /* |
2 | | * Licensed to the Apache Software Foundation (ASF) under one or more |
3 | | * contributor license agreements. See the NOTICE file distributed with |
4 | | * this work for additional information regarding copyright ownership. |
5 | | * The ASF licenses this file to You under the Apache License, Version 2.0 |
6 | | * (the "License"); you may not use this file except in compliance with |
7 | | * the License. You may obtain a copy of the License at |
8 | | * |
9 | | * http://www.apache.org/licenses/LICENSE-2.0 |
10 | | * |
11 | | * Unless required by applicable law or agreed to in writing, software |
12 | | * distributed under the License is distributed on an "AS IS" BASIS, |
13 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14 | | * See the License for the specific language governing permissions and |
15 | | * limitations under the License. |
16 | | */ |
17 | | |
18 | | #include <log4cxx/private/consolewriter_priv.h> |
19 | | #include <log4cxx/helpers/transcoder.h> |
20 | | #if !defined(LOG4CXX) |
21 | | #define LOG4CXX 1 |
22 | | #endif |
23 | | #include <log4cxx/private/log4cxx_private.h> |
24 | | |
25 | | using namespace LOG4CXX_NS; |
26 | | |
27 | | static bool isConsoleWide(FILE *file) |
28 | 119k | { |
29 | | #if LOG4CXX_FORCE_WIDE_CONSOLE |
30 | | return true; |
31 | | #elif LOG4CXX_FORCE_BYTE_CONSOLE || !LOG4CXX_HAS_FWIDE |
32 | | return false; |
33 | | #else |
34 | 119k | return fwide(file, 0) > 0; |
35 | 119k | #endif |
36 | 119k | } |
37 | | |
38 | | size_t helpers::writeToConsole(const LogString& str, FILE *file) |
39 | 119k | { |
40 | 119k | #if LOG4CXX_WCHAR_T_API |
41 | 119k | if (isConsoleWide(file)) |
42 | 0 | { |
43 | 0 | LOG4CXX_ENCODE_WCHAR(msg, str); |
44 | 0 | int status = fputws(msg.c_str(), file); |
45 | 0 | return status == EOF ? 0 : msg.size(); |
46 | 0 | } |
47 | 119k | #endif |
48 | | |
49 | 119k | LOG4CXX_ENCODE_CHAR(msg, str); |
50 | | |
51 | | // |
52 | | // We can't use fputs, fprintf, or even a `%.*s` specifier |
53 | | // as the message may contain embedded null bytes, which would cause the |
54 | | // message to be prematurely truncated. |
55 | | // |
56 | 119k | return fwrite(msg.data(), 1, msg.size(), file); |
57 | 119k | } log4cxx::helpers::writeToConsole(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, _IO_FILE*) Line | Count | Source | 39 | 83.0k | { | 40 | 83.0k | #if LOG4CXX_WCHAR_T_API | 41 | 83.0k | if (isConsoleWide(file)) | 42 | 0 | { | 43 | 0 | LOG4CXX_ENCODE_WCHAR(msg, str); | 44 | 0 | int status = fputws(msg.c_str(), file); | 45 | 0 | return status == EOF ? 0 : msg.size(); | 46 | 0 | } | 47 | 83.0k | #endif | 48 | | | 49 | 83.0k | LOG4CXX_ENCODE_CHAR(msg, str); | 50 | | | 51 | | // | 52 | | // We can't use fputs, fprintf, or even a `%.*s` specifier | 53 | | // as the message may contain embedded null bytes, which would cause the | 54 | | // message to be prematurely truncated. | 55 | | // | 56 | 83.0k | return fwrite(msg.data(), 1, msg.size(), file); | 57 | 83.0k | } |
log4cxx::helpers::writeToConsole(std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > const&, _IO_FILE*) Line | Count | Source | 39 | 35.9k | { | 40 | 35.9k | #if LOG4CXX_WCHAR_T_API | 41 | 35.9k | if (isConsoleWide(file)) | 42 | 0 | { | 43 | 0 | LOG4CXX_ENCODE_WCHAR(msg, str); | 44 | 0 | int status = fputws(msg.c_str(), file); | 45 | 0 | return status == EOF ? 0 : msg.size(); | 46 | 0 | } | 47 | 35.9k | #endif | 48 | | | 49 | 35.9k | LOG4CXX_ENCODE_CHAR(msg, str); | 50 | | | 51 | | // | 52 | | // We can't use fputs, fprintf, or even a `%.*s` specifier | 53 | | // as the message may contain embedded null bytes, which would cause the | 54 | | // message to be prematurely truncated. | 55 | | // | 56 | 35.9k | return fwrite(msg.data(), 1, msg.size(), file); | 57 | 35.9k | } |
|