1
1

Fixing STRDIR in path.c and prototyping errors

This commit was SVN r177.
Этот коммит содержится в:
Prabhanjan Kambadur 2004-01-09 18:47:52 +00:00
родитель 07ad5a5ec3
Коммит 3b2c1b6dd7
2 изменённых файлов: 93 добавлений и 87 удалений

Просмотреть файл

@ -6,16 +6,10 @@
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <lam_config> #include "lam_config.h"
#include "lam/util/argv.h" #include "lam/util/argv.h"
#include "lam/util/malloc.h" #include "lam/util/malloc.h"
#if 0
#include <args.h>
#include <laminternal.h>
#include <sfh.h>
#endif
/** @file **/ /** @file **/
/** /**
@ -27,9 +21,16 @@
#define PATHENVSEP ':' #define PATHENVSEP ':'
#endif #endif
static void path_env_load(char *, int *, char ***); /**
static char *path_access(char *, char *, int); * Directory seperator
static char *list_env_get(char *, char **); */
#define STRDIR '/'
#define STRSDIR "/"
static void path_env_load(char *path, int *pargc, char ***pargv);
static char *path_access(char *fname, char *path, int mode);
static char *list_env_get(char *var, char **list);
/** /**
* Locates a file with certain permissions * Locates a file with certain permissions
@ -51,28 +52,28 @@ static char *list_env_get(char *, char **);
char * char *
lam_path_findv(char *fname, char **pathv, int mode, char **envv) lam_path_findv(char *fname, char **pathv, int mode, char **envv)
{ {
char *fullpath; /* full pathname of search file */ char *fullpath;
char *delimit; /* ptr to first delimiter in prefix */ char *delimit;
char *env; /* ptr to environment var */ char *env;
char *pfix; /* prefix directory */ char *pfix;
int i; int i;
/* /*
* If absolute path is given, return it without searching. * If absolute path is given, return it without searching.
*/ */
if (*fname == STRDIR) { if (STRDIR == *fname) {
return(path_access(fname, "", mode)); return(path_access(fname, "", mode));
} }
/* /*
* Initialize. * Initialize.
*/ */
fullpath = NULL; fullpath = NULL;
i = 0; i = 0;
/* /*
* Consider each directory until the file is found. * Consider each directory until the file is found.
* Thus, the order of directories is important. * Thus, the order of directories is important.
*/ */
while (pathv[i] && !fullpath) { while (pathv[i] && !fullpath) {
/* /*
* Replace environment variable at the head of the string. * Replace environment variable at the head of the string.
*/ */
if ('$' == *pathv[i]) { if ('$' == *pathv[i]) {
@ -89,7 +90,7 @@ lam_path_findv(char *fname, char **pathv, int mode, char **envv)
fullpath = path_access(fname, env, mode); fullpath = path_access(fname, env, mode);
} else { } else {
pfix = LAM_MALLOC((unsigned) strlen(env) + strlen(delimit) + 1); pfix = LAM_MALLOC((unsigned) strlen(env) + strlen(delimit) + 1);
if (pfix == NULL){ if (NULL == pfix){
return(0); return(0);
} }
strcpy(pfix, env); strcpy(pfix, env);
@ -148,13 +149,13 @@ lam_path_find(char *fname, char **pathv, int mode)
char * char *
lam_path_env_findv(char *fname, int mode, char **envv, char *wrkdir) lam_path_env_findv(char *fname, int mode, char **envv, char *wrkdir)
{ {
char **dirv; /* search directories */ char **dirv;
char *fullpath; /* full pathname */ char *fullpath;
char *path; /* value of PATH */ char *path;
int dirc; /* # search directories */ int dirc;
int i; int i;
int found_dot = 0; int found_dot = 0;
/* /*
* Set the local search paths. * Set the local search paths.
*/ */
dirc = 0; dirc = 0;
@ -163,7 +164,7 @@ lam_path_env_findv(char *fname, int mode, char **envv, char *wrkdir)
if ((path = list_env_get("PATH", envv))) { if ((path = list_env_get("PATH", envv))) {
path_env_load(path, &dirc, &dirv); path_env_load(path, &dirc, &dirv);
} }
/* /*
* Replace the "." path by the working directory. * Replace the "." path by the working directory.
*/ */
for (i = 0; i < dirc; ++i) { for (i = 0; i < dirc; ++i) {
@ -176,7 +177,7 @@ lam_path_env_findv(char *fname, int mode, char **envv, char *wrkdir)
} }
} }
} }
/* /*
* If we didn't find "." in the path and we have a wrkdir, append * If we didn't find "." in the path and we have a wrkdir, append
* the wrkdir to the end of the path * the wrkdir to the end of the path
*/ */
@ -216,18 +217,20 @@ lam_path_env_find(char *fname, int mode)
/** /**
* Forms a complete pathname and checks it for existance and permissions * Forms a complete pathname and checks it for existance and permissions
* *
* @param fname File name * Accepts:
* @param path Path prefix * -fname File name
* @param mode Target permissions which must be satisfied * -path Path prefix
* -mode Target permissions which must be satisfied
* *
* @retval Full pathname of located file Success * Returns:
* @retval NULL Failure * -Full pathname of located file Success
* -NULL Failure
*/ */
static char * static char *
path_access(char *fname, char *path, int mode) path_access(char *fname, char *path, int mode)
{ {
char *fullpath; /* full pathname of search file */ char *fullpath; /* full pathname of search file */
/* /*
* Allocate space for the full pathname. * Allocate space for the full pathname.
*/ */
fullpath = LAM_MALLOC((unsigned) strlen(path) + strlen(fname) + 2); fullpath = LAM_MALLOC((unsigned) strlen(path) + strlen(fname) + 2);
@ -242,7 +245,7 @@ path_access(char *fname, char *path, int mode)
} else { } else {
strcpy(fullpath, fname); strcpy(fullpath, fname);
} }
/* /*
* Get status on the full path name to check for existance. * Get status on the full path name to check for existance.
* Then check the permissions. * Then check the permissions.
*/ */
@ -258,9 +261,10 @@ path_access(char *fname, char *path, int mode)
* *
* Loads argument array with $PATH env var. * Loads argument array with $PATH env var.
* *
* @param path String contiaing the $PATH * Accepts
* @param argc Pointer to argc * -path String contiaing the $PATH
* @param argv Pointer to list of argv * -argc Pointer to argc
* -argv Pointer to list of argv
* *
*/ */
static void static void
@ -273,15 +277,15 @@ path_env_load(char *path, int *pargc, char ***pargv)
*pargc = 0; *pargc = 0;
return; return;
} }
/* /*
* Loop through the paths (delimited by PATHENVSEP), adding each one to argv. * Loop through the paths (delimited by PATHENVSEP), adding each one to argv.
*/ */
while (*path) { while (*path) {
/* /*
* Locate the delimiter. * Locate the delimiter.
*/ */
for (p = path; *p && (*p != PATHENVSEP); ++p); for (p = path; *p && (*p != PATHENVSEP); ++p);
/* /*
* Add the path. * Add the path.
*/ */
if (p != path) { if (p != path) {
@ -291,7 +295,7 @@ path_env_load(char *path, int *pargc, char ***pargv)
*p = saved; *p = saved;
path = p; path = p;
} }
/* /*
* Skip past the delimiter, if present. * Skip past the delimiter, if present.
*/ */
if (*path) { if (*path) {
@ -303,11 +307,13 @@ path_env_load(char *path, int *pargc, char ***pargv)
/** /**
* Gets value of variable in list or environment. Looks in the list first * Gets value of variable in list or environment. Looks in the list first
* *
* @param var String variable * Accepts:
* @param list Pointer to environment list * -var String variable
* -list Pointer to environment list
* *
* @retval List Pointer to environment list Success * Returns:
* @retval NULL Failure * -List Pointer to environment list Success
* -NULL Failure
*/ */
static char * static char *
list_env_get(char *var, char **list) list_env_get(char *var, char **list)

Просмотреть файл

@ -5,9 +5,9 @@
#ifndef LAM_PATH_H #ifndef LAM_PATH_H
#define LAM_PATH_H #define LAM_PATH_H
char *lam_path_find (char *, char **, int); char *lam_path_find (char *fname, char **pathv, int mode);
char *lam_path_env_find (char *, int); char *lam_path_env_find (char *fname, int mode);
char *lam_path_findv (char *, char **, int, char **); char *lam_path_findv (char *fname, char **pathv, int mode, char **envv);
char *lam_path_env_findv (char *, int, char **, char *); char *lam_path_env_findv (char *fname, int mode, char **envv, char *wrkdir);
#endif /* LAM_PATH_H */ #endif /* LAM_PATH_H */