libu8
u8pathfns.h File Reference

These functions provide ways to manipulate file pathnames. More...

Functions

U8_EXPORT u8_string u8_getcwd (void)
 Gets the current working directory. More...
 
U8_EXPORT int u8_setcwd (u8_string dirname)
 Changes the current working directory. More...
 
U8_EXPORT char * u8_localpath (u8_string path)
 Returns an absolute local pathname from a utf-8 pathname. More...
 
U8_EXPORT u8_string u8_mkpath (u8_string dir, u8_string name)
 Makes a pathname by combining a directory and a name component. More...
 
U8_EXPORT u8_string u8_abspath (u8_string path, u8_string wd)
 Returns an absolute pathname given a current directory. More...
 
U8_EXPORT u8_string u8_dirname (u8_string path)
 Returns the directory component of a pathname. More...
 
U8_EXPORT u8_string u8_pathsuffix (u8_string path)
 Returns the suffix component of a pathname. More...
 
U8_EXPORT u8_string u8_basename (u8_string path, u8_string suffix)
 Returns the non-directory non-suffix component of a pathname. More...
 
u8_string u8_realpath (u8_string path, u8_string wd)
 Returns an absolute pathname, resolving symbolic links. More...
 

Detailed Description

These functions provide ways to manipulate file pathnames.

They provide both utility functions and translation from unix-style UTF-8 pathnames to the local file system encoding and conventions. They do not provide access (in general) to file metadata or content.

Function Documentation

U8_EXPORT u8_string u8_abspath ( u8_string  path,
u8_string  wd 
)

Returns an absolute pathname given a current directory.

Parameters
patha pathname
wda directory name
Returns
a utf-8 string

References u8_directoryp(), u8_dirname(), u8_getcwd(), u8_mkpath(), u8_string_append(), and u8_valid_copy().

Referenced by u8_localpath(), u8_pathsuffix(), u8_readlink(), u8_realpath(), and u8_rmdir().

U8_EXPORT u8_string u8_basename ( u8_string  path,
u8_string  suffix 
)

Returns the non-directory non-suffix component of a pathname.

Returns the non-directory non-suffix component of a pathname. If the suffix is provided, it is stripped from the end of the pathname.

Parameters
patha utf-8 pathname
suffixa utf-8string
Returns
a utf-8 pathname
U8_EXPORT u8_string u8_dirname ( u8_string  path)

Returns the directory component of a pathname.

Parameters
patha utf-8 pathname
Returns
a utf-8 directory pathname

References u8_valid_copy().

Referenced by u8_abspath(), u8_mkdir(), u8_mkdirs(), and u8_readlink().

U8_EXPORT u8_string u8_getcwd ( void  )

Gets the current working directory.

Converts its result from the local encoding to utf-8

Returns
utf8_string

References u8_fromlibc(), and u8_graberr().

Referenced by u8_abspath(), and u8_readlink().

U8_EXPORT char* u8_localpath ( u8_string  path)

Returns an absolute local pathname from a utf-8 pathname.

This handles interpretation of relative pathnames and ~ prefixes as well as encoding conversion.

Parameters
patha utf8 string
Returns
a locally-encoded string

References u8_2libc(), and u8_abspath().

Referenced by u8_chmod(), u8_file_atime(), u8_file_ctime(), u8_file_existsp(), u8_file_mode(), u8_file_mtime(), u8_file_owner(), u8_file_readablep(), u8_file_size(), u8_file_writablep(), u8_fopen(), u8_fopen_locked(), u8_mkdir(), u8_movefile(), u8_open_fd(), u8_readlink(), u8_removefile(), u8_rmdir(), u8_set_mtime(), u8_setcwd(), and u8_subscribe().

U8_EXPORT u8_string u8_mkpath ( u8_string  dir,
u8_string  name 
)

Makes a pathname by combining a directory and a name component.

Parameters
dira utf-8 directory name
namea utf-8 filename
Returns
a utf-8 string

Referenced by u8_abspath(), and u8_rmdir().

U8_EXPORT u8_string u8_pathsuffix ( u8_string  path)

Returns the suffix component of a pathname.

Parameters
patha utf-8 pathname
Returns
a (copied) path suffix or NULL

References u8_abspath(), u8_fromlibc(), and u8_realpath().

u8_string u8_realpath ( u8_string  path,
u8_string  wd 
)

Returns an absolute pathname, resolving symbolic links.

Parameters
patha pathname
wda directory name
Returns
a utf-8 string

References u8_abspath().

Referenced by u8_pathsuffix().

U8_EXPORT int u8_setcwd ( u8_string  dirname)

Changes the current working directory.

Converts its argument into the local encoding and calls chdir() to make it the default directory.

Parameters
dirnamethe directory name in utf-8
Returns
-1 on error, 0 otherwise

References u8_fromlibc(), u8_graberr(), and u8_localpath().