blob: 2e015a578476b7ef615c7067d61a188649a8efbf [file] [log] [blame]
Dmitriy Ivanova1feb112015-10-01 18:41:57 -07001/*
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#ifndef __LINKER_UTILS_H
17#define __LINKER_UTILS_H
18
19#include <string>
Dimitry Ivanov48ec2882016-08-04 11:50:36 -070020#include <vector>
Dmitriy Ivanova1feb112015-10-01 18:41:57 -070021
Dmitriy Ivanov42d5fcb2015-10-29 17:01:24 -070022extern const char* const kZipFileSeparator;
23
Dmitriy Ivanov42d5fcb2015-10-29 17:01:24 -070024bool file_is_in_dir(const std::string& file, const std::string& dir);
Dimitry Ivanov284ae352015-12-08 10:47:13 -080025bool file_is_under_dir(const std::string& file, const std::string& dir);
Dimitry Ivanov48ec2882016-08-04 11:50:36 -070026bool normalize_path(const char* path, std::string* normalized_path);
Dmitriy Ivanov42d5fcb2015-10-29 17:01:24 -070027bool parse_zip_path(const char* input_path, std::string* zip_path, std::string* entry_path);
Dmitriy Ivanova1feb112015-10-01 18:41:57 -070028
Dimitry Ivanov48ec2882016-08-04 11:50:36 -070029// For every path element this function checks of it exists, and is a directory,
30// and normalizes it:
31// 1. For regular path it converts it to realpath()
32// 2. For path in a zip file it uses realpath on the zipfile
33// normalizes entry name by calling normalize_path function.
34void resolve_paths(std::vector<std::string>& paths, std::vector<std::string>* resolved_paths);
35void split_path(const char* path, const char* delimiters, std::vector<std::string>* paths);
36
37std::string dirname(const char* path);
38
Dmitriy Ivanov84bab5a2015-11-20 13:34:11 -080039off64_t page_start(off64_t offset);
40size_t page_offset(off64_t offset);
41bool safe_add(off64_t* out, off64_t a, size_t b);
42
Dmitriy Ivanova1feb112015-10-01 18:41:57 -070043#endif