libqaeda

Unnamed repository; edit this file 'description' to name the repository.
Info | Log | Files | Refs | README | LICENSE

cwk_path_get_basename.md (1928B)


      1 ---
      2 title: cwk_path_get_basename
      3 description: Gets the basename of a file path.
      4 ---
      5 
      6 _(since v1.0.0)_  
      7 Gets the basename of a file path.
      8 
      9 ## Description
     10 ```c
     11 void cwk_path_get_basename(const char *path, const char **basename,
     12   size_t *length);
     13 ```
     14 
     15 This function gets the basename of a file path. The basename is the last segment of a path. For instance, ``logs`` is the basename of the path ``/var/logs``. A pointer to the beginning of the basename will be returned through the basename parameter. This pointer will be positioned on the first letter after the separator. The length of the file path will be returned through the length parameter. The length will be set to zero and the basename to NULL if there is no basename available.
     16 
     17 ## Parameters
     18  * **path**: The path which will be inspected.
     19  * **basename**: The output of the basename pointer.
     20  * **length**: The output of the length of the basename.
     21 
     22 ## Outcomes
     23 
     24 | Path                 | Basename      |
     25 |----------------------|---------------|
     26 | ``/my/path.txt``     | ``path.txt``  |
     27 | ``/my/path.txt/``    | ``path.txt``  |
     28 | ``/my/path.txt////`` | ``path.txt``  |
     29 | ``file_name``        | ``file_name`` |
     30 | ``..``               | ``..``        |
     31 | ``.``                | ``.``         |
     32 | ``/``                | `` ``         |
     33 | ``C:\path\test.txt`` | ``test.txt``  |
     34 
     35 ## Example
     36 ```c
     37 #include <cwalk.h>
     38 #include <stdio.h>
     39 #include <stddef.h>
     40 #include <stdlib.h>
     41 
     42 int main(int argc, char *argv[])
     43 {
     44   const char *basename;
     45   size_t length;
     46 
     47   cwk_path_get_basename("/my/path.txt", &basename, &length);
     48   printf("The basename is: '%.*s'", length, basename);
     49 
     50   return EXIT_SUCCESS;
     51 }
     52 ```
     53 Ouput:
     54 ```
     55 The basename is: 'path.txt'
     56 ```
     57 
     58 ## Changelog
     59 
     60 | Version    | Description                                            |
     61 |------------|--------------------------------------------------------|
     62 | **v1.0.0** | The function is introduced.                            |