myMPD
Internal API documentation
Loading...
Searching...
No Matches
sds_file.c File Reference

File functions for sds strings. More...

#include "compile_time.h"
#include "src/lib/sds/sds_file.h"
#include "dist/sds/sds.h"
#include "src/lib/log.h"
#include "src/lib/sds/sds_extras.h"
#include <assert.h>
#include <errno.h>
#include <string.h>
Include dependency graph for sds_file.c:

Functions

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_slash (sds dirname)
void sds_strip_file_extension (sds filename)
sds sds_replace_file_extension (sds filename, const char *ext)
void sds_sanitize_filename (sds filename)
void sds_sanitize_filename2 (sds filename)

Variables

static const char * invalid_filename_chars = "<>/.:?&$%!#=;\a\b\f\n\r\t\v\\|"
static const char * invalid_filename_chars2 = "\a\b\f\n\r\t\v/\\"

Detailed Description

File functions for sds strings.

Function Documentation

◆ sds_basename()

sds sds_basename ( sds s)

Replacement for basename function. Modifies the sds string in place.

Parameters
ssds 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
    urisds string to modify in place

◆ sds_dirname()

sds sds_dirname ( sds s)

Replacement for dirname function. Modifies the sds string in place.

Parameters
ssds 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
san already allocated sds string that should hold the file content
file_pathfilename to read
maxmaximum bytes to read
remove_newlineremoves CR/LF if true
warnlog an error if file does not exist
nreadNumber 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
san already allocated sds string that should hold the file content
fpFILE pointer to read
maxmaximum bytes to read
remove_newlineremoves CR/LF if true
nreadNumber 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
san already allocated sds string
fpa file descriptor to read from
maxmax line length to read
nreadNumber 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
filenamesds string to replace the extension
extnew 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
filenamesds string to sanitize

◆ sds_sanitize_filename2()

void sds_sanitize_filename2 ( sds filename)

Replaces invalid filename characters with "_", same chars as vcb_isfilename

Parameters
filenamesds string to sanitize

◆ sds_strip_file_extension()

void sds_strip_file_extension ( sds filename)

Removes the file extension

Parameters
filenamesds string to remove the extension

◆ sds_strip_slash()

void sds_strip_slash ( sds dirname)

Strips all slashes from the end

Parameters
dirnamesds string to strip

Variable Documentation

◆ invalid_filename_chars

const char* invalid_filename_chars = "<>/.:?&$%!#=;\a\b\f\n\r\t\v\\|"
static

Invalid and uncommon characters for filenames.

◆ invalid_filename_chars2

const char* invalid_filename_chars2 = "\a\b\f\n\r\t\v/\\"
static

Invalid characters for filenames.