coan 4.2.4
The Filesystem component interface.
Collaboration diagram for The Filesystem component interface.:

Files

file  filesys.h

Defines

#define fs_absolute_path(pathtype)   (((pathtype) & FS_ABS_PATH) == FS_ABS_PATH)
#define fs_unix_path(pathtype)   (((pathtype) & FS_UNIX_PATH) == FS_UNIX_PATH)
#define fs_windows_path(pathtype)   (((pathtype) & FS_WIN_PATH) == FS_WIN_PATH)
#define fs_dangling_path(pathtype)   (((pathtype) & FS_DANGLING_PATH) == FS_DANGLING_PATH)
#define fs_root_path(pathtype)   (((pathtype) & FS_ROOT_PATH) == FS_ROOT_PATH)
#define FS_IS_FILE(objtype)   (((objtype) & FS_OBJ_FILE) != 0)
#define FS_IS_DIR(objtype)   (((objtype) & FS_OBJ_DIR) != 0)
#define FS_IS_SLINK(objtype)   (((objtype) & FS_OBJ_SLINK) != 0)

Typedefs

typedef void * fs_dir_t

Enumerations

enum  fs_obj_type_t { FS_OBJ_NONE, FS_OBJ_SLINK = 1, FS_OBJ_FILE = 2, FS_OBJ_DIR = 4 }
enum  fs_path_type_t {
  FS_ABS_PATH = 1, FS_UNIX_PATH = 2, FS_WIN_PATH = 6, FS_DANGLING_PATH = 8,
  FS_ROOT_PATH = 16
}

Functions

fs_obj_type_t fs_obj_type (char const *name)
fs_obj_type_t fs_file_or_dir (char const *name)
fs_dir_t fs_open_dir (char const *dirname, fs_dir_t const parent)
void fs_close_dir (fs_dir_t dir)
char const * fs_read_dir (fs_dir_t dir, char const **fullname)
fs_dir_t fs_get_parent (fs_dir_t dir)
heap_str fs_compose_filename (char const *path, char const *leafname)
heap_str fs_split_filename (char const *path, char **leafname)
heap_str fs_real_path (char const *relname, size_t *namelen)
char const * fs_cur_dir_entry (fs_dir_t dir, char const **entry)
fs_path_type_t fs_path_type (char const *filename)
char * fs_tempname (char *template)
char const * fs_path_comp (char const *first, char const *second, size_t *sharedlen)

Define Documentation

#define fs_absolute_path (   pathtype)    (((pathtype) & FS_ABS_PATH) == FS_ABS_PATH)

The path type pathtype denotes an absolute path.

Definition at line 78 of file filesys.h.

Referenced by seek().

#define fs_dangling_path (   pathtype)    (((pathtype) & FS_DANGLING_PATH) == FS_DANGLING_PATH)

The path type pathtype denotes a dangling path (with trailing path delimiter)

Definition at line 97 of file filesys.h.

#define FS_IS_DIR (   objtype)    (((objtype) & FS_OBJ_DIR) != 0)

The object type objtype indicates a directory

Definition at line 116 of file filesys.h.

Referenced by add_files().

#define FS_IS_FILE (   objtype)    (((objtype) & FS_OBJ_FILE) != 0)

The object type objtype indicates a file

Definition at line 111 of file filesys.h.

Referenced by add_files(), and fs_split_filename().

#define FS_IS_SLINK (   objtype)    (((objtype) & FS_OBJ_SLINK) != 0)

The object type objtype indicates a symbolic link

Definition at line 121 of file filesys.h.

Referenced by add_files(), file_tree_add(), file_tree_add_canon(), and new_dir_node().

#define fs_root_path (   pathtype)    (((pathtype) & FS_ROOT_PATH) == FS_ROOT_PATH)

