rcutils  master
C API providing common utilities and data structures.
filesystem.h
Go to the documentation of this file.
1 // Copyright 2017 Open Source Robotics Foundation, Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
16 
17 #ifndef RCUTILS__FILESYSTEM_H_
18 #define RCUTILS__FILESYSTEM_H_
19 
20 #ifdef __cplusplus
21 extern "C"
22 {
23 #endif
24 
25 #include <stdbool.h>
26 #include <stddef.h>
27 #include <stdint.h>
28 
29 #include "rcutils/allocator.h"
30 #include "rcutils/macros.h"
32 
34 
43 bool
44 rcutils_get_cwd(char * buffer, size_t max_length);
45 
47 
54 bool
55 rcutils_is_directory(const char * abs_path);
56 
58 
65 bool
66 rcutils_is_file(const char * abs_path);
67 
69 
76 bool
77 rcutils_exists(const char * abs_path);
78 
80 
87 bool
88 rcutils_is_readable(const char * abs_path);
89 
91 
98 bool
99 rcutils_is_writable(const char * abs_path);
100 
102 
109 bool
110 rcutils_is_readable_and_writable(const char * abs_path);
111 
113 
126 char *
128  const char * left_hand_path,
129  const char * right_hand_path,
130  rcutils_allocator_t allocator);
131 
133 
145 char *
147  const char * path,
148  rcutils_allocator_t allocator);
149 
151 
165 char *
166 rcutils_expand_user(const char * path, rcutils_allocator_t allocator);
167 
169 
187 bool
188 rcutils_mkdir(const char * abs_path);
189 
191 
205  const char * directory_path,
206  uint64_t * size,
207  rcutils_allocator_t allocator);
208 
210 
234  const char * directory_path,
235  const size_t max_depth,
236  uint64_t * size,
237  rcutils_allocator_t allocator);
238 
240 
245 size_t
246 rcutils_get_file_size(const char * file_path);
247 
249 typedef struct rcutils_dir_iter_t
250 {
252  const char * entry_name;
256  void * state;
258 
260 
276 rcutils_dir_iter_start(const char * directory_path, const rcutils_allocator_t allocator);
277 
279 
285 bool
287 
289 
293 void
295 
296 #ifdef __cplusplus
297 }
298 #endif
299 
300 #endif // RCUTILS__FILESYSTEM_H_
rcutils_is_file
bool rcutils_is_file(const char *abs_path)
Check if the provided path points to a file.
rcutils_dir_iter_t
struct rcutils_dir_iter_t rcutils_dir_iter_t
An iterator used for enumerating directory contents.
macros.h
rcutils_mkdir
bool rcutils_mkdir(const char *abs_path)
Create the specified directory.
rcutils_is_readable
bool rcutils_is_readable(const char *abs_path)
Check if the provided path points to a file/folder readable by current user.
rcutils_dir_iter_next
bool rcutils_dir_iter_next(rcutils_dir_iter_t *iter)
Continue iterating over the contents of a directory.
rcutils_dir_iter_start
rcutils_dir_iter_t * rcutils_dir_iter_start(const char *directory_path, const rcutils_allocator_t allocator)
Begin iterating over the contents of the specified directory.
rcutils_is_directory
bool rcutils_is_directory(const char *abs_path)
Check if the provided path points to a directory.
rcutils_calculate_directory_size_with_recursion
rcutils_ret_t rcutils_calculate_directory_size_with_recursion(const char *directory_path, const size_t max_depth, uint64_t *size, rcutils_allocator_t allocator)
Calculate the size of the specified directory with recursion.
rcutils_get_file_size
size_t rcutils_get_file_size(const char *file_path)
Calculate the size of the specifed file.
rcutils_get_cwd
bool rcutils_get_cwd(char *buffer, size_t max_length)
Return current working directory.
rcutils_ret_t
int rcutils_ret_t
The type that holds a return value for an rcutils operation.
Definition: rcutils_ret.h:26
RCUTILS_WARN_UNUSED
#define RCUTILS_WARN_UNUSED
A macro to make the compiler warn when the return value of a function is not used.
Definition: macros.h:27
rcutils_is_writable
bool rcutils_is_writable(const char *abs_path)
Check if the provided path points to a file/folder writable by current user.
rcutils_dir_iter_t
An iterator used for enumerating directory contents.
Definition: filesystem.h:249
visibility_control.h
rcutils_calculate_directory_size
rcutils_ret_t rcutils_calculate_directory_size(const char *directory_path, uint64_t *size, rcutils_allocator_t allocator)
Calculate the size of the specified directory.
rcutils_exists
bool rcutils_exists(const char *abs_path)
Check if the provided path points to an existing file/folder.
rcutils_to_native_path
char * rcutils_to_native_path(const char *path, rcutils_allocator_t allocator)
Return newly allocated string with all argument's "/" replaced by platform specific separator.
rcutils_allocator_t
Encapsulation of an allocator.
Definition: allocator.h:47
allocator.h
RCUTILS_PUBLIC
#define RCUTILS_PUBLIC
Definition: visibility_control.h:23
rcutils_expand_user
char * rcutils_expand_user(const char *path, rcutils_allocator_t allocator)
Expand user directory in path.
rcutils_dir_iter_end
void rcutils_dir_iter_end(rcutils_dir_iter_t *iter)
Finish iterating over the contents of a directory.
rcutils_join_path
char * rcutils_join_path(const char *left_hand_path, const char *right_hand_path, rcutils_allocator_t allocator)
Return newly allocated string with arguments separated by correct delimiter for the platform.
rcutils_dir_iter_t::allocator
rcutils_allocator_t allocator
The allocator used internally by iteration functions.
Definition: filesystem.h:254
rcutils_is_readable_and_writable
bool rcutils_is_readable_and_writable(const char *abs_path)
Check if the provided path points to a file/folder both readable and writable by current user.
rcutils_dir_iter_t::entry_name
const char * entry_name
The name of the enumerated file or directory.
Definition: filesystem.h:252
rcutils_dir_iter_t::state
void * state
The platform-specific iteration state.
Definition: filesystem.h:256