LMMS
Loading...
Searching...
No Matches
util.c File Reference
#include <ctype.h>
#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stddef.h>
#include <dirent.h>
#include <limits.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include "lilv_internal.h"

Classes

struct  Latest

Macros

#define _POSIX_C_SOURCE   200809L /* for fileno */
#define _BSD_SOURCE   1 /* for realpath, symlink */
#define _DEFAULT_SOURCE   1 /* for realpath, symlink */
#define PAGE_SIZE   4096

Functions

void lilv_free (void *ptr)
char * lilv_strjoin (const char *first,...)
char * lilv_strdup (const char *str)
const char * lilv_uri_to_path (const char *uri)
char * lilv_file_uri_parse (const char *uri, char **hostname)
char * lilv_get_lang (void)
static char * strappend (char *dst, size_t *dst_len, const char *suffix, size_t suffix_len)
static char * append_var (char *dst, size_t *dst_len, const char *var)
char * lilv_expand (const char *path)
static bool lilv_is_dir_sep (const char c)
char * lilv_dirname (const char *path)
bool lilv_path_exists (const char *path, void *ignored)
char * lilv_find_free_path (const char *in_path, bool(*exists)(const char *, void *), void *user_data)
int lilv_copy_file (const char *src, const char *dst)
bool lilv_path_is_absolute (const char *path)
 Return true iff path is an absolute path.
char * lilv_path_absolute (const char *path)
char * lilv_path_join (const char *a, const char *b)
 Join path a and path b with a single directory separator between them.
static void update_latest (const char *path, const char *name, void *data)
char * lilv_get_latest_copy (const char *path, const char *copy_path)
char * lilv_realpath (const char *path)
int lilv_symlink (const char *oldpath, const char *newpath)
char * lilv_path_relative_to (const char *path, const char *base)
bool lilv_path_is_child (const char *path, const char *dir)
 Return true iff path is a child of dir.
int lilv_flock (FILE *file, bool lock)
void lilv_dir_for_each (const char *path, void *data, void(*f)(const char *path, const char *name, void *data))
int lilv_mkdir_p (const char *dir_path)
static off_t lilv_file_size (const char *path)
bool lilv_file_equals (const char *a_path, const char *b_path)
 Return true iff the given paths point to files with identical contents.

Macro Definition Documentation

◆ _BSD_SOURCE

#define _BSD_SOURCE   1 /* for realpath, symlink */

◆ _DEFAULT_SOURCE

#define _DEFAULT_SOURCE   1 /* for realpath, symlink */

◆ _POSIX_C_SOURCE

#define _POSIX_C_SOURCE   200809L /* for fileno */

◆ PAGE_SIZE

#define PAGE_SIZE   4096

Function Documentation

◆ append_var()

char * append_var ( char * dst,
size_t * dst_len,
const char * var )
static

Append the value of the environment variable var to dst.

◆ lilv_copy_file()

int lilv_copy_file ( const char * src,
const char * dst )

Copy the file at path src to path dst.

Returns
Zero on success, or a standard errno error code.

◆ lilv_dir_for_each()

void lilv_dir_for_each ( const char * path,
void * data,
void(* )(const char *path, const char *name, void *data) )

Visit every file in the directory at path.

Parameters
pathA path to a directory.
dataOpaque user data that is passed to f.
fA function called on every entry in the directory. The path parameter is always the directory path passed to this function, the name parameter is the name of the directory entry (not its full path).

◆ lilv_dirname()

char * lilv_dirname ( const char * path)

◆ lilv_expand()

char * lilv_expand ( const char * path)

Expand variables (e.g. POSIX ~ or $FOO, Windows FOO%) in path.

◆ lilv_file_equals()

bool lilv_file_equals ( const char * a_path,
const char * b_path )

Return true iff the given paths point to files with identical contents.

◆ lilv_file_size()

off_t lilv_file_size ( const char * path)
static

◆ lilv_find_free_path()

char * lilv_find_free_path ( const char * in_path,
bool(* exists )(const char *, void *),
void * user_data )

◆ lilv_flock()

int lilv_flock ( FILE * file,
bool lock )

◆ lilv_get_lang()

char * lilv_get_lang ( void )

Return the current LANG converted to Turtle (i.e. RFC3066) style. For example, if LANG is set to "en_CA.utf-8", this returns "en-ca".

◆ lilv_get_latest_copy()

char * lilv_get_latest_copy ( const char * path,
const char * copy_path )

Return the latest copy of the file at path that is newer.

◆ lilv_is_dir_sep()

bool lilv_is_dir_sep ( const char c)
static

◆ lilv_mkdir_p()

int lilv_mkdir_p ( const char * dir_path)

◆ lilv_path_absolute()

char * lilv_path_absolute ( const char * path)

Return path as an absolute path.

If path is absolute, an identical copy of it is returned. Otherwise, the returned path is relative to the current working directory.

◆ lilv_path_exists()

bool lilv_path_exists ( const char * path,
void * ignored )

◆ lilv_path_is_absolute()

bool lilv_path_is_absolute ( const char * path)

Return true iff path is an absolute path.

◆ lilv_path_is_child()

bool lilv_path_is_child ( const char * path,
const char * dir )

Return true iff path is a child of dir.

◆ lilv_path_join()

char * lilv_path_join ( const char * a,
const char * b )

Join path a and path b with a single directory separator between them.

◆ lilv_path_relative_to()

char * lilv_path_relative_to ( const char * path,
const char * base )

Return path relative to base if possible.

If path is not within base, a copy is returned. Otherwise, an equivalent path relative to base is returned (which may contain up-references).

◆ lilv_realpath()

char * lilv_realpath ( const char * path)

◆ lilv_strdup()

char * lilv_strdup ( const char * str)

◆ lilv_strjoin()

char * lilv_strjoin ( const char * first,
... )

◆ lilv_symlink()

int lilv_symlink ( const char * oldpath,
const char * newpath )

Create a symlink at newpath that points to oldpath.

Returns
Zero on success, otherwise non-zero and errno is set.

◆ strappend()

char * strappend ( char * dst,
size_t * dst_len,
const char * suffix,
size_t suffix_len )
static

Append suffix to dst, update dst_len, and return the realloc'd result.

◆ update_latest()

void update_latest ( const char * path,
const char * name,
void * data )
static