Mstdlib-1.24.0

Functions

size_t M_fs_path_get_path_max (M_fs_system_t sys_type)
 
M_bool M_fs_path_isabs (const char *p, M_fs_system_t sys_type)
 
M_bool M_fs_path_isunc (const char *p)
 
M_bool M_fs_path_ishidden (const char *path, const M_fs_info_t *info)
 
M_list_str_tM_fs_path_componentize_path (const char *path, M_fs_system_t sys_type)
 
char * M_fs_path_join (const char *p1, const char *p2, M_fs_system_t sys_type)
 
char * M_fs_path_join_parts (const M_list_str_t *path, M_fs_system_t sys_type)
 
char * M_fs_path_join_vparts (M_fs_system_t sys_type, size_t num,...)
 
char * M_fs_path_join_resolved (const char *path, const char *part, const char *resolved_name, M_fs_system_t sys_type)
 
char * M_fs_path_dirname (const char *path, M_fs_system_t sys_type)
 
char * M_fs_path_basename (const char *path, M_fs_system_t sys_type)
 
char * M_fs_path_user_confdir (M_fs_system_t sys_type)
 
char * M_fs_path_tmpdir (M_fs_system_t sys_type)
 
M_fs_error_t M_fs_path_get_cwd (char **cwd)
 
M_fs_error_t M_fs_path_set_cwd (const char *path)
 
M_fs_error_t M_fs_path_readlink (char **out, const char *path)
 
M_fs_error_t M_fs_path_norm (char **out, const char *path, M_uint32 flags, M_fs_system_t sys_type)
 

Detailed Description

Function Documentation

◆ M_fs_path_get_path_max()

size_t M_fs_path_get_path_max ( M_fs_system_t  sys_type)

Determine the max path length for the system.

Parameters
[in]sys_typeThe system type used to determine the maximum path length.
Returns
The maximum path length.

◆ M_fs_path_isabs()

M_bool M_fs_path_isabs ( const char *  p,
M_fs_system_t  sys_type 
)

Check if a path is an absolute path.

A path is absolute if it's Unix and starts with /. Or Windows and starts with \\ (UNC) or a drive letter.

Parameters
[in]pThe path.
[in]sys_typeThe system type.
Returns
M_TRUE if an absolute path. Otherwise M_FALSE.

◆ M_fs_path_isunc()

M_bool M_fs_path_isunc ( const char *  p)

Check if a path is a UNC path.

A path is UNC if it's Windows and starts with "\\\\".

Parameters
[in]pThe path.
Returns
M_TRUE if an UNC path. Otherwise M_FALSE.

◆ M_fs_path_ishidden()

M_bool M_fs_path_ishidden ( const char *  path,
const M_fs_info_t info 
)

Check if the path is considered hidden by the OS.

Either the path or info parameters can be NULL. Both cannot be NULL.

Parameters
[in]pathThe path.
[in]infoThe info.
Returns
Whether the path is considered hidden.

◆ M_fs_path_componentize_path()

M_list_str_t * M_fs_path_componentize_path ( const char *  path,
M_fs_system_t  sys_type 
)

Take a path and split it into components.

This will remove empty parts. An absolute path (Unix) starting with / will have the / replaced with an empty to start the list. The same is true for UNC paths. An empty at the start of the path list should be treated as an absolute path.

Parameters
[in]pathThe path.
[in]sys_typeThe system type.
Returns
A list of path parts.

◆ M_fs_path_join()

char * M_fs_path_join ( const char *  p1,
const char *  p2,
M_fs_system_t  sys_type 
)

Join two parts into one path.

If either part is empty the separator won't be added. Unlike M_fs_path_join_parts this does not have special handling (using an empty string) for absolute paths. This is a convenience function to write the appropriate system separator between two paths.

Parameters
[in]p1First part.
[in]p2Second part.
[in]sys_typeThe system type.
Returns
The path as a single string.

◆ M_fs_path_join_parts()

char * M_fs_path_join_parts ( const M_list_str_t path,
M_fs_system_t  sys_type 
)

Take a list of path components and join them into a string separated by the system path separator.

Empty parts (except the first on Unix and UNC) will be ignored. An empty part at the start is used on Unix and UNC to denote an absolute path.

Parameters
[in]pathThe path.
[in]sys_typeThe system type.
Returns
The path as a single string.

◆ M_fs_path_join_vparts()

char * M_fs_path_join_vparts ( M_fs_system_t  sys_type,
size_t  num,
  ... 
)

Take a list of path components and join them into a string separated by the system path separator.

Empty parts (except the first on Unix and UNC) will be ignored. An empty part at the start is used on Unix and UNC to denote an absolute path.

Parameters
[in]sys_typeThe system type.
[in]numThe number of parts.
[in]...char * parts to be joined.
Returns
The path as a single string.

◆ M_fs_path_join_resolved()

char * M_fs_path_join_resolved ( const char *  path,
const char *  part,
const char *  resolved_name,
M_fs_system_t  sys_type 
)

