HTML automatically generated with rman
Table of Contents


root, extension, head, tail, defext, pathopen, pathfind, _mappath, - file operations


#include <stdinc.h>#include <filefn.h>string root(filename)string extension(filename)string
head(filename)string tail(filename)string fullname(filename)
string defext(filename,ext)stream
pathopen(path, filename, mode)string pathfind(path, filename)string _mappath(fn,
path, filename, arg)
string filename, ext, mode, path;
DescriptionThe first
four functions  root(), extension(), head(), and tail(), returns a component
of a file name and are equivalent to the C shell substitution characters
:r, :e, :h, and :t, respectively.  fullname() returns the full name of a
file, making it easier to find the file again if the user used chdir(2)
during the program. 
defext() adds an extension to a file name if none already
exists.  Alternatively, if the extension field ext begins with a *, any
old extension in filename is replaced with the given extension.        
     defext(filename, ".xxx")   --  add .xxx if no ext       
     defext(filename, "*.xxx")  --  force .xxx as ext        
Note: defext returns a pointer to dynamically-allocated string storage which is never freed. This is necessary to ensure safety on multiple calls in a single statement.

pathopen() is used to open files using a search path similar to that used, for example, by csh in searching for a command. The pathopen routine has the same structure as fopen(3) and the filename and mode arguments are the same as in that call. The path argument consists of a list of directories which are prepended to the filename, unless the filename begins with either a / or a ~. The directories in the list are separated by colons as in the definition of the PATH environment variable. White space and empty fields are ignored to simplify formatting of paths in a definition file.

After each directory name has been added, the pathopen performs ~ (tilde) expansion in the same form as csh. The path argument may be NULL, in which case no directories are prepended. This is useful if ~ expansion is the only required function.

pathopen() returns an open stream to the indicated file, or NULL, if no existing file is found.

pathfind() is similar to pathopen, except that it does not try to open the file but instead returns the full name of the first file that exists along the path, or NULL if none exist.

_mappath() maps the string function fn over each path/filename combination, stopping when fn(name, arg) returns non-null. That value is returned. If the function always returns a NULL value for each element in the path, NULL is returned from _mappath.


Eric Roberts


~/src/kernel/cores    filefn.c

Update History

11-jan-86    Last modified       Roberts
6-dec-86    Fixed some bugs and updated for Nemo    Josh
6-oct-90    Manual page written    Peter
17-mar-06    added fullname    Peter

Table of Contents