rcutils
master
C API providing common utilities and data structures.
|
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "rcutils/allocator.h"
#include "rcutils/macros.h"
#include "rcutils/visibility_control.h"
Go to the source code of this file.
Classes | |
struct | rcutils_dir_iter_t |
An iterator used for enumerating directory contents. More... | |
Typedefs | |
typedef struct rcutils_dir_iter_t | rcutils_dir_iter_t |
An iterator used for enumerating directory contents. More... | |
Functions | |
bool | rcutils_get_cwd (char *buffer, size_t max_length) |
Return current working directory. More... | |
bool | rcutils_is_directory (const char *abs_path) |
Check if the provided path points to a directory. More... | |
bool | rcutils_is_file (const char *abs_path) |
Check if the provided path points to a file. More... | |
bool | rcutils_exists (const char *abs_path) |
Check if the provided path points to an existing file/folder. More... | |
bool | rcutils_is_readable (const char *abs_path) |
Check if the provided path points to a file/folder readable by current user. More... | |
bool | rcutils_is_writable (const char *abs_path) |
Check if the provided path points to a file/folder writable by current user. More... | |
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. More... | |
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. More... | |
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. More... | |
char * | rcutils_expand_user (const char *path, rcutils_allocator_t allocator) |
Expand user directory in path. More... | |
bool | rcutils_mkdir (const char *abs_path) |
Create the specified directory. More... | |
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. More... | |
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. More... | |
size_t | rcutils_get_file_size (const char *file_path) |
Calculate the size of the specifed file. More... | |
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. More... | |
bool | rcutils_dir_iter_next (rcutils_dir_iter_t *iter) |
Continue iterating over the contents of a directory. More... | |
void | rcutils_dir_iter_end (rcutils_dir_iter_t *iter) |
Finish iterating over the contents of a directory. More... | |
typedef struct rcutils_dir_iter_t rcutils_dir_iter_t |
An iterator used for enumerating directory contents.
bool rcutils_get_cwd | ( | char * | buffer, |
size_t | max_length | ||
) |
Return current working directory.
[in] | buffer | Allocated string to store current directory path to |
[in] | max_length | maximum length to be stored in buffer |
true
if success, or false
if buffer is NULL, or false
on failure. bool rcutils_is_directory | ( | const char * | abs_path | ) |
Check if the provided path points to a directory.
[in] | abs_path | Absolute path to check. |
true
if provided path is a directory, or false
if abs_path is NULL, or false
on failure. bool rcutils_is_file | ( | const char * | abs_path | ) |
Check if the provided path points to a file.
[in] | abs_path | Absolute path to check. |
true
if provided path is a file, or false
if abs_path is NULL, or false
on failure. bool rcutils_exists | ( | const char * | abs_path | ) |
Check if the provided path points to an existing file/folder.
[in] | abs_path | Absolute path to check. |
true
if the path exists, or false
if abs_path is NULL, or false
on failure. bool rcutils_is_readable | ( | const char * | abs_path | ) |
Check if the provided path points to a file/folder readable by current user.
[in] | abs_path | Absolute path to check. |
true
if the file is readable, or false
if abs_path is NULL, or false
on failure. bool rcutils_is_writable | ( | const char * | abs_path | ) |
Check if the provided path points to a file/folder writable by current user.
[in] | abs_path | Absolute path to check. |
true
if the file is writable, or false
if abs_path is NULL, or false
on failure. 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.
[in] | abs_path | Absolute path to check. |
true
if the file is readable and writable, or false
if abs_path is NULL false
on failure. 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.
This function allocates memory and returns it to the caller. It is up to the caller to release the memory once it is done with it by calling deallocate
on the same allocator passed here.
[in] | left_hand_path | |
[in] | right_hand_path | |
[in] | allocator |
NULL
on invalid arguments NULL
on failure 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.
This function allocates memory and returns it to the caller. It is up to the caller to release the memory once it is done with it by calling deallocate
on the same allocator passed here.
[in] | path | |
[in] | allocator |
NULL
on invalid arguments NULL
on failure char* rcutils_expand_user | ( | const char * | path, |
rcutils_allocator_t | allocator | ||
) |
Expand user directory in path.
This function expands an initial '~' to the current user's home directory. The home directory is fetched using rcutils_get_home_dir()
. This function returns a newly allocated string on success. It is up to the caller to release the memory once it is done with it by calling deallocate
on the same allocator passed here.
[in] | path | A null-terminated C string representing a path. |
[in] | allocator |
NULL
on invalid arguments, or NULL
on failure. bool rcutils_mkdir | ( | const char * | abs_path | ) |
Create the specified directory.
This function creates an absolutely-specified directory. If any of the intermediate directories do not exist, this function will return False. If the abs_path already exists, and is a directory, this function will return true.
This function is not thread-safe due to mkdir races as described in the openat(2) documentation.
[in] | abs_path |
true
if making the directory was successful, or false
if path is NULL, or false
if path is empty, or false
if path is not absolute, or false
if any intermediate directories don't exist. 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.
Calculates the size of a directory by summarizing the file size of all files.
[in] | directory_path | The directory path to calculate the size of. |
[out] | size | The size of the directory in bytes on success. |
[in] | allocator | Allocator being used for internal file path composition. |
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.
Calculates the size of a directory and subdirectory by summarizing the file size of all files. If necessary, you can specify the maximum directory depth to recurse into. Depth definition as below.
[in] | directory_path | The directory path to calculate the size of. |
[in] | max_depth | The maximum depth of subdirectory. 0 means no limitation. |
[out] | size | The size of the directory in bytes on success. |
[in] | allocator | Allocator being used for internal file path composition. |
size_t rcutils_get_file_size | ( | const char * | file_path | ) |
Calculate the size of the specifed file.
[in] | file_path | The path of the file to obtain its size of. |
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.
This function is used to list the files and directories that are contained in a specified directory. The structure returned by it must be deallocated using rcutils_dir_iter_end when the iteration is completed. The name of the enumerated entry is stored in the entry_name
member of the returned object, and the first entry is already populated upon completion of this function. To populate the entry with the name of the next entry, use the rcutils_dir_iter_next function. Note that the "." and ".." entries are typically among the entries enumerated.
[in] | directory_path | The directory path to iterate over the contents of. |
[in] | allocator | Allocator used to create the returned structure. |
bool rcutils_dir_iter_next | ( | rcutils_dir_iter_t * | iter | ) |
Continue iterating over the contents of a directory.
[in] | iter | An iterator created by rcutils_dir_iter_start. |
true
if another entry was found, or false
if there are no more entries in the directory. void rcutils_dir_iter_end | ( | rcutils_dir_iter_t * | iter | ) |
Finish iterating over the contents of a directory.
[in] | iter | An iterator created by rcutils_dir_iter_start. |