1
0
mirror of https://github.com/adtools/clib2.git synced 2025-12-08 14:59:05 +00:00

- Fixed to compile correctly.

- Changed how multi-volume assignments are handled by execve().


git-svn-id: file:///Users/olsen/Code/migration-svn-zu-git/logical-line-staging/clib2/trunk@15115 87f5fb63-7c3d-0410-a384-fd976d0f7a62
This commit is contained in:
Olaf Barthel
2006-08-02 06:49:47 +00:00
parent 6cf4cc5b4a
commit 9caa5b7ec4
6 changed files with 49 additions and 34 deletions

View File

@@ -1,5 +1,5 @@
/* /*
* $Id: unistd.h,v 1.20 2006-08-01 16:41:02 obarthel Exp $ * $Id: unistd.h,v 1.21 2006-08-02 06:49:47 obarthel Exp $
* *
* :ts=4 * :ts=4
* *
@@ -123,7 +123,7 @@ extern char *ttyname(int);
extern int ttyname_r(int file_descriptor,char *name,size_t buflen); extern int ttyname_r(int file_descriptor,char *name,size_t buflen);
extern int ttyname_t(int,char *,size_t); extern int ttyname_t(int,char *,size_t);
extern int execl(const char *path,const char *arg0,...); extern int execl(const char *path,const char *arg0,...);
extern int execle(const char *path,const char *arg0,...): extern int execle(const char *path,const char *arg0,...);
extern int execlp(const char *path,const char *arg0,...); extern int execlp(const char *path,const char *arg0,...);
extern int execv(const char *path,char * const argv[]); extern int execv(const char *path,char * const argv[]);
extern int execve(const char *path,char *const argv[],char *const envp[]); extern int execve(const char *path,char *const argv[],char *const envp[]);

View File

@@ -1,5 +1,5 @@
/* /*
* $Id: unistd_execl.c,v 1.1 2006-08-01 14:27:52 obarthel Exp $ * $Id: unistd_execl.c,v 1.2 2006-08-02 06:49:47 obarthel Exp $
* *
* :ts=4 * :ts=4
* *
@@ -75,12 +75,12 @@ execl(const char *path, const char *arg0, ...)
{ {
size_t i; size_t i;
argv[0] = arg0; argv[0] = (char *)arg0;
va_start(args,arg0); va_start(args,arg0);
for(i = 1 ; i < argc ; i++) for(i = 1 ; i < argc ; i++)
argv[i] = va_arg(args,const char *); argv[i] = va_arg(args,char *);
va_end(args); va_end(args);
} }

View File

@@ -1,5 +1,5 @@
/* /*
* $Id: unistd_execle.c,v 1.2 2006-08-01 17:01:13 obarthel Exp $ * $Id: unistd_execle.c,v 1.3 2006-08-02 06:49:47 obarthel Exp $
* *
* :ts=4 * :ts=4
* *
@@ -78,10 +78,10 @@ execle(const char *path, const char *arg0, ...)
{ {
size_t i; size_t i;
argv[0] = arg0; argv[0] = (char *)arg0;
for(i = 1 ; i < argc ; i++) for(i = 1 ; i < argc ; i++)
argv[i] = va_arg(args,const char *); argv[i] = va_arg(args,char *);
/* Skip the NULL terminator */ /* Skip the NULL terminator */
(void)va_arg(args, char **); (void)va_arg(args, char **);

View File

