MentOS  0.8.0
The Mentoring Operating System
Functions
libgen.c File Reference

String routines. More...

Functions

int dirname (const char *path, char *buffer, size_t buflen)
 Extracts the parent directory of the given path and saves it inside the given buffer, e.g., from "/home/user/test.txt" it extracts "/home/user". If the path does not contain a '/', it will return ".". More...
 
const char * basename (const char *path)
 Extract the component after the final '/'. More...
 
char * realpath (const char *path, char *buffer, size_t buflen)
 Return the canonicalized absolute pathname. More...
 

Detailed Description

String routines.

Function Documentation

◆ basename()

const char* basename ( const char *  path)

Extract the component after the final '/'.

Parameters
paththe path from which we extract the final component.
Returns
a pointer after the final '/', or path itself it none was found.

◆ dirname()

int dirname ( const char *  path,
char *  buffer,
size_t  buflen 
)

Extracts the parent directory of the given path and saves it inside the given buffer, e.g., from "/home/user/test.txt" it extracts "/home/user". If the path does not contain a '/', it will return ".".

Parameters
paththe path we are parsing.
bufferthe buffer where we save the directory name.
buflenthe length of the buffer.
Returns
1 if succesfull, or 0 if the buffer cannot contain the path.

◆ realpath()

char* realpath ( const char *  path,
char *  buffer,
size_t  buflen 
)

Return the canonicalized absolute pathname.

Parameters
paththe path we are canonicalizing.
bufferwhere we will store the canonicalized path.
buflenthe size of the buffer.
Returns
If there is no error, realpath() returns a pointer to the buffer. Otherwise, it returns NULL, the contents of the array buffer are undefined, and errno is set to indicate the error.