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

File functions for sds strings. More...

#include "dist/sds/sds.h"
#include <stdbool.h>
#include <stdio.h>
Include dependency graph for sds_file.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Enumerations

enum  getfile_status { FILE_IS_EMPTY = 0 , FILE_NOT_EXISTS = -1 , FILE_TO_BIG = -2 , FILE_ERROR = -3 }

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_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)

Detailed Description

File functions for sds strings.

Enumeration Type Documentation

◆ getfile_status

Status of sds_getfile functions

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