path.c File Reference

Manipulate strings that contain filesystem paths. More...

#include "lib/fs/path.h"
#include "lib/malloc/malloc.h"
#include "lib/log/log.h"
#include "lib/log/util_bug.h"
#include "lib/string/printf.h"
#include "lib/string/util_string.h"
#include "lib/string/compat_ctype.h"
#include "lib/fs/userdb.h"
#include <errno.h>
#include <string.h>

Go to the source code of this file.


char * get_unquoted_path (const char *path)
char * expand_filename (const char *filename)
int path_is_relative (const char *filename)
void clean_fname_for_stat (char *name)
int get_parent_directory (char *fname)
static char * alloc_getcwd (void)
char * make_path_absolute (const char *fname)

Detailed Description

Manipulate strings that contain filesystem paths.

Definition in file path.c.

Function Documentation

◆ alloc_getcwd()

static char* alloc_getcwd ( void  )

Return a newly allocated string containing the output of getcwd(). Return NULL on failure. (We can't just use getcwd() into a PATH_MAX buffer, since Hurd hasn't got a PATH_MAX.)

Definition at line 224 of file path.c.

◆ clean_fname_for_stat()

void clean_fname_for_stat ( char *  name)

Clean up name so that we can use it in a call to "stat". On Unix, we do nothing. On Windows, we remove a trailing slash, unless the path is the root of a disk.

Definition at line 145 of file path.c.

◆ expand_filename()

char* expand_filename ( const char *  filename)

Expand any homedir prefix on filename; return a newly allocated string.

Definition at line 66 of file path.c.

◆ get_parent_directory()

int get_parent_directory ( char *  fname)

Modify fname to contain the name of its parent directory. Doesn't actually examine the filesystem; does a purely syntactic modification.

The parent of the root director is considered to be iteself.

Path separators are the forward slash (/) everywhere and additionally the backslash () on Win32.

Cuts off any number of trailing path separators but otherwise ignores them for purposes of finding the parent directory.

Returns 0 if a parent directory was successfully found, -1 otherwise (fname did not have any path separators or only had them at the end).

Definition at line 176 of file path.c.

◆ get_unquoted_path()

char* get_unquoted_path ( const char *  path)

Removes enclosing quotes from path and unescapes quotes between the enclosing quotes. Backslashes are not unescaped. Return the unquoted path on success or 0 if path is not quoted correctly.

Definition at line 32 of file path.c.

◆ make_path_absolute()

char* make_path_absolute ( const char *  fname)

Expand possibly relative path fname to an absolute path. Return a newly allocated string, which may be a duplicate of fname.

Definition at line 261 of file path.c.

Referenced by get_esc_cfile(), and warn_if_option_path_is_relative().

◆ path_is_relative()

int path_is_relative ( const char *  filename)

Return true iff filename is a relative path.

Definition at line 126 of file path.c.

Referenced by warn_if_option_path_is_relative().