source: rtems-tools/rtemstoolkit/rld-path.h

Last change on this file was b249516, checked in by Chris Johns <chrisj@…>, on Mar 29, 2015 at 7:06:00 AM

rtemstoolkit: Add support to return the system path split as paths.

Seacch the path for the program name if not found and set it as
an absolute path. This allow the prefix to be found.

  • Property mode set to 100644
File size: 4.6 KB
Line 
1/*
2 * Copyright (c) 2011-2014, Chris Johns <chrisj@rtems.org>
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16/**
17 * @file
18 *
19 * @ingroup rtems-ld
20 *
21 * @brief RTEMS Linker Path to help manage paths.
22 *
23 */
24
25#if !defined (_RLD_PATH_H_)
26#define _RLD_PATH_H_
27
28#include <list>
29#include <map>
30#include <string>
31#include <vector>
32
33#include <rld.h>
34
35namespace rld
36{
37  namespace path
38  {
39    /**
40     * Container of file paths.
41     */
42    typedef std::vector < std::string > paths;
43
44    /**
45     * Return the basename of the file name.
46     *
47     * @param name The full file name.
48     * @return const std::string The basename of the file.
49     */
50    const std::string basename (const std::string& name);
51
52    /**
53     * Return the dirname of the file name.
54     *
55     * @param name The full file name.
56     * @return const std::string The dirname of the file.
57     */
58    const std::string dirname (const std::string& name);
59
60    /**
61     * Return the extension of the file name.
62     *
63     * @param name The full file name.
64     * @return const std::string The extension of the file.
65     */
66    const std::string extension (const std::string& name);
67
68    /**
69     * Split a path from a string with the path seperator to the path
70     * container. Add only the paths that exist and ignore those that do not.
71     *
72     * @param path The paths as a single string delimited by the path
73     *             separator.
74     * @param paths The split path paths.
75     */
76    void path_split (const std::string& path,
77                     paths&             paths);
78
79    /**
80     * Make a path by joining the base and part with required separator.
81     *
82     * @param base The path component to be joined.
83     * @param part The file name to add to the path.
84     * @param joined The joined path and file name with a path separator.
85     */
86    void path_join (const std::string& base,
87                    const std::string& part,
88                    std::string&       joined);
89
90    /**
91     * Make a path by joining the parts with the base and the required
92     * separator.
93     *
94     * @param base The path component to be joined.
95     * @param parts The files to add to the path.
96     * @param joined The joined path and file name with a path separator.
97     */
98    void path_join (const std::string& base,
99                    const paths&       parts,
100                    std::string&       joined);
101
102    /**
103     * Return the absolute path given a path and using the current working
104     * directory. The path is flattened removing any '..' sequences.
105     *
106     * @param path The path to be return as absolute.
107     * @return const std::string The absolute path.
108     */
109    const std::string path_abs (const std::string& path);
110
111    /**
112     * Check the path is a file using a stat call.
113     *
114     * @param path The path to check.
115     * @retval true The path is valid.
116     * @retval false The path is not valid.
117     */
118    bool check_file (const std::string& path);
119
120    /**
121     * Check if the path is a directory.
122     *
123     * @param path The path to check.
124     * @retval false The path is not a directory.
125     * @retval true The path is a directory.
126     */
127    bool check_directory (const std::string& path);
128
129    /**
130     * Find the file given a container of paths and file names.
131     *
132     * @param path The path of the file if found else empty.
133     * @param name The name of the file to search for.
134     * @param search_paths The container of paths to search.
135     */
136    void find_file (std::string&       path,
137                    const std::string& name,
138                    paths&             search_paths);
139
140    /**
141     * Unlink the file.
142     *
143     * @param path The path of the file to unlink.
144     */
145    void unlink (const std::string& path, bool not_present_error = false);
146
147    /**
148     * Return the system path as a set of strings.
149     *
150     * @param paths The split path paths.
151     */
152    void get_system_path (paths& paths);
153  }
154}
155
156#endif
Note: See TracBrowser for help on using the repository browser.