ZEDA  1.6.18
Macros | Functions
pathname operations.

Macros

#define ZEDA_ZTK_SUFFIX   "ztk"
 default suffix of .ztk (Z-Tag-and-Key) file format. More...
 
#define zOpenZTKFile(filename, mode)   zOpenFile( filename, ZEDA_ZTK_SUFFIX, mode )
 open a .ztk file. More...
 

Functions

char * zGetBasename (char *path, char *name, size_t size)
 strip a directory from a filename. More...
 
char * zGetBasenameDRC (char *name)
 
int zGetDirFilename (char *path, char *dirname, char *filename, size_t size)
 get a directory name and a file name from a path. More...
 
char * zGetSuffix (char *name)
 get a suffix from a filename. More...
 
char * zAddSuffix (char *org, char *suffix, char *dest, size_t size)
 add a suffix to a filename. More...
 
char * zReplaceSuffix (char *org, char *suffix, char *dest, size_t size)
 replace the suffix of a filename to a specified one. More...
 
char * zCutSuffix (char *name)
 cut a suffix from a filename More...
 
FILE * zOpenFile (char filename[], char *suffix, char *mode)
 open a file with default suffix. More...
 

Detailed Description

Macro Definition Documentation

◆ ZEDA_ZTK_SUFFIX

#define ZEDA_ZTK_SUFFIX   "ztk"

default suffix of .ztk (Z-Tag-and-Key) file format.

◆ zOpenZTKFile

#define zOpenZTKFile (   filename,
  mode 
)    zOpenFile( filename, ZEDA_ZTK_SUFFIX, mode )

open a .ztk file.

Function Documentation

◆ zGetBasename()

char* zGetBasename ( char *  path,
char *  name,
size_t  size 
)

strip a directory from a filename.

zGetBasename() acquires a filename from a path string path with any leading directory names removed, and puts it where name points. ex. if path is "/home/user/dummy.suf", name will be "dummy.suf".

zGetBasenameDRC() overrides a given string name by the stripped string.

Returns
zGetBasename() and zGetBasenameDRC() return a pointer name.
Note
Both '/' and '\' are accepted as delimiters of the path name.

◆ zGetBasenameDRC()

char* zGetBasenameDRC ( char *  name)

◆ zGetDirFilename()

int zGetDirFilename ( char *  path,
char *  dirname,
char *  filename,
size_t  size 
)

get a directory name and a file name from a path.

zGetDirFilename() acquires a directory name and a file name from a path path, and puts them into dirname and filename, respectively. More than or equal to size bytes have to be allocated for all path, dirname and filename.

Returns
zGetDirFilename() returns an integer value from 0 to 3. If filename is non-empty, the least bit of the value turns 1. If dirname is non-empty, the second least bit of the value turns 1. Otherwise, the corresponding bit turns 0.

◆ zGetSuffix()

char* zGetSuffix ( char *  name)

get a suffix from a filename.

zGetSuffix() finds a suffix from a filename name. The string pointed by name is not modified.

Returns
a pointer to the head of suffix is returned. ex. if name is "xxx.yyy.zzz", then the address of the first "z" is returned.

◆ zAddSuffix()

char* zAddSuffix ( char *  org,
char *  suffix,
char *  dest,
size_t  size 
)

add a suffix to a filename.

zAddSuffix() concatenates '.' + a string suffix to the original filename org, if necessary. The resultant pathname is put where dest points. If org already has the same suffix with suffix, org is simply copied to dest. size is the size of the destination buffer.

Returns
a pointer dest is returned.
Note
dest must have enough size for org, '.' and the additional suffix.

◆ zReplaceSuffix()

char* zReplaceSuffix ( char *  org,
char *  suffix,
char *  dest,
size_t  size 
)

replace the suffix of a filename to a specified one.

zReplaceSuffix() replaces the suffix of a string org, which is supposed to be a name of file with '.' + a string suffix. The resulted pathname is put where dest points. If org does not have a suffix, it simply concatenates suffix to org. size is the size of the destination buffer.

Returns
a pointer dest is returned.
Note
dest must have enough size for the suffix-exempt org, '.' and suffix.

◆ zCutSuffix()

char* zCutSuffix ( char *  name)

cut a suffix from a filename

zCutSuffix() directly cuts a suffix from a filename name. If name doesn't have a suffix, nothing happens.

Returns
a pointer to the cut suffix in the original name. ex. if name is "xxx.yyy.zzz", then name will be modified to "xxx.yyy", and a pointer to the first "z" is returned.

◆ zOpenFile()

FILE* zOpenFile ( char  filename[],
char *  suffix,
char *  mode 
)

open a file with default suffix.

zOpenFile() opens a file named filename. mode is an access mode to the file. The definition is the same with that for fopen() in ANSI-C. If it fails to open filename and suffix is not the null pointer, it tries to open file named 'filename '.'suffix '.

Returns
zOpenFile() returns a pointer to the opened file if succeeds. Otherwise, the null pointer is returned.