The path type pathtype denotes a root path of the filesystem ("/" for unix, drive paths for windows.

Definition at line 105 of file filesys.h.

#define fs_unix_path (   pathtype)    (((pathtype) & FS_UNIX_PATH) == FS_UNIX_PATH)

The path type pathtype denotes a unix path.

Definition at line 84 of file filesys.h.

#define fs_windows_path (   pathtype)    (((pathtype) & FS_WIN_PATH) == FS_WIN_PATH)

The path type pathtype denotes a windows path.

Definition at line 90 of file filesys.h.

Referenced by seek().


Typedef Documentation

typedef void* fs_dir_t

Abstract type of directory handle

Definition at line 55 of file filesys.h.


Enumeration Type Documentation

Enumerated type of filesystem objects

Enumerator:
FS_OBJ_NONE 

No such object

FS_OBJ_SLINK 

Object is a symbolic link

FS_OBJ_FILE 

Object is a file

FS_OBJ_DIR 

Object is a directory

Definition at line 59 of file filesys.h.

Enumerated attributes of pathnames as returned by fs_path_type()

Enumerator:
FS_ABS_PATH 

Absolute path

FS_UNIX_PATH 

Unix path

FS_WIN_PATH 

Windows path

FS_DANGLING_PATH 

Path has trailing PATH_DELIM

FS_ROOT_PATH 

Path represents files system root

Definition at line 67 of file filesys.h.


Function Documentation

void fs_close_dir ( fs_dir_t  dir)

Close an abstract directory handle, releasing its resources.

Definition at line 133 of file fs_nix.c.

References fs_dir_nix::dir, fs_dir_win::dirname, fs_dir_nix::dirname, and fs_dir_win::handle.

Referenced by file_tree_add_canon(), and new_dir_node().

heap_str fs_compose_filename ( char const *  path,
char const *  leafname 
)

Compose a filename from a path and a leafname. If either path or leafname is quoted or contains spaces then the resulting filename is quoted.

Returns:
The composed filename in a string allocated on the heap. It is the caller's responsiblity to free this string.

Definition at line 50 of file filesys.c.

References PATH_DELIM, and zallocate().

Referenced by file_tree_name().

Here is the call graph for this function:

char const* fs_cur_dir_entry ( fs_dir_t  dir,
char const **  entry 
)

Return the absolute pathname of the current entry from a directory handle.

Parameters:
dirDirectory handle
entryNULL, or an address at which the function shall store a pointer to the terminal portion of the current full pathname that follows the full pathname of dir.
Returns:
Pointer to the absolute pathname of the current entry in dir.

The current entry in dir is the entry read by the last call to fs_read_dir(dir), if any. If fs_read_dir(dir) has not yet been called, or if the last call returned NULL, then the returned pointer addresses the absolute name of dir and, if leafname is not NULL, then *leafname[0] will be 0.

Otherwise, if leafname is not NULL then *leafname will point to the last component of the current absolute pathname commencing with '/' (unix) or '\' (windows)

Definition at line 181 of file fs_nix.c.

References fs_dir_win::dirname, fs_dir_nix::dirname, fs_dir_win::dirname_end, and fs_dir_nix::dirname_end.

Referenced by file_tree_add_symlink(), and new_dir_node().

fs_obj_type_t fs_file_or_dir ( char const *  name)

Return the type of the putative file or directory designated by a filename. Bail if neither file nor directory.

Definition at line 64 of file filesys.c.

References bail(), FS_OBJ_NONE, fs_obj_type(), and GRIPE_NO_FILE.

Referenced by file_tree_add(), and fs_split_filename().

Here is the call graph for this function:

fs_dir_t fs_get_parent ( fs_dir_t  dir)

Return the handle of the open parent directory of a directory, if any, else NULL.

Definition at line 192 of file fs_nix.c.

References fs_dir_win::parent, and fs_dir_nix::parent.

Referenced by file_tree_add_symlink().

fs_obj_type_t fs_obj_type ( char const *  name)

Return the type of the object putatively designated by a filename

Definition at line 91 of file fs_nix.c.

References FS_OBJ_DIR, FS_OBJ_FILE, FS_OBJ_NONE, FS_OBJ_SLINK, and fs_dir_win::obj_info.

Referenced by add_files(), file_tree_add_canon(), fs_file_or_dir(), fs_tempname(), and new_dir_node().

fs_dir_t fs_open_dir ( char const *  dirname,
fs_dir_t const  parent 
)

Open an abstract directory handle through which the contents of a directory can be traversed.

Parameters:
dirnameThe name of the directory to be opened.
parentThe handle of the open directory of dirname is a subdirectory, or NULL if none.
Returns:
A handle to dirname, or NULL if an error occurs, which will be indicated by errno.

Definition at line 113 of file fs_nix.c.

References fs_dir_nix::dir, fs_dir_win::dirname, fs_dir_nix::dirname, fs_dir_win::dirname_end, fs_dir_nix::dirname_end, fs_real_path(), fs_dir_win::handle, HANDLE, fs_dir_win::obj_info, fs_dir_win::parent, fs_dir_nix::parent, PATH_DELIM, reallocate(), and zallocate().

Referenced by file_tree_add_canon(), and new_dir_node().

Here is the call graph for this function:

char const* fs_path_comp ( char const *  first,
char const *  second,
size_t *  sharedlen 
)

Compare two pathnames.

Parameters:
firstThe first pathname.
secondThe second pathname.
sharedlenAddress of an integer at which the function shall store the length of any common initial component of first and second unless they are identical pathnames, in which case 0 shall be stored at sharedlen.
Returns:
Pointer to the common initial component of first and second, or NULL if there is none.

If the returned value cp is non-NULL then it is equal to either first or to second. Then:

  • If *sharedlen != 0 and cp[*sharedlen] == 0, then returned pathname is entirely an intitial component of the other pathname.
  • If *sharedlen != 0 and cp[*sharedlen] != 0 then the *sharedlen bytes at cp comprise the common initial component of first and second.
  • If *sharedlen == 0 then first and second are identical pathnames.

If the returned value is NULL then first and second are wholly disjoint pathnames.

Definition at line 129 of file filesys.c.

References PATH_DELIM.

Referenced by file_tree_add_symlink().

fs_path_type_t fs_path_type ( char const *  filename)

Get the type of a pathname

Definition at line 95 of file filesys.c.

References FS_ABS_PATH, FS_DANGLING_PATH, FS_ROOT_PATH, FS_UNIX_PATH, and FS_WIN_PATH.

Referenced by seek().

char const* fs_read_dir ( fs_dir_t  dir,
char const **  fullname 
)

Get the name of the next entry in a directory.

Parameters:
dirThe open directory handle to read.
fullnameNULL, or a pointer at which the function will store the address of the absolute name of the entry returned. This pointer is only valid until the next call or until fs_close_dir(dir)
Returns:
A pointer to the next entry in the directory, if any; otherwise NULL. The pointer is only valid until the next call or until fs_close_dir(dir)

The function ignores the entries '.' and '..'.

Definition at line 145 of file fs_nix.c.

References bail(), fs_dir_nix::dir, fs_dir_win::dirname, fs_dir_nix::dirname, fs_dir_win::dirname_end, fs_dir_nix::dirname_end, fs_dir_nix::entry, fs_read_dir(), GRIPE_CANT_READ_DIR, fs_dir_win::handle, fs_dir_win::obj_info, PATH_DELIM, and reallocate().

Referenced by file_tree_add_canon(), fs_read_dir(), and new_dir_node().

Here is the call graph for this function:

heap_str fs_real_path ( char const *  relname,
size_t *  namelen 
)

Return the absolute real pathname of a file or directory name (which may be the name of a symbolic link).

Parameters:
relnamePossibly relative file or directory name.
namelenIf non-NULL then the length of the absolute real name of relname is stored here at return.
Returns:
The absolute real pathname of relname in a string allocated on the heap. It is the caller's responsiblity to free this string. NULL is returned if an error occurs.

Definition at line 74 of file fs_nix.c.

References zallocate().

Referenced by file_tree_add(), file_tree_add_symlink(), and fs_open_dir().

Here is the call graph for this function:

heap_str fs_split_filename ( char const *  path,
char **  leafname 
)

Split at filename into its parent directory component and its terminal component.

Parameters:
pathPath to be split
leafnameNULL, or an address at which the function will store the address of the terminal component of path.
Returns:
The parent directory component of path allocated in a string on the heap. It is the caller's responsibility to free this string.

If path has only one component then, if that component is a directory, it is returned and NULL will be stored at leafname; if the one component is a file then NULL is returned

Definition at line 160 of file filesys.c.

References fs_file_or_dir(), FS_IS_FILE, PATH_DELIM, and zallocate().

Referenced by file_tree_add_canon().

Here is the call graph for this function:

char* fs_tempname ( char *  template)

Create a tempory filename from a template

Parameters:
templateA pathname pattern from which to compose the temporary filename.
Returns:
A pointer to the temporary filename created, or NULL if a temporary file satisfying template cannot be created.

The writable string template must terminate with XXXXXX This suffix will be replaced, if possible, with a string of characters to compose a filename different from that of any existing file.

Definition at line 74 of file filesys.c.

References FS_OBJ_NONE, and fs_obj_type().

Referenced by make_tempfile().

Here is the call graph for this function:

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines