summaryrefslogtreecommitdiffstats
path: root/rtemstoolkit/rld-path.h
blob: d73c59b119558e56fb463ee46d12e5570b23330c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*
 * Copyright (c) 2011-2014, Chris Johns <chrisj@rtems.org>
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */
/**
 * @file
 *
 * @ingroup rtems-ld
 *
 * @brief RTEMS Linker Path to help manage paths.
 *
 */

#if !defined (_RLD_PATH_H_)
#define _RLD_PATH_H_

#include <list>
#include <map>
#include <string>
#include <vector>

#include <rld.h>

namespace rld
{
  namespace path
  {
    /**
     * Container of file paths.
     */
    typedef std::vector < std::string > paths;

    /**
     * Return the basename of the file name.
     *
     * @param name The full file name.
     * @return const std::string The basename of the file.
     */
    const std::string basename (const std::string& name);

    /**
     * Return the dirname of the file name.
     *
     * @param name The full file name.
     * @return const std::string The dirname of the file.
     */
    const std::string dirname (const std::string& name);

    /**
     * Return the extension of the file name.
     *
     * @param name The full file name.
     * @return const std::string The extension of the file.
     */
    const std::string extension (const std::string& name);

    /**
     * Split a path from a string with the path seperator to the path
     * container. Add only the paths that exist and ignore those that do not.
     *
     * @param path The paths as a single string delimited by the path
     *             separator.
     * @param paths The split path paths.
     */
    void path_split (const std::string& path,
                     paths&             paths);

    /**
     * Make a path by joining the base and part with required separator.
     *
     * @param base The path component to be joined.
     * @param part The file name to add to the path.
     * @param joined The joined path and file name with a path separator.
     */
    void path_join (const std::string& base,
                    const std::string& part,
                    std::string&       joined);

    /**
     * Make a path by joining the parts with the base and the required
     * separator.
     *
     * @param base The path component to be joined.
     * @param parts The files to add to the path.
     * @param joined The joined path and file name with a path separator.
     */
    void path_join (const std::string& base,
                    const paths&       parts,
                    std::string&       joined);

    /**
     * Return the absolute path given a path and using the current working
     * directory. The path is flattened removing any '..' sequences.
     *
     * @param path The path to be return as absolute.
     * @return const std::string The absolute path.
     */
    const std::string path_abs (const std::string& path);

    /**
     * Check the path is a file using a stat call.
     *
     * @param path The path to check.
     * @retval true The path is valid.
     * @retval false The path is not valid.
     */
    bool check_file (const std::string& path);

    /**
     * Check if the path is a directory.
     *
     * @param path The path to check.
     * @retval false The path is not a directory.
     * @retval true The path is a directory.
     */
    bool check_directory (const std::string& path);

    /**
     * Find the file given a container of paths and file names.
     *
     * @param path The path of the file if found else empty.
     * @param name The name of the file to search for.
     * @param search_paths The container of paths to search.
     */
    void find_file (std::string&       path,
                    const std::string& name,
                    paths&             search_paths);

    /**
     * Unlink the file.
     *
     * @param path The path of the file to unlink.
     */
    void unlink (const std::string& path, bool not_present_error = false);

  }
}

#endif