Join a base path, the name and the resolved name into the full resolved path.

This is a helper for dealing with M_fs_dir_walk in order to determine the resolved path when the entry returned by the callback is a symlink.

We have three parts: path, entry_name, resolved_name. The entry_name needs to have the last part removed because it is a symlink. Then we need to put path and resolved_name on either size to get the real name.

For example: path = /usr/share/zoneinfo/America part = Indiana/Indianapolis resolved_name = ../../posix/America/Indiana/Indianapolis

We need: /usr/share/zoneinfo/America/Indiana/../../posix/America/Indiana/Indianapolis

Parameters
[in]pathThe base path.
[in]partThe path component under the base.
[in]resolved_nameThe resolved path for a symlink that needs to be combined with the base and part.
[in]sys_typeThe system type.
Returns
The resolved path.

◆ M_fs_path_dirname()

char * M_fs_path_dirname ( const char *  path,
M_fs_system_t  sys_type 
)

Strip last component from a filename.

Remove last full non-slash component. Output will not include trailing slashes. E.g: /usr/bin/echo.exe -> /usr/bin

A path without a dir component will output NULL as there is no directory and cannot be assumed to be a relative path.

Parameters
[in]pathThe path.
[in]sys_typeThe system path logic and separator to use.
Returns
The path component from a filename.

◆ M_fs_path_basename()

char * M_fs_path_basename ( const char *  path,
M_fs_system_t  sys_type 
)

Strip all but the last component from a filename.

Remove all but the last full non-slash component. Output will not include trailing slashes.

E.g: /usr/bin/ -> bin

E.g: bin -> bin

Parameters
[in]pathThe path.
[in]sys_typeThe system path logic and separator to use.
Returns
The path last component from a filename.

◆ M_fs_path_user_confdir()

char * M_fs_path_user_confdir ( M_fs_system_t  sys_type)

The user's configuration directory.

This is a user level not system level directory. This is the OS standard directory for application configuration files.

Parameters
[in]sys_typeThe system path logic and separator to use.
Returns
The path to the config dir, otherwise NULL on error.

◆ M_fs_path_tmpdir()

char * M_fs_path_tmpdir ( M_fs_system_t  sys_type)

Temporary directory set by the system that the application can use for temporary storage.

Warning
This is NOT a secure location.

Other processes on the system can share this directory. It's recommend to create an applications specific subdirectory to use for temporary files. Again, this is NOT intended to be used for secure files or when secure files are necessary.

This should only be used for temporary storage of files being manipulated. For example, unpacking a compressed archive then moving the files to the destination. Or saving to a temporary file then using M_fs_move to ensure an atomic write.

Parameters
[in]sys_typeThe system path logic and separator to use.
Returns
The path to a temporary dir, otherwise NULL on error.

◆ M_fs_path_get_cwd()

M_fs_error_t M_fs_path_get_cwd ( char **  cwd)

Get the current working directory for the calling process.

Parameters
[in]cwdAn allocated string with the cwd.
Returns
result.

◆ M_fs_path_set_cwd()

M_fs_error_t M_fs_path_set_cwd ( const char *  path)

Set the current working directory for the calling process.

Parameters
[in]pathThe path to set as the cwd.
Returns
result.

◆ M_fs_path_readlink()

M_fs_error_t M_fs_path_readlink ( char **  out,
const char *  path 
)

Resolve a symlink.

Reads the value pointed to by a symlink.

Parameters
[out]outAn allocated string with the normalized path.
[in]pathThe path to resolve.
Returns
Result.

◆ M_fs_path_norm()

M_fs_error_t M_fs_path_norm ( char **  out,
const char *  path,
M_uint32  flags,
M_fs_system_t  sys_type 
)

Normalize a path.

This typically does not need to be called because all functions that take a path (file) will call this internally using the appropriate parameters. This is provided as a convenience for displaying paths to a user.

Supported features on all OS's;

  • Home dir (~) expansion.
  • Environment variable expansion (both $var and %var%).

Supported feature Unix only:

  • Symlink resolution.
Parameters
[out]outAn allocated string with the normalized path.
[in]pathThe path to normalize.
[in]flagsM_fs_path_norm_t flags to control the normalization behavior.
[in]sys_typeThe system path format to the path is in. This denotes the path type and how it should be normalized. For example, a Windows path with "C:\..." passed with the UNIX type will do strange things because it is not a Unix formatted path. The purpose of this argument is to specify the path type if known. Allows a Windows path on a Unix system to be parsed properly even though it's not the standard path type for the system. Note that if the path is not the same as the system standard type the M_FS_PATH_NORM_ABSOLUTE my give unexpected results for non-absolute paths. For example this relative path specified as a Windows path run on a Unix system: ".\\abc.\\\\\\..\\xyz\\\\.\\123\\.\\xyr\\." may result in something like May give a result like: "home\jschember\svn\mstdlib-trunk\build\xyz\123\xyr" Notice there is no '\' or drive letter because they are not technically valid. However, the path was properly converted to an absolute path.
Returns
Result.