JWS C Library
C language utility library
fname.c File Reference

Declarations for manipulating file and directory names. More...

#include <jwsc/config.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <inttypes.h>
#include "jwsc/base/fname.h"
Include dependency graph for fname.c:

Go to the source code of this file.

Functions

static const char * last_occurrence (const char *fname, char c)
 find the last occurrence of c in fname.
int fname_has_suffix (const char *fname, const char *suffix)
 Returns whether a file name has a certain suffix.
char * get_fname_suffix (const char *fname)
 Returns a copy of the file name suffix, if it has one.
char * get_fname_dir (const char *fname)
 Returns a copy of the file name directory prefix.
char * get_fname_base (const char *fname)

Detailed Description

Declarations for manipulating file and directory names.

Author:
Joseph Schlecht
License:
Creative Commons BY-NC-SA 3.0

Definition in file fname.c.


Function Documentation

static const char* last_occurrence ( const char *  fname,
char  c 
) [static]

find the last occurrence of c in fname.

Assumes fname is string properly terminated with 0.

Definition at line 65 of file fname.c.

int fname_has_suffix ( const char *  fname,
const char *  suffix 
)

Returns whether a file name has a certain suffix.

Parameters:
fnameThe file name.
suffixSuffix to look for.
Returns:
Whether the file name contains the suffix.
If the file name contains the suffix 1; otherwise 0.

Definition at line 96 of file fname.c.

char* get_fname_suffix ( const char *  fname)

Returns a copy of the file name suffix, if it has one.

Suffix is everything after the last '.' in the file name.

Parameters:
fnameFile name to get the suffix of.
Returns:
If the file has no '.' suffix, 0 is returned; otherwise a copy of the suffix is returned.

Definition at line 120 of file fname.c.

char* get_fname_dir ( const char *  fname)

Returns a copy of the file name directory prefix.

Directory is everything before the last '/' in the file name.

Parameters:
fnameFile name to get the directory of.
Returns:
If the file has no directory, '.' is returned; otherwise a copy of the directory is returned.

Definition at line 147 of file fname.c.

char* get_fname_base ( const char *  fname)

Base name is everything after the last '/' in the file name.

Parameters:
fnameFile name to get the base of.
Returns:
A copy of the file base name.

Definition at line 194 of file fname.c.