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

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.