Main Page | Modules | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

tc_path.c File Reference


Detailed Description

For internal use only.

This file contains the implementation of the tc_path() function, used to locate files in a given path.

Definition in file tc_path.c.

#include <errno.h>
#include <pwd.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include "treeconf_int.h"

Include dependency graph for tc_path.c:

Include dependency graph

Go to the source code of this file.

Data Structures

struct  buf
 File name buffer. More...

Defines

#define BUF_CHUNK
 Buffer chunk.
#define STOP
 Stop file search loop return value.
#define CONTINUE
 Continue file search loop return value.
#define stop(e)
 Stop file search loop.
#define cont()
 Continue file search loop.
#define _TC_PATH_DEFAULT
 Default path has been searched.
#define _TC_PATH_PERCENT
 Percent character.

Functions

unsigned int _get_pwd (struct passwd **pwd_p, const char *uname, int len)
 Look up password structure.
unsigned int _add_str (struct buf *buf, const char *str, int len)
 Add string to buffer.
unsigned int _tilde (struct buf *buf, const char *uname, int len)
 Add user home directory to buffer.
int _subst (struct buf *buf, treeconf_str_t *element, treeconf_subst_t substs[], int s_cnt, unsigned int flags, treeconf_file_t call, void *call_data, unsigned int *err)
 Perform file name substitution and process a file.
unsigned int tc_path (const char *path, const char *def, treeconf_subst_t substs[], int s_cnt, unsigned int flags, treeconf_file_t call, void *call_data)
 Search a path-like string for readable files.


Define Documentation

#define _TC_PATH_DEFAULT
 

For internal use only.

This flag, if set, indicates that the default path has been searched. It is used to avoid searching the default more than once.

Definition at line 216 of file tc_path.c.

#define _TC_PATH_PERCENT
 

For internal use only.

This flag, if set, indicates that the previous character processed was a percent character. This will trigger a search of the substitutions passed to _subst() to fill in the appropriate data.

Definition at line 225 of file tc_path.c.

#define BUF_CHUNK
 

For internal use only.

This macro sets the allocation size for a file name. If the buffer is too short to accommodate the name, the buffer size will be incremented by this amount.

Definition at line 56 of file tc_path.c.

 
#define cont  ) 
 

For internal use only.

This macro exits the _subst() routine with an instruction to tc_path() to continue the file search loop.

Definition at line 207 of file tc_path.c.

Referenced by _subst().

#define CONTINUE
 

For internal use only.

The _subst() function is called in a loop by tc_path(). If _subst() returns this value to tc_path(), tc_path() will continue on to the next file in the path.

Definition at line 188 of file tc_path.c.

Referenced by _subst().

#define stop  ) 
 

For internal use only.

This macro exits the _subst() routine with an instruction to tc_path() to terminate the file search loop. It may be used to signal an error condition, thus the e parameter.

Parameters:
e An error code for tc_path() to return.

Definition at line 199 of file tc_path.c.

Referenced by _subst().

#define STOP
 

For internal use only.

The _subst() function is called in a loop by tc_path(). If _subst() returns this value to tc_path(), the file search loop will be exited.

Definition at line 179 of file tc_path.c.


Function Documentation

unsigned int _add_str struct buf buf,
const char *  str,
int  len
[static]
 

For internal use only.

This function simply adds the given str to the file name buffer. If str is NULL, the current user's user name will be added instead.

Parameters:
buf A pointer to a struct buf designating the buffer to add the string to.
str A pointer to a char designating the string to add to the buffer.
len The length of the str to add to the buffer.
Returns:
Anything _get_pwd() can return, or ENOMEM if no memory could be allocated for the buffer.

Definition at line 111 of file tc_path.c.

References _get_pwd(), buf::len, buf::size, and buf::str.

Referenced by _subst(), and _tilde().

Here is the call graph for this function:

unsigned int _get_pwd struct passwd **  pwd_p,
const char *  uname,
int  len
[static]
 

For internal use only.

This function looks up a given user's password file entry. If uname is NULL, the current effective user ID will be looked up.

Parameters:
pwd_p A pointer to a pointer to a struct passwd to fill in with the user password structure.
uname The name of the user to look up, or NULL to look up the current effective user.
len The length of uname.
Returns:
Zero on success, or any of the errors that can be generated by getpwnam(), getpwuid(), or geteuid().

Definition at line 74 of file tc_path.c.

Referenced by _add_str(), and _tilde().

int _subst struct buf buf,
treeconf_str_t element,
treeconf_subst_t  substs[],
int  s_cnt,
unsigned int  flags,
treeconf_file_t  call,
void *  call_data,
unsigned int *  err
[static]
 

For internal use only.

This is the workhorse routine for tc_path(). This routine is passed an element of the path list, and processes that element, performing tilde and percent substitutions to determine the actual file name. Then, that file is checked for readability; if it is readable, the call callback function will be executed for that file.

Parameters:
buf A pointer to a struct buf to hold the substituted file name.
element The element of the path to process.
substs An array of treeconf_subst_t structures specifying all caller-specified substitutions.
s_cnt An int containing the number of caller-specified substitution rules passed in the substs parameter.
flags The flags controlling the path search.
call A treeconf_file_t function pointer.
call_data Extra data to pass to the call function.
err A pointer to an unsigned int to receive an error code.
Return values:
CONTINUE The file search loop should be continued.
STOP The file search loop should be terminated.

Definition at line 257 of file tc_path.c.

References _add_str(), _tilde(), access(), cont, CONTINUE, buf::len, stop, buf::str, substs, TC_PATH_ALL, treeconf_str_t, treeconf_subst_t, _treeconf_str_s::ts_length, _treeconf_str_s::ts_string, _treeconf_subst_s::tu_char, _treeconf_subst_s::tu_flags, and tu_value.

Referenced by tc_path().

Here is the call graph for this function:

unsigned int _tilde struct buf buf,
const char *  uname,
int  len
[static]
 

For internal use only.

This simple helper function simply adds the given user's home directory to the file name buffer.

Parameters:
buf A pointer to a struct buf designating the buffer to add the string to.
uname The name of the user, or NULL to look up the current effective user.
len The length of uname.
Returns:
Zero on success, or any of the errors that can be generated by _get_pwd() or _add_str().

Definition at line 163 of file tc_path.c.

References _add_str(), and _get_pwd().

Referenced by _subst().

Here is the call graph for this function:


Generated on Wed Jun 8 09:18:34 2005 for treeconf by  doxygen 1.3.9.1