YAZ  5.34.0
Functions
tpath.h File Reference

File Path utilities. More...

#include <yaz/yconfig.h>
#include <stdio.h>

Go to the source code of this file.

Functions

int yaz_is_abspath (const char *path)
 checks whether path is absolute More...
 
size_t yaz_filepath_comp (const char **path_p, const char **comp)
 get next path component in filepath More...
 
char * yaz_filepath_resolve (const char *fname, const char *path, const char *base, char *fullpath)
 resolve file on path More...
 
FILE * yaz_fopen (const char *path, const char *fname, const char *mode, const char *base)
 opens first file in path in path More...
 
FILE * yaz_path_fopen (const char *path, const char *fname, const char *mode)
 opens first file in path in path More...
 
int yaz_fclose (FILE *f)
 closes file More...
 

Detailed Description

File Path utilities.

Definition in file tpath.h.

Function Documentation

◆ yaz_fclose()

int yaz_fclose ( FILE *  f)

closes file

Parameters
fFILE handle
Return values
-1on failure
0on success

Definition at line 38 of file tpath.c.

◆ yaz_filepath_comp()

size_t yaz_filepath_comp ( const char **  path_p,
const char **  comp 
)

get next path component in filepath

Parameters
path_ppointer to path (updated to "next" entry if any)
compupon pointer to component (if component is found)
Return values
0no component found (and no more componennts)
>0length of component (length of *comp)

A filepath has components separted by colon. For example /usr/lib/modules:c:/my:/:lib which has these components "/usr/lib/modules", "c:/my", "/", "lib"

Definition at line 44 of file tpath.c.

Referenced by yaz_filepath_resolve().

◆ yaz_filepath_resolve()

char* yaz_filepath_resolve ( const char *  fname,
const char *  path,
const char *  base,
char *  fullpath 
)

resolve file on path

Parameters
fname"short" filename (without path)
paththe path (dir1:dir2,..) - ala Unix
basecan be added to relative paths (NULL for no append)
fullpaththe full path to filename (if successful)
Returns
fullpath or NULL if file could not be found

Be sure to allocate at least 1024 bytes for fullpath

Definition at line 74 of file tpath.c.

References yaz_filepath_comp().

Referenced by xml_config_read(), and yaz_fopen().

◆ yaz_fopen()

FILE* yaz_fopen ( const char *  path,
const char *  fname,
const char *  mode,
const char *  base 
)

opens first file in path in path

Parameters
fname"short" filename (without path)
modemode as in fopen(3)
paththe path (dir1:dir2,..) - ala Unix
basecan be added to relative paths (NULL for no append)
Returns
FILE pointer if fname could be found; NULL otherwise

Definition at line 117 of file tpath.c.

References yaz_filepath_resolve().

Referenced by yaz_path_fopen().

◆ yaz_is_abspath()

int yaz_is_abspath ( const char *  path)

checks whether path is absolute

Parameters
pathpath to checked
Return values
1path is absolute
0path is relative

Definition at line 127 of file tpath.c.

Referenced by conf_dir_path().

◆ yaz_path_fopen()

FILE* yaz_path_fopen ( const char *  path,
const char *  fname,
const char *  mode 
)

opens first file in path in path

Parameters
fname"short" filename (without path)
modemode as in fopen(3)
paththe path (dir1:dir2,..) - ala Unix
Returns
FILE pointer if fname could be found; NULL otherwise

Definition at line 33 of file tpath.c.

References name, and yaz_fopen().