]>
git.ipfire.org Git - thirdparty/strongswan.git/blob - src/libstrongswan/utils/utils/path.h
2 * Copyright (C) 2008-2014 Tobias Brunner
3 * Copyright (C) 2008 Martin Willi
5 * Copyright (C) secunet Security Networks AG
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 * @defgroup path_i path
27 * Directory separator character in paths on this platform
30 # define DIRECTORY_SEPARATOR "\\"
31 /* the Windows API also accepts / as separator */
32 # define DIRECTORY_SEPARATOR_ALT "/"
34 # define DIRECTORY_SEPARATOR "/"
38 * Check if the given character is a directory separator.
41 * @return TRUE if the character is a directory separator
43 static inline bool path_is_separator(char c
)
46 return c
== DIRECTORY_SEPARATOR
[0] || c
== DIRECTORY_SEPARATOR_ALT
[0];
48 return c
== DIRECTORY_SEPARATOR
[0];
53 * Returns a pointer to the first occurrence of a directory separator in the
54 * given string (optionally limited to a given length).
56 * @param path path to search
57 * @param len optional length to search, -1 for the full string
58 * @return pointer to separator, or NULL if not found
60 char *path_first_separator(const char *path
, int len
);
63 * Returns a pointer to the last occurrence of a directory separator in the
64 * given string (optionally limited to a given length).
66 * @param path path to search
67 * @param len optional length to search, -1 for the full string
68 * @return pointer to separator, or NULL if not found
70 char *path_last_separator(const char *path
, int len
);
73 * Like dirname(3) returns the directory part of the given null-terminated
74 * pathname, up to but not including the final '/' (or '.' if no '/' is found).
75 * Trailing '/' are not counted as part of the pathname.
77 * The difference is that it does this in a thread-safe manner (i.e. it does not
78 * use static buffers) and does not modify the original path.
80 * @param path original pathname
81 * @return allocated directory component
83 char *path_dirname(const char *path
);
86 * Like basename(3) returns the filename part of the given null-terminated path,
87 * i.e. the part following the final '/' (or '.' if path is empty or NULL).
88 * Trailing '/' are not counted as part of the pathname.
90 * The difference is that it does this in a thread-safe manner (i.e. it does not
91 * use static buffers) and does not modify the original path.
93 * @param path original pathname
94 * @return allocated filename component
96 char *path_basename(const char *path
);
99 * Check if a given path is absolute.
101 * @param path path to check
102 * @return TRUE if absolute, FALSE if relative
104 bool path_absolute(const char *path
);
107 * Creates a directory and all required parent directories.
109 * @param path path to the new directory
110 * @param mode permissions of the new directory/directories
111 * @return TRUE on success
113 bool mkdir_p(const char *path
, mode_t mode
);
115 #endif /** PATH_H_ @} */