Coverage Report

Created: 2024-11-18 10:37

/root/doris/be/src/util/errno.cpp
Line
Count
Source (jump to first uncovered line)
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with 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,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
#include "util/errno.h"
19
20
#ifndef __APPLE__
21
#include <features.h>
22
#endif
23
24
#include <cstring>
25
26
#include "gutil/dynamic_annotations.h"
27
28
namespace doris {
29
30
0
void errno_to_cstring(int err, char* buf, size_t buf_len) {
31
#if !defined(__GLIBC__) || \
32
        ((_POSIX_C_SOURCE >= 200112 || _XOPEN_SOURCE >= 600) && !defined(_GNU_SOURCE))
33
    // Using POSIX version 'int strerror_r(...)'.
34
    int ret = strerror_r(err, buf, buf_len);
35
    if (ret && ret != ERANGE && ret != EINVAL) {
36
        strncpy(buf, "unknown error", buf_len);
37
        buf[buf_len - 1] = '\0';
38
    }
39
#else
40
    // Using GLIBC version
41
42
    // KUDU-1515: TSAN in Clang 3.9 has an incorrect interceptor for strerror_r:
43
    // https://github.com/google/sanitizers/issues/696
44
0
    ANNOTATE_IGNORE_WRITES_BEGIN();
45
0
    char* ret = strerror_r(err, buf, buf_len);
46
0
    ANNOTATE_IGNORE_WRITES_END();
47
0
    if (ret != buf) {
48
0
        strncpy(buf, ret, buf_len);
49
0
        buf[buf_len - 1] = '\0';
50
0
    }
51
0
#endif
52
0
}
53
54
} // namespace doris