blob: f4a3dafa4fa65e43685bd256b6a39be5d4c7526b [file] [log] [blame]
Dimitry Ivanovdf91dc22016-02-25 15:22:04 -08001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "linker_dlwarning.h"
18
19#include <strings.h>
20
21#include <string>
22
23static std::string current_msg;
24static std::string old_msg;
25
26void add_dlwarning(const char* sopath, const char* message, const char* value) {
27 if (!current_msg.empty()) {
28 current_msg += '\n';
29 }
30
31 current_msg = current_msg + basename(sopath) + ": " + message;
32
33 if (value != nullptr) {
34 current_msg = current_msg + " \'" + value + "\'";
35 }
36
37}
38
39// Resets the current one (like dlerror but instead of
40// being thread-local it is process-local).
41const char* get_dlwarning() {
42 if (current_msg.empty()) {
43 return nullptr;
44 }
45
46 old_msg = current_msg;
47 current_msg.clear();
48
49 return old_msg.c_str();
50}