Coverage Report

Created: 2026-05-30 06:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/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
51.3k
{
29
#if LOG4CXX_FORCE_WIDE_CONSOLE
30
  return true;
31
#elif LOG4CXX_FORCE_BYTE_CONSOLE || !LOG4CXX_HAS_FWIDE
32
  return false;
33
#else
34
51.3k
  return fwide(file, 0) > 0;
35
51.3k
#endif
36
51.3k
}
37
38
size_t helpers::writeToConsole(const LogString& str, FILE *file)
39
51.3k
{
40
51.3k
#if LOG4CXX_WCHAR_T_API
41
51.3k
  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
51.3k
#endif
48
49
51.3k
  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
51.3k
  return fwrite(msg.data(), 1, msg.size(), file);
57
51.3k
}