File functions for sds strings.
More...
#include "dist/sds/sds.h"
#include <stdbool.h>
#include <stdio.h>
Go to the source code of this file.
|
| enum | getfile_status { FILE_IS_EMPTY = 0
, FILE_NOT_EXISTS = -1
, FILE_TO_BIG = -2
, FILE_ERROR = -3
} |
|
| sds | sds_getline (sds s, FILE *fp, size_t max, int *nread) |
| sds | sds_getfile (sds s, const char *file_path, size_t max, bool remove_newline, bool warn, int *nread) |
| sds | sds_getfile_from_fp (sds s, FILE *fp, size_t max, bool remove_newline, int *nread) |
| sds | sds_basename (sds s) |
| sds | sds_dirname (sds s) |
| void | sds_basename_uri (sds uri) |
| void | sds_strip_file_extension (sds filename) |
| sds | sds_replace_file_extension (sds filename, const char *ext) |
| void | sds_strip_slash (sds dirname) |
| void | sds_sanitize_filename (sds filename) |
| void | sds_sanitize_filename2 (sds filename) |
File functions for sds strings.
◆ getfile_status
Status of sds_getfile functions
◆ sds_basename()
| sds sds_basename |
( |
sds | s | ) |
|
Replacement for basename function. Modifies the sds string in place.
- Parameters
-
| s | sds string to apply basename function |
- Returns
- new pointer to s
◆ sds_basename_uri()
| void sds_basename_uri |
( |
sds | uri | ) |
|
Calculates the basename for files and uris
- for files the path is removed
- for uris the query string and hash is removed
- Parameters
-
| uri | sds string to modify in place |
◆ sds_dirname()
Replacement for dirname function. Modifies the sds string in place.
- Parameters
-
| s | sds string to apply dirname function |
- Returns
- new pointer to s
◆ sds_getfile()
| sds sds_getfile |
( |
sds | s, |
|
|
const char * | file_path, |
|
|
size_t | max, |
|
|
bool | remove_newline, |
|
|
bool | warn, |
|
|
int * | nread ) |
Reads a whole file in the sds string s from *fp Removes whitespace characters from start and end
- Parameters
-
| s | an already allocated sds string that should hold the file content |
| file_path | filename to read |
| max | maximum bytes to read |
| remove_newline | removes CR/LF if true |
| warn | log an error if file does not exist |
| nread | Number of bytes read, -1 error reading file, -2 file is too big |
- Returns
- pointer to s
◆ sds_getfile_from_fp()
| sds sds_getfile_from_fp |
( |
sds | s, |
|
|
FILE * | fp, |
|
|
size_t | max, |
|
|
bool | remove_newline, |
|
|
int * | nread ) |
Reads a whole file in the sds string s from *fp Removes whitespace characters from start and end
- Parameters
-
| s | an already allocated sds string that should hold the file content |
| fp | FILE pointer to read |
| max | maximum bytes to read |
| remove_newline | removes CR/LF if true |
| nread | Number of bytes read, -2 if file is too big |
- Returns
- pointer to s
◆ sds_getline()
| sds sds_getline |
( |
sds | s, |
|
|
FILE * | fp, |
|
|
size_t | max, |
|
|
int * | nread ) |
Getline function that trims whitespace characters
- Parameters
-
| s | an already allocated sds string |
| fp | a file descriptor to read from |
| max | max line length to read |
| nread | Number of bytes read, -1 on EOF |
- Returns
- Pointer to s
◆ sds_replace_file_extension()
| sds sds_replace_file_extension |
( |
sds | filename, |
|
|
const char * | ext ) |
Replaces the file extension
- Parameters
-
| filename | sds string to replace the extension |
| ext | new file extension |
- Returns
- newly allocated sds string with new file extension
◆ sds_sanitize_filename()
| void sds_sanitize_filename |
( |
sds | filename | ) |
|
Replaces invalid and uncommon filename characters with "_"
- Parameters
-
| filename | sds string to sanitize |
◆ sds_sanitize_filename2()
| void sds_sanitize_filename2 |
( |
sds | filename | ) |
|
Replaces invalid filename characters with "_", same chars as vcb_isfilename
- Parameters
-
| filename | sds string to sanitize |
◆ sds_strip_file_extension()
| void sds_strip_file_extension |
( |
sds | filename | ) |
|
Removes the file extension
- Parameters
-
| filename | sds string to remove the extension |
◆ sds_strip_slash()
| void sds_strip_slash |
( |
sds | dirname | ) |
|
Strips all slashes from the end
- Parameters
-
| dirname | sds string to strip |