Imported from ../bash-2.05a.tar.gz.
This commit is contained in:
49
findcmd.c
49
findcmd.c
@@ -22,7 +22,7 @@
|
||||
#include "config.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include "chartypes.h"
|
||||
#include "bashtypes.h"
|
||||
#ifndef _MINIX
|
||||
# include <sys/file.h>
|
||||
@@ -34,10 +34,6 @@
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#if defined (HAVE_LIMITS_H)
|
||||
# include <limits.h>
|
||||
#endif
|
||||
|
||||
#include "bashansi.h"
|
||||
|
||||
#include "memalloc.h"
|
||||
@@ -46,12 +42,18 @@
|
||||
#include "hashlib.h"
|
||||
#include "pathexp.h"
|
||||
#include "hashcmd.h"
|
||||
#include "findcmd.h" /* matching prototypes and declarations */
|
||||
|
||||
extern int posixly_correct;
|
||||
|
||||
/* Static functions defined and used in this file. */
|
||||
static char *find_user_command_internal (), *find_user_command_in_path ();
|
||||
static char *find_in_path_element (), *find_absolute_program ();
|
||||
static char *_find_user_command_internal __P((const char *, int));
|
||||
static char *find_user_command_internal __P((const char *, int));
|
||||
static char *find_user_command_in_path __P((const char *, char *, int));
|
||||
static char *find_in_path_element __P((const char *, char *, int, int, struct stat *));
|
||||
static char *find_absolute_program __P((const char *, int));
|
||||
|
||||
static char *get_next_path_element __P((char *, int *));
|
||||
|
||||
/* The file name which we would try to execute, except that it isn't
|
||||
possible to execute it. This is the first file that matches the
|
||||
@@ -81,7 +83,7 @@ int dot_found_in_search = 0;
|
||||
Zero is returned if the file is not found. */
|
||||
int
|
||||
file_status (name)
|
||||
char *name;
|
||||
const char *name;
|
||||
{
|
||||
struct stat finfo;
|
||||
|
||||
@@ -145,7 +147,7 @@ file_status (name)
|
||||
what an executable file is. */
|
||||
int
|
||||
executable_file (file)
|
||||
char *file;
|
||||
const char *file;
|
||||
{
|
||||
int s;
|
||||
|
||||
@@ -155,14 +157,14 @@ executable_file (file)
|
||||
|
||||
int
|
||||
is_directory (file)
|
||||
char *file;
|
||||
const char *file;
|
||||
{
|
||||
return (file_status (file) & FS_DIRECTORY);
|
||||
}
|
||||
|
||||
int
|
||||
executable_or_directory (file)
|
||||
char *file;
|
||||
const char *file;
|
||||
{
|
||||
int s;
|
||||
|
||||
@@ -177,7 +179,7 @@ executable_or_directory (file)
|
||||
and that is the only match, then return that. */
|
||||
char *
|
||||
find_user_command (name)
|
||||
char *name;
|
||||
const char *name;
|
||||
{
|
||||
return (find_user_command_internal (name, FS_EXEC_PREFERRED|FS_NODIRS));
|
||||
}
|
||||
@@ -188,14 +190,14 @@ find_user_command (name)
|
||||
returns the first file found. */
|
||||
char *
|
||||
find_path_file (name)
|
||||
char *name;
|
||||
const char *name;
|
||||
{
|
||||
return (find_user_command_internal (name, FS_EXISTS));
|
||||
}
|
||||
|
||||
static char *
|
||||
_find_user_command_internal (name, flags)
|
||||
char *name;
|
||||
const char *name;
|
||||
int flags;
|
||||
{
|
||||
char *path_list, *cmd;
|
||||
@@ -221,13 +223,13 @@ _find_user_command_internal (name, flags)
|
||||
|
||||
static char *
|
||||
find_user_command_internal (name, flags)
|
||||
char *name;
|
||||
const char *name;
|
||||
int flags;
|
||||
{
|
||||
#ifdef __WIN32__
|
||||
char *res, *dotexe;
|
||||
|
||||
dotexe = xmalloc (strlen (name) + 5);
|
||||
dotexe = (char *)xmalloc (strlen (name) + 5);
|
||||
strcpy (dotexe, name);
|
||||
strcat (dotexe, ".exe");
|
||||
res = _find_user_command_internal (dotexe, flags);
|
||||
@@ -270,7 +272,7 @@ get_next_path_element (path_list, path_index_pointer)
|
||||
in $PATH. Returns a newly-allocated string. */
|
||||
char *
|
||||
search_for_command (pathname)
|
||||
char *pathname;
|
||||
const char *pathname;
|
||||
{
|
||||
char *hashed_file, *command;
|
||||
int temp_path, st;
|
||||
@@ -324,14 +326,14 @@ search_for_command (pathname)
|
||||
else
|
||||
command = find_user_command (pathname);
|
||||
if (command && hashing_enabled && temp_path == 0)
|
||||
remember_filename (pathname, command, dot_found_in_search, 1);
|
||||
remember_filename ((char *)pathname, command, dot_found_in_search, 1); /* XXX fix const later */
|
||||
}
|
||||
return (command);
|
||||
}
|
||||
|
||||
char *
|
||||
user_command_matches (name, flags, state)
|
||||
char *name;
|
||||
const char *name;
|
||||
int flags, state;
|
||||
{
|
||||
register int i;
|
||||
@@ -414,7 +416,7 @@ user_command_matches (name, flags, state)
|
||||
|
||||
static char *
|
||||
find_absolute_program (name, flags)
|
||||
char *name;
|
||||
const char *name;
|
||||
int flags;
|
||||
{
|
||||
int st;
|
||||
@@ -431,12 +433,13 @@ find_absolute_program (name, flags)
|
||||
if ((flags & FS_EXISTS) || ((flags & FS_EXEC_ONLY) && (st & FS_EXECABLE)))
|
||||
return (savestring (name));
|
||||
|
||||
return ((char *)NULL);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
static char *
|
||||
find_in_path_element (name, path, flags, name_len, dotinfop)
|
||||
char *name, *path;
|
||||
const char *name;
|
||||
char *path;
|
||||
int flags, name_len;
|
||||
struct stat *dotinfop;
|
||||
{
|
||||
@@ -509,7 +512,7 @@ find_in_path_element (name, path, flags, name_len, dotinfop)
|
||||
*/
|
||||
static char *
|
||||
find_user_command_in_path (name, path_list, flags)
|
||||
char *name;
|
||||
const char *name;
|
||||
char *path_list;
|
||||
int flags;
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user