@@ -1,5 +1,5 @@
/* /*
* $Id: unistd_execlp.c,v 1.1 2006-08-01 14:27:52 obarthel Exp $ * $Id: unistd_execlp.c,v 1.2 2006-08-02 06:49:47 obarthel Exp $
* *
* :ts=4 * :ts=4
* *
@@ -75,12 +75,12 @@ execlp(const char *path, const char *arg0, ...)
{ {
size_t i; size_t i;
argv[0] = arg0; argv[0] = (char *)arg0;
va_start(args,arg0); va_start(args,arg0);
for(i = 1 ; i < argc ; i++) for(i = 1 ; i < argc ; i++)
argv[i] = va_arg(args,const char *); argv[i] = va_arg(args,char *);
va_end(args); va_end(args);
} }

View File

@@ -1,5 +1,5 @@
/* /*
* $Id: unistd_execve.c,v 1.2 2006-08-01 19:01:17 obarthel Exp $ * $Id: unistd_execve.c,v 1.3 2006-08-02 06:49:47 obarthel Exp $
* *
* :ts=4 * :ts=4
* *
@@ -37,6 +37,10 @@
/****************************************************************************/ /****************************************************************************/
#include <dos/stdio.h>
/****************************************************************************/
/* The following is not part of the ISO 'C' (1994) standard. */ /* The following is not part of the ISO 'C' (1994) standard. */
/****************************************************************************/ /****************************************************************************/
@@ -73,7 +77,7 @@ find_resident_command(const char * command_name)
a more sophisticated arbitration method for this yet... */ a more sophisticated arbitration method for this yet... */
Forbid(); Forbid();
seg = FindSegment((STRPTR)name,NULL,0); seg = FindSegment((STRPTR)command_name,NULL,0);
if(seg != NULL) if(seg != NULL)
{ {
/* Check if that's a disable command or something else. */ /* Check if that's a disable command or something else. */
@@ -104,11 +108,12 @@ get_first_script_line(const char * path,char ** line_ptr)
int result = -1; int result = -1;
char * script_line = NULL; char * script_line = NULL;
size_t script_line_size = 0; size_t script_line_size = 0;
size_t script_line_length = 0;
LONG c; LONG c;
(*line_ptr) = NULL; (*line_ptr) = NULL;
script_file = Open(path,MODE_OLDFILE); script_file = Open((STRPTR)path,MODE_OLDFILE);
if(script_file == ZERO) if(script_file == ZERO)
{ {
__set_errno(__translate_io_error_to_errno(IoErr())); __set_errno(__translate_io_error_to_errno(IoErr()));
@@ -133,7 +138,7 @@ get_first_script_line(const char * path,char ** line_ptr)
new_script_line = realloc(script_line,script_line_length + 10); new_script_line = realloc(script_line,script_line_length + 10);
if(new_script_line == NULL) if(new_script_line == NULL)
{ {
__set_error(ENOMEM); __set_errno(ENOMEM);
goto out; goto out;
} }
@@ -141,11 +146,11 @@ get_first_script_line(const char * path,char ** line_ptr)
script_line_size = script_line_length + 10; script_line_size = script_line_length + 10;
} }
script_line[script_line_length++] = c;
/* Stop when we hit a line feed or unprintable character */ /* Stop when we hit a line feed or unprintable character */
if(c == '\n' || c < ' ' || (c >= 128 && c < 160)) if(c == '\n' || c < ' ' || (c >= 128 && c < 160))
break; break;
script_line[script_line_length++] = c;
} }
/* Check for read error */ /* Check for read error */
@@ -224,14 +229,13 @@ free_program_info(struct program_info * pi)
/* Try to find a command by name; if the name does not include any path /* Try to find a command by name; if the name does not include any path
information, try the dos.library resident command list */ information, try the dos.library resident command list */
static int static int
find_command(char * path,struct program_info ** result_ptr) find_command(const char * path,struct program_info ** result_ptr)
{ {
struct name_translation_info nti; struct name_translation_info nti;
char * script_line = NULL; char * script_line = NULL;
struct program_info * pi; struct program_info * pi;
APTR old_window_ptr; APTR old_window_ptr;
int result = -1; int result = -1;
BPTR file_lock;
BPTR old_dir; BPTR old_dir;
int error; int error;
@@ -258,7 +262,7 @@ find_command(char * path,struct program_info ** result_ptr)
} }
/* No relative or absolute path given? */ /* No relative or absolute path given? */
if(FilePart(path) == (STRPTR)path) if(FilePart((STRPTR)path) == (STRPTR)path)
{ {
/* Try to find the command on the resident list */ /* Try to find the command on the resident list */
pi->resident_command = find_resident_command(path); pi->resident_command = find_resident_command(path);
@@ -272,6 +276,7 @@ find_command(char * path,struct program_info ** result_ptr)
{ {
struct MsgPort * file_system; struct MsgPort * file_system;
struct DevProc * dvp = NULL; struct DevProc * dvp = NULL;
STRPTR relative_path;
BOOL done = FALSE; BOOL done = FALSE;
LONG io_err; LONG io_err;
int error = 0; int error = 0;
@@ -281,18 +286,30 @@ find_command(char * path,struct program_info ** result_ptr)
referring to "C:" gracefully */ referring to "C:" gracefully */
file_system = GetFileSysTask(); file_system = GetFileSysTask();
/* Figure out which part of the path name includes the device
or assignment portion, then skip it. This is because the
loop below uses GetDeviceProc() to find the file or command,
and it starts by changing to the directory the device, volume
or assignment in the path name is bound to. */
relative_path = (STRPTR)strchr(path,':');
if(relative_path != NULL)
relative_path++;
else
relative_path = (STRPTR)path;
do do
{ {
dvp = GetDeviceProc(path,dvp); dvp = GetDeviceProc((STRPTR)path,dvp);
if(dvp != NULL) if(dvp != NULL)
{ {
SetFileSysTask(dvp->dvp_Port); SetFileSysTask(dvp->dvp_Port);
old_dir = CurrentDir(dvp->dvp_Lock); old_dir = CurrentDir(dvp->dvp_Lock);
/* First try: let's assume that that the file is /* First try: let's assume that that the file is
executable */ executable */
pi->segment_list = LoadSeg(path); pi->segment_list = LoadSeg(relative_path);
if(pi->segment_list != ZERO) if(pi->segment_list != ZERO)
{ {
/* Remember where that file came from so that /* Remember where that file came from so that
@@ -320,7 +337,7 @@ find_command(char * path,struct program_info ** result_ptr)
if(error == 0 && !done && (io_err == ERROR_OBJECT_NOT_FOUND || io_err == ERROR_OBJECT_WRONG_TYPE || io_err == ERROR_BAD_HUNK)) if(error == 0 && !done && (io_err == ERROR_OBJECT_NOT_FOUND || io_err == ERROR_OBJECT_WRONG_TYPE || io_err == ERROR_BAD_HUNK))
{ {
/* Could that be an ARexx or shell script? */ /* Could that be an ARexx or shell script? */
if(get_first_script_line(path,&script_line) == 0) if(get_first_script_line(relative_path,&script_line) == 0)
{ {
if(strncmp(script_line,"/*",2) == SAME) if(strncmp(script_line,"/*",2) == SAME)
{ {
@@ -387,7 +404,7 @@ find_command(char * path,struct program_info ** result_ptr)
{ {
BPTR file_lock; BPTR file_lock;
file_lock = Lock(path,SHARED_LOCK); file_lock = Lock(relative_path,SHARED_LOCK);
if(file_lock != ZERO) if(file_lock != ZERO)
{ {
D_S(struct FileInfoBlock,fib); D_S(struct FileInfoBlock,fib);
@@ -458,7 +475,7 @@ count_extra_escape_chars(const char * string,size_t len)
for(i = 0 ; i < len ; i++) for(i = 0 ; i < len ; i++)
{ {
c = (*s++); c = (*string++);
if(c == '\"' || c == '*' || c == '\n') if(c == '\"' || c == '*' || c == '\n')
count++; count++;
} }
@@ -479,7 +496,7 @@ string_needs_quoting(const char * string,size_t len)
for(i = 0 ; i < len ; i++) for(i = 0 ; i < len ; i++)
{ {
c = (*s++); c = (*string++);
if(c == ' ' || ((unsigned char)c) == 0xA0 || c == '\t' || c == '\n' || c == '\"') if(c == ' ' || ((unsigned char)c) == 0xA0 || c == '\t' || c == '\n' || c == '\"')
{ {
result = TRUE; result = TRUE;
@@ -580,16 +597,15 @@ int
execve(const char *path, char *const argv[], char *const envp[]) execve(const char *path, char *const argv[], char *const envp[])
{ {
struct Process * this_process = (struct Process *)FindTask(NULL); struct Process * this_process = (struct Process *)FindTask(NULL);
char old_program_name[256] char old_program_name[256];
int result = -1; int result = -1;
struct program_info * pi; struct program_info * pi;
char * arg_string = NULL; char * arg_string = NULL;
size_t arg_string_len = 0; size_t arg_string_len = 0;
size_t parameter_string_len; size_t parameter_string_len;
BOOL success = FALSE; BOOL success = FALSE;
int error; BPTR old_dir;
LONG rc; LONG rc;
LONG c;
/* We begin by trying to find the command to execute */ /* We begin by trying to find the command to execute */
if(find_command((char *)path,&pi) != 0) if(find_command((char *)path,&pi) != 0)
@@ -679,8 +695,8 @@ execve(const char *path, char *const argv[], char *const envp[])
/* Change the command's home directory, so that "PROGDIR:" /* Change the command's home directory, so that "PROGDIR:"
can be used */ can be used */
old_dir = ThisProcess->pr_HomeDir; old_dir = this_process->pr_HomeDir;
ThisProcess->pr_HomeDir = pi->home_dir; this_process->pr_HomeDir = pi->home_dir;
/* Reset the break signal before the program starts */ /* Reset the break signal before the program starts */
SetSignal(0,SIGBREAKF_CTRL_C); SetSignal(0,SIGBREAKF_CTRL_C);
@@ -689,7 +705,7 @@ execve(const char *path, char *const argv[], char *const envp[])
rc = RunCommand((pi->resident_command != NULL) ? pi->resident_command->seg_Seg : pi->segment_list,Cli()->cli_DefaultStack * sizeof(LONG),arg_string,arg_string_len); rc = RunCommand((pi->resident_command != NULL) ? pi->resident_command->seg_Seg : pi->segment_list,Cli()->cli_DefaultStack * sizeof(LONG),arg_string,arg_string_len);
/* Restore the home directory */ /* Restore the home directory */
ThisProcess->pr_HomeDir = old_dir; this_process->pr_HomeDir = old_dir;
/* Restore the program name */ /* Restore the program name */
SetProgramName(old_program_name); SetProgramName(old_program_name);

View File

@@ -1,5 +1,5 @@
/* /*
* $Id: unistd_execvp.c,v 1.2 2006-08-01 17:01:13 obarthel Exp $ * $Id: unistd_execvp.c,v 1.3 2006-08-02 06:49:47 obarthel Exp $
* *
* :ts=4 * :ts=4
* *
@@ -98,7 +98,6 @@ execvp(const char *command,char * const argv[])
char * command_buffer = NULL; char * command_buffer = NULL;
char * path_copy = NULL; char * path_copy = NULL;
int result = -1; int result = -1;
char * bp;
/* Do not allow null command */ /* Do not allow null command */
if(command == NULL || (*command) == '\0') if(command == NULL || (*command) == '\0')