1995-08-09 08:06:35 -07:00
|
|
|
/***********************************************************************/
|
|
|
|
/* */
|
1996-04-30 07:53:58 -07:00
|
|
|
/* Objective Caml */
|
1995-08-09 08:06:35 -07:00
|
|
|
/* */
|
|
|
|
/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */
|
|
|
|
/* */
|
1996-04-30 07:53:58 -07:00
|
|
|
/* Copyright 1996 Institut National de Recherche en Informatique et */
|
1999-11-17 10:59:06 -08:00
|
|
|
/* en Automatique. All rights reserved. This file is distributed */
|
|
|
|
/* under the terms of the GNU Library General Public License. */
|
1995-08-09 08:06:35 -07:00
|
|
|
/* */
|
|
|
|
/***********************************************************************/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
/* Basic system calls */
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <signal.h>
|
1995-05-04 05:48:07 -07:00
|
|
|
#include <stdlib.h>
|
1997-06-13 08:49:36 -07:00
|
|
|
#include <stdio.h>
|
1995-05-04 03:15:53 -07:00
|
|
|
#include <string.h>
|
1998-02-25 02:20:38 -08:00
|
|
|
#include <time.h>
|
1996-11-02 10:00:46 -08:00
|
|
|
#if !macintosh
|
1995-08-10 02:16:58 -07:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
1996-11-02 10:00:46 -08:00
|
|
|
#endif
|
1998-12-02 08:11:37 -08:00
|
|
|
#if !macintosh && !_WIN32
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#endif
|
1999-11-29 11:03:05 -08:00
|
|
|
#if macintosh
|
|
|
|
#include "macintosh.h"
|
|
|
|
#endif
|
1995-05-04 03:15:53 -07:00
|
|
|
#include "config.h"
|
1996-02-21 02:49:46 -08:00
|
|
|
#ifdef HAS_UNISTD
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
1998-02-25 02:20:38 -08:00
|
|
|
#ifdef HAS_TIMES
|
|
|
|
#include <sys/times.h>
|
|
|
|
#endif
|
1999-11-23 02:49:40 -08:00
|
|
|
#ifdef HAS_GETTIMEOFDAY
|
|
|
|
#include <sys/time.h>
|
|
|
|
#endif
|
1995-05-04 03:15:53 -07:00
|
|
|
#include "alloc.h"
|
1996-11-29 10:36:42 -08:00
|
|
|
#include "debugger.h"
|
1995-05-04 03:15:53 -07:00
|
|
|
#include "fail.h"
|
|
|
|
#include "instruct.h"
|
|
|
|
#include "mlvalues.h"
|
|
|
|
#include "signals.h"
|
|
|
|
#include "stacks.h"
|
1996-10-01 02:46:42 -07:00
|
|
|
#include "sys.h"
|
1995-08-08 06:37:34 -07:00
|
|
|
#ifdef HAS_UI
|
|
|
|
#include "ui.h"
|
|
|
|
#endif
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
extern int errno;
|
|
|
|
|
|
|
|
#ifdef HAS_STRERROR
|
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
extern char * strerror(int);
|
1995-05-04 03:15:53 -07:00
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
char * error_message(void)
|
1995-05-04 03:15:53 -07:00
|
|
|
{
|
|
|
|
return strerror(errno);
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
extern int sys_nerr;
|
|
|
|
extern char * sys_errlist [];
|
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
char * error_message(void)
|
1995-05-04 03:15:53 -07:00
|
|
|
{
|
|
|
|
if (errno < 0 || errno >= sys_nerr)
|
|
|
|
return "unknown error";
|
|
|
|
else
|
|
|
|
return sys_errlist[errno];
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* HAS_STRERROR */
|
|
|
|
|
1998-11-20 07:36:27 -08:00
|
|
|
#ifndef EAGAIN
|
|
|
|
#define EAGAIN (-1)
|
|
|
|
#endif
|
|
|
|
#ifndef EWOULDBLOCK
|
|
|
|
#define EWOULDBLOCK (-1)
|
|
|
|
#endif
|
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
void sys_error(value arg)
|
1995-05-04 03:15:53 -07:00
|
|
|
{
|
1999-11-29 11:03:05 -08:00
|
|
|
CAMLparam1 (arg);
|
1998-11-20 07:36:27 -08:00
|
|
|
char * err;
|
1999-11-29 11:03:05 -08:00
|
|
|
CAMLlocal1 (str);
|
1996-10-01 02:46:42 -07:00
|
|
|
|
1998-11-20 07:36:27 -08:00
|
|
|
if (errno == EAGAIN || errno == EWOULDBLOCK) {
|
|
|
|
raise_sys_blocked_io();
|
1995-05-04 03:15:53 -07:00
|
|
|
} else {
|
1998-11-20 07:36:27 -08:00
|
|
|
err = error_message();
|
|
|
|
if (arg == NO_ARG) {
|
|
|
|
str = copy_string(err);
|
|
|
|
} else {
|
|
|
|
int err_len = strlen(err);
|
|
|
|
int arg_len = string_length(arg);
|
1997-05-26 10:16:31 -07:00
|
|
|
str = alloc_string(arg_len + 2 + err_len);
|
1998-11-20 07:36:27 -08:00
|
|
|
bcopy(String_val(arg), &Byte(str, 0), arg_len);
|
|
|
|
bcopy(": ", &Byte(str, arg_len), 2);
|
|
|
|
bcopy(err, &Byte(str, arg_len + 2), err_len);
|
|
|
|
}
|
|
|
|
raise_sys_error(str);
|
1995-05-04 03:15:53 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
value sys_exit(value retcode) /* ML */
|
1995-05-04 03:15:53 -07:00
|
|
|
{
|
1997-01-02 06:15:42 -08:00
|
|
|
#ifndef NATIVE_CODE
|
1996-11-29 10:36:42 -08:00
|
|
|
debugger(PROGRAM_EXIT);
|
1997-01-02 06:15:42 -08:00
|
|
|
#endif
|
1995-08-08 06:37:34 -07:00
|
|
|
#ifdef HAS_UI
|
|
|
|
ui_exit(Int_val(retcode));
|
|
|
|
#else
|
1995-05-04 03:15:53 -07:00
|
|
|
exit(Int_val(retcode));
|
1995-08-08 06:37:34 -07:00
|
|
|
#endif
|
1996-02-18 06:44:59 -08:00
|
|
|
return Val_unit;
|
1995-05-04 03:15:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef O_BINARY
|
|
|
|
#define O_BINARY 0
|
|
|
|
#endif
|
|
|
|
#ifndef O_TEXT
|
|
|
|
#define O_TEXT 0
|
|
|
|
#endif
|
1996-04-29 06:18:36 -07:00
|
|
|
#ifndef O_NONBLOCK
|
|
|
|
#ifdef O_NDELAY
|
|
|
|
#define O_NONBLOCK O_NDELAY
|
|
|
|
#else
|
|
|
|
#define O_NONBLOCK 0
|
|
|
|
#endif
|
|
|
|
#endif
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
static int sys_open_flags[] = {
|
1996-04-29 06:18:36 -07:00
|
|
|
O_RDONLY, O_WRONLY, O_APPEND, O_CREAT, O_TRUNC, O_EXCL,
|
|
|
|
O_BINARY, O_TEXT, O_NONBLOCK
|
1995-05-04 03:15:53 -07:00
|
|
|
};
|
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
value sys_open(value path, value flags, value perm) /* ML */
|
1995-05-04 03:15:53 -07:00
|
|
|
{
|
|
|
|
int ret;
|
1996-11-02 10:00:46 -08:00
|
|
|
ret = open(String_val(path), convert_flag_list(flags, sys_open_flags)
|
|
|
|
#if !macintosh
|
1997-06-13 08:49:36 -07:00
|
|
|
, Int_val(perm)
|
1996-11-02 10:00:46 -08:00
|
|
|
#endif
|
1997-05-19 08:42:21 -07:00
|
|
|
);
|
1996-10-01 02:46:42 -07:00
|
|
|
if (ret == -1) sys_error(path);
|
1995-05-04 03:15:53 -07:00
|
|
|
return Val_long(ret);
|
|
|
|
}
|
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
value sys_close(value fd) /* ML */
|
1996-10-31 08:01:50 -08:00
|
|
|
{
|
|
|
|
close(Int_val(fd));
|
|
|
|
return Val_unit;
|
|
|
|
}
|
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
value sys_file_exists(value name) /* ML */
|
1995-05-04 03:15:53 -07:00
|
|
|
{
|
1996-11-02 10:00:46 -08:00
|
|
|
#if macintosh
|
|
|
|
int f;
|
|
|
|
f = open (String_val (name), O_RDONLY);
|
|
|
|
if (f == -1) return (Val_bool (0));
|
|
|
|
close (f);
|
|
|
|
return (Val_bool (1));
|
|
|
|
#else
|
1995-08-10 02:16:58 -07:00
|
|
|
struct stat st;
|
|
|
|
return Val_bool(stat(String_val(name), &st) == 0);
|
1996-11-02 10:00:46 -08:00
|
|
|
#endif
|
1995-05-04 03:15:53 -07:00
|
|
|
}
|
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
value sys_remove(value name) /* ML */
|
1995-05-04 03:15:53 -07:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
ret = unlink(String_val(name));
|
1996-10-01 02:46:42 -07:00
|
|
|
if (ret != 0) sys_error(name);
|
1995-06-18 07:44:56 -07:00
|
|
|
return Val_unit;
|
1995-05-04 03:15:53 -07:00
|
|
|
}
|
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
value sys_rename(value oldname, value newname) /* ML */
|
1995-05-04 03:15:53 -07:00
|
|
|
{
|
|
|
|
if (rename(String_val(oldname), String_val(newname)) != 0)
|
1996-10-01 02:46:42 -07:00
|
|
|
sys_error(oldname);
|
1995-06-18 07:44:56 -07:00
|
|
|
return Val_unit;
|
1995-05-04 03:15:53 -07:00
|
|
|
}
|
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
value sys_chdir(value dirname) /* ML */
|
1995-05-04 03:15:53 -07:00
|
|
|
{
|
1996-10-01 02:46:42 -07:00
|
|
|
if (chdir(String_val(dirname)) != 0) sys_error(dirname);
|
1995-06-18 07:44:56 -07:00
|
|
|
return Val_unit;
|
1995-05-04 03:15:53 -07:00
|
|
|
}
|
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
value sys_getcwd(value unit) /* ML */
|
1995-08-23 04:54:56 -07:00
|
|
|
{
|
|
|
|
char buff[4096];
|
1995-09-25 07:42:51 -07:00
|
|
|
#ifdef HAS_GETCWD
|
1996-10-01 02:46:42 -07:00
|
|
|
if (getcwd(buff, sizeof(buff)) == 0) sys_error(NO_ARG);
|
1995-09-25 07:42:51 -07:00
|
|
|
#else
|
1996-10-01 02:46:42 -07:00
|
|
|
if (getwd(buff) == 0) sys_error(NO_ARG);
|
1996-11-02 10:00:46 -08:00
|
|
|
#endif /* HAS_GETCWD */
|
1995-08-23 04:54:56 -07:00
|
|
|
return copy_string(buff);
|
|
|
|
}
|
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
value sys_getenv(value var) /* ML */
|
1995-05-04 03:15:53 -07:00
|
|
|
{
|
|
|
|
char * res;
|
|
|
|
|
|
|
|
res = getenv(String_val(var));
|
|
|
|
if (res == 0) raise_not_found();
|
|
|
|
return copy_string(res);
|
|
|
|
}
|
|
|
|
|
|
|
|
static char ** main_argv;
|
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
value sys_get_argv(value unit) /* ML */
|
1995-05-04 03:15:53 -07:00
|
|
|
{
|
|
|
|
return copy_string_array(main_argv);
|
|
|
|
}
|
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
void sys_init(char **argv)
|
1995-05-04 03:15:53 -07:00
|
|
|
{
|
|
|
|
main_argv = argv;
|
|
|
|
}
|
|
|
|
|
1998-12-02 08:11:37 -08:00
|
|
|
#if !(defined(WIFEXITED) && defined(WEXITSTATUS))
|
|
|
|
/* Assume old-style V7 status word */
|
|
|
|
#define WIFEXITED(status) (((status) & 0xFF) == 0)
|
|
|
|
#define WEXITSTATUS(status) (((status) >> 8) & 0xFF)
|
|
|
|
#endif
|
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
value sys_system_command(value command) /* ML */
|
1995-05-04 03:15:53 -07:00
|
|
|
{
|
1998-12-02 08:11:37 -08:00
|
|
|
int status, retcode;
|
1999-11-29 11:03:05 -08:00
|
|
|
|
|
|
|
enter_blocking_section ();
|
1997-12-10 05:27:48 -08:00
|
|
|
#ifndef _WIN32
|
1998-12-02 08:11:37 -08:00
|
|
|
status = system(String_val(command));
|
|
|
|
if (WIFEXITED(status))
|
|
|
|
retcode = WEXITSTATUS(status);
|
|
|
|
else
|
|
|
|
retcode = 255;
|
1997-12-10 05:27:48 -08:00
|
|
|
#else
|
1998-12-02 08:11:37 -08:00
|
|
|
status = retcode = win32_system(String_val(command));
|
1997-12-10 05:27:48 -08:00
|
|
|
#endif
|
1999-11-29 11:03:05 -08:00
|
|
|
leave_blocking_section ();
|
1998-12-02 08:11:37 -08:00
|
|
|
if (status == -1) sys_error(command);
|
1995-05-04 03:15:53 -07:00
|
|
|
return Val_int(retcode);
|
|
|
|
}
|
|
|
|
|
1998-02-25 02:20:38 -08:00
|
|
|
value sys_time(value unit) /* ML */
|
|
|
|
{
|
|
|
|
#ifdef HAS_TIMES
|
|
|
|
#ifndef CLK_TCK
|
|
|
|
#ifdef HZ
|
|
|
|
#define CLK_TCK HZ
|
|
|
|
#else
|
|
|
|
#define CLK_TCK 60
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
struct tms t;
|
|
|
|
times(&t);
|
|
|
|
return copy_double((double)(t.tms_utime + t.tms_stime) / CLK_TCK);
|
|
|
|
#else
|
|
|
|
/* clock() is standard ANSI C */
|
|
|
|
return copy_double((double)clock() / CLOCKS_PER_SEC);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
1999-11-23 02:49:40 -08:00
|
|
|
value sys_random_seed (value unit) /* ML */
|
1999-07-22 05:59:43 -07:00
|
|
|
{
|
1999-11-23 02:49:40 -08:00
|
|
|
#ifdef HAS_GETTIMEOFDAY
|
|
|
|
struct timeval tv;
|
|
|
|
gettimeofday(&tv, NULL);
|
|
|
|
return Val_int(tv.tv_sec ^ tv.tv_usec);
|
|
|
|
#else
|
|
|
|
return Val_int(time (NULL));
|
|
|
|
#endif
|
1999-07-22 05:59:43 -07:00
|
|
|
}
|
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
value sys_get_config(value unit) /* ML */
|
1996-10-06 09:36:37 -07:00
|
|
|
{
|
1999-11-29 11:03:05 -08:00
|
|
|
CAMLparam0 (); /* unit is unused */
|
|
|
|
CAMLlocal2 (result, ostype);
|
1997-05-26 10:16:31 -07:00
|
|
|
|
|
|
|
ostype = copy_string(OCAML_OS_TYPE);
|
1999-11-29 11:03:05 -08:00
|
|
|
result = alloc_small (2, 0);
|
|
|
|
Field(result, 0) = ostype;
|
|
|
|
Field(result, 1) = Val_long (8 * sizeof(value));
|
|
|
|
CAMLreturn (result);
|
1996-10-06 09:36:37 -07:00
|
|
|
}
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
/* Search path function */
|
|
|
|
|
1996-11-02 10:00:46 -08:00
|
|
|
#ifdef _WIN32
|
1995-08-10 02:16:58 -07:00
|
|
|
|
1998-02-27 06:06:41 -08:00
|
|
|
#define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
|
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
char * searchpath(char * name)
|
1995-05-04 03:15:53 -07:00
|
|
|
{
|
1996-02-22 04:51:45 -08:00
|
|
|
char * fullname;
|
1995-05-04 03:15:53 -07:00
|
|
|
char * path;
|
|
|
|
char * p;
|
|
|
|
char * q;
|
1995-08-10 02:16:58 -07:00
|
|
|
struct stat st;
|
1995-05-04 03:15:53 -07:00
|
|
|
|
1996-11-02 10:00:46 -08:00
|
|
|
if (stat(name, &st) == 0) return name;
|
1995-05-04 03:15:53 -07:00
|
|
|
path = getenv("PATH");
|
1995-08-10 05:18:40 -07:00
|
|
|
if (path == NULL) return 0;
|
1996-11-02 10:00:46 -08:00
|
|
|
fullname = stat_alloc(strlen(name) + strlen(path) + 6);
|
|
|
|
strcpy(fullname, name);
|
|
|
|
strcat(fullname, ".exe");
|
|
|
|
if (stat(fullname, &st) == 0) return fullname;
|
1996-12-10 06:45:58 -08:00
|
|
|
for (p = name; *p != 0; p++) {
|
|
|
|
if (*p == '/' || *p == '\\' || *p == ':') return name;
|
|
|
|
}
|
1995-05-04 03:15:53 -07:00
|
|
|
while(1) {
|
1996-11-02 10:00:46 -08:00
|
|
|
for (p = fullname; *path != 0 && *path != ';'; p++, path++) *p = *path;
|
|
|
|
if (p != fullname && p[-1] != '\\') *p++ = '\\';
|
1996-02-22 04:51:45 -08:00
|
|
|
for (q = name; *q != 0; p++, q++) *p = *q;
|
|
|
|
*p = 0;
|
1998-02-26 04:48:44 -08:00
|
|
|
if (stat(fullname, &st) == 0 && S_ISREG(st.st_mode)) break;
|
1996-11-02 10:00:46 -08:00
|
|
|
strcpy(p, ".exe");
|
1998-02-26 04:48:44 -08:00
|
|
|
if (stat(fullname, &st) == 0 && S_ISREG(st.st_mode)) break;
|
1996-02-22 04:51:45 -08:00
|
|
|
if (*path == 0) return 0;
|
|
|
|
path++;
|
|
|
|
}
|
|
|
|
return fullname;
|
|
|
|
}
|
|
|
|
|
1996-11-02 10:00:46 -08:00
|
|
|
#elif macintosh
|
|
|
|
|
|
|
|
/* We don't need searchpath on the Macintosh because there are no #! scripts */
|
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
char *searchpath (char * name)
|
1996-11-02 10:00:46 -08:00
|
|
|
{
|
1997-05-19 08:42:21 -07:00
|
|
|
return name;
|
1996-11-02 10:00:46 -08:00
|
|
|
}
|
|
|
|
|
1996-02-22 04:51:45 -08:00
|
|
|
#else
|
|
|
|
|
1996-11-02 10:00:46 -08:00
|
|
|
#ifndef S_ISREG
|
|
|
|
#define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
|
|
|
|
#endif
|
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
char * searchpath(char * name)
|
1996-02-22 04:51:45 -08:00
|
|
|
{
|
|
|
|
char * fullname;
|
|
|
|
char * path;
|
|
|
|
char * p;
|
|
|
|
char * q;
|
|
|
|
struct stat st;
|
|
|
|
|
|
|
|
for (p = name; *p != 0; p++) {
|
1996-11-02 10:00:46 -08:00
|
|
|
if (*p == '/') return name;
|
1996-02-22 04:51:45 -08:00
|
|
|
}
|
|
|
|
path = getenv("PATH");
|
|
|
|
if (path == NULL) return 0;
|
1996-11-02 10:00:46 -08:00
|
|
|
fullname = stat_alloc(strlen(name) + strlen(path) + 2);
|
1996-02-22 04:51:45 -08:00
|
|
|
while(1) {
|
1996-11-02 10:00:46 -08:00
|
|
|
for (p = fullname; *path != 0 && *path != ':'; p++, path++) *p = *path;
|
|
|
|
if (p != fullname) *p++ = '/';
|
1996-02-22 04:51:45 -08:00
|
|
|
for (q = name; *q != 0; p++, q++) *p = *q;
|
1995-05-04 03:15:53 -07:00
|
|
|
*p = 0;
|
1996-11-02 10:00:46 -08:00
|
|
|
if (stat(fullname, &st) == 0 && S_ISREG(st.st_mode)) break;
|
1995-05-04 03:15:53 -07:00
|
|
|
if (*path == 0) return 0;
|
|
|
|
path++;
|
|
|
|
}
|
1996-02-22 04:51:45 -08:00
|
|
|
return fullname;
|
1995-05-04 03:15:53 -07:00
|
|
|
}
|
1996-02-22 04:51:45 -08:00
|
|
|
|
1996-11-02 10:00:46 -08:00
|
|
|
#endif /* _WIN32, macintosh, ... */
|
1997-12-10 05:27:48 -08:00
|
|
|
|
1998-02-26 04:48:44 -08:00
|
|
|
/* Wrapper around "system" for Win32 */
|
|
|
|
|
1997-12-10 05:27:48 -08:00
|
|
|
#ifdef _WIN32
|
|
|
|
|
|
|
|
#include <ctype.h>
|
|
|
|
extern char * mktemp(char *);
|
|
|
|
|
|
|
|
int win32_system(char * cmdline)
|
|
|
|
{
|
|
|
|
#define MAX_CMD_LENGTH 256
|
|
|
|
char cmd[MAX_CMD_LENGTH + 16];
|
|
|
|
char template[9];
|
|
|
|
char * tempfile;
|
1998-12-03 03:58:13 -08:00
|
|
|
FILE * fd;
|
|
|
|
int len, i, j, k, retcode;
|
1997-12-10 05:27:48 -08:00
|
|
|
|
|
|
|
len = strlen(cmdline);
|
|
|
|
if (len < 1000) {
|
|
|
|
return system(cmdline);
|
|
|
|
} else {
|
1997-12-10 06:56:28 -08:00
|
|
|
/* Skip initial blanks, if any */
|
|
|
|
for (i = 0; cmdline[i] != 0 && isspace(cmdline[i]); i++) /*nothing*/;
|
1997-12-10 05:27:48 -08:00
|
|
|
/* Copy command name to buffer, stop at first blank */
|
1997-12-10 06:56:28 -08:00
|
|
|
for (j = 0; cmdline[i] != 0 && ! isspace(cmdline[i]); i++) {
|
1997-12-10 05:27:48 -08:00
|
|
|
if (j < MAX_CMD_LENGTH) cmd[j++] = cmdline[i];
|
|
|
|
}
|
|
|
|
/* Save remainder of command line to temp file */
|
|
|
|
strcpy(template, "cmXXXXXX");
|
|
|
|
tempfile = mktemp(template);
|
1998-12-03 03:58:13 -08:00
|
|
|
fd = fopen(tempfile, "w");
|
|
|
|
if (fd == NULL) return -1;
|
|
|
|
for (k = i; k < len; k++)
|
|
|
|
fputc((isspace(cmdline[k]) ? '\n' : cmdline[k]), fd);
|
|
|
|
fclose(fd);
|
1997-12-10 05:27:48 -08:00
|
|
|
/* Add " @tempfile" to the command line */
|
|
|
|
sprintf(cmd + j, " @%s", tempfile);
|
|
|
|
/* Run command */
|
|
|
|
retcode = system(cmd);
|
|
|
|
/* Remove temp file and exit */
|
|
|
|
unlink(tempfile);
|
|
|
|
return retcode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|