rcutils  master
C API providing common utilities and data structures.
Functions
filesystem.h File Reference
#include <stdbool.h>
#include <stddef.h>
#include "rcutils/allocator.h"
#include "rcutils/macros.h"
#include "rcutils/visibility_control.h"
Include dependency graph for filesystem.h:

Go to the source code of this file.

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...
 
bool rcutils_mkdir (const char *abs_path)
 Create the specified directory. More...
 
size_t rcutils_calculate_directory_size (const char *directory_path, rcutils_allocator_t allocator)
 Calculate the size of the specified directory. More...
 
size_t rcutils_get_file_size (const char *file_path)
 Calculate the size of the specifed file. More...
 

Function Documentation

◆ rcutils_get_cwd()

bool rcutils_get_cwd ( char *  buffer,
size_t  max_length 
)

Return current working directory.

Parameters
[in]bufferAllocated string to store current directory path to
[in]max_lengthmaximum length to be stored in buffer
Returns
True if success
False if buffer is NULL
False on failure

◆ rcutils_is_directory()

bool rcutils_is_directory ( const char *  abs_path)

Check if the provided path points to a directory.

Parameters
[in]abs_pathAbsolute path to check.
Returns
True if directory
False if abs_path is NULL
False on failure

◆ rcutils_is_file()

bool rcutils_is_file ( const char *  abs_path)

Check if the provided path points to a file.

Parameters
[in]abs_pathAbsolute path to check.
Returns
True if file
False if abs_path is NULL
False on failure

◆ rcutils_exists()

bool rcutils_exists ( const char *  abs_path)

Check if the provided path points to an existing file/folder.

Parameters
[in]abs_pathAbsolute path to check.
Returns
True if the path exists
False if abs_path is NULL
False on failure

◆ 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.

Parameters
[in]abs_pathAbsolute path to check.
Returns
True if the file is readable
False if abs_path is NULL
False on failure

◆ 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.

Parameters
[in]abs_pathAbsolute path to check.
Returns
True if the file is writable
False if abs_path is NULL
False on failure

◆ 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.

Parameters
[in]abs_pathAbsolute path to check.
Returns
True if the file is redable and writable False otherwise
False if abs_path is NULL
False on failure

◆ 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.

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.

Parameters
[in]left_hand_path
[in]right_hand_path
[in]allocator
Returns
concatenated path on success
NULL on invalid arguments
NULL on failure

◆ 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.

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.

Parameters
[in]path
[in]allocator
Returns
path using platform specific delimiters on success
NULL on invalid arguments
NULL on failure

◆ rcutils_mkdir()

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.

Parameters
[in]abs_path
Returns
True if making the directory was successful, False otherwise
False if path is NULL
False if path is empty
False if path is not absolute
False if any intermediate directories don't exist

◆ rcutils_calculate_directory_size()

size_t rcutils_calculate_directory_size ( const char *  directory_path,
rcutils_allocator_t  allocator 
)

Calculate the size of the specified directory.

◆ rcutils_get_file_size()

size_t rcutils_get_file_size ( const char *  file_path)

Calculate the size of the specifed file.