Make work, mostly, on Windows --- temporary files are now created in the
right place, creat() isn't used because it doesn't work, partial file read/writes work, etc.
This commit is contained in:
parent
1654700314
commit
cb37502a23
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include "system.h"
|
||||
|
||||
extern File *_get_entry();
|
||||
|
@ -23,11 +24,11 @@ sys_open(path, flag, filep)
|
|||
return 0;
|
||||
switch (flag) {
|
||||
case OP_READ:
|
||||
if ((fd = open(path, 0)) < 0)
|
||||
if ((fd = open(path, O_RDONLY|O_BINARY)) < 0)
|
||||
return 0;
|
||||
break;
|
||||
case OP_APPEND:
|
||||
if ((fd = open(path, 1)) < 0) {
|
||||
if ((fd = open(path, O_WRONLY|O_BINARY)) < 0) {
|
||||
if (access(path, 0) == 0)
|
||||
return 0;
|
||||
}
|
||||
|
@ -40,7 +41,7 @@ sys_open(path, flag, filep)
|
|||
}
|
||||
/* Fall through */
|
||||
case OP_WRITE:
|
||||
if ((fd = creat(path, 0666)) < 0)
|
||||
if ((fd = open(path, O_CREAT|O_WRONLY|O_BINARY, 0666)) < 0)
|
||||
return 0;
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -7,12 +7,24 @@
|
|||
#include <unistd.h>
|
||||
#include "system.h"
|
||||
|
||||
int
|
||||
sys_read(fp, bufptr, bufsiz, pnbytes)
|
||||
File *fp;
|
||||
char *bufptr;
|
||||
int bufsiz, *pnbytes;
|
||||
int sys_read(File* fp, char* bufptr, int bufsiz, int* pnbytes)
|
||||
{
|
||||
if (! fp) return 0;
|
||||
return (*pnbytes = read(fp->o_fd, bufptr, bufsiz)) >= 0;
|
||||
if (!fp)
|
||||
return 0;
|
||||
|
||||
*pnbytes = 0;
|
||||
while (bufsiz != 0)
|
||||
{
|
||||
int len = read(fp->o_fd, bufptr, bufsiz);
|
||||
if (len < 0)
|
||||
return 0;
|
||||
if (len == 0)
|
||||
return *pnbytes != 0;
|
||||
|
||||
*pnbytes += len;
|
||||
bufptr += len;
|
||||
bufsiz -= len;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -7,12 +7,21 @@
|
|||
#include <unistd.h>
|
||||
#include "system.h"
|
||||
|
||||
int
|
||||
sys_write(fp, bufptr, nbytes)
|
||||
File *fp;
|
||||
char *bufptr;
|
||||
int nbytes;
|
||||
int sys_write(File* fp, char* bufptr, int nbytes)
|
||||
{
|
||||
if (! fp) return 0;
|
||||
return write(fp->o_fd, bufptr, nbytes) == nbytes;
|
||||
if (!fp)
|
||||
return 0;
|
||||
|
||||
while (nbytes != 0)
|
||||
{
|
||||
int len = write(fp->o_fd, bufptr, nbytes);
|
||||
if (len < 0)
|
||||
return 0;
|
||||
|
||||
bufptr += len;
|
||||
nbytes -= len;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -54,12 +54,22 @@ int setfiles(trf *phase) {
|
|||
} else {
|
||||
gr_init(&pathname) ;
|
||||
if ( !phase->t_keep && !t_flag ) {
|
||||
/* Unix temporary directory. */
|
||||
char* tmpdir = getenv("TMPDIR");
|
||||
/* Fallback: Windows, running under MSYS2. */
|
||||
if (!tmpdir)
|
||||
tmpdir = getenv("temp");
|
||||
/* Fallback: Windows, running natively. */
|
||||
if (!tmpdir)
|
||||
tmpdir = getenv("TEMP");
|
||||
/* Fallback: Hard-coded directory. */
|
||||
if (!tmpdir)
|
||||
tmpdir = "/tmp";
|
||||
gr_cat(&pathname, tmpdir);
|
||||
gr_cat(&pathname, "/Ack-XXXXXX");
|
||||
mkstemp(pathname.gr_string);
|
||||
int fd = mkstemp(pathname.gr_string);
|
||||
close(fd);
|
||||
remove(pathname.gr_string);
|
||||
out.p_keep=NO ;
|
||||
} else {
|
||||
if ( !p_basename ) {
|
||||
|
|
|
@ -56,10 +56,7 @@ int main(int argc, char** argv)
|
|||
}
|
||||
if (callname)
|
||||
{
|
||||
if (machine)
|
||||
{
|
||||
fuerror("can not produce code for both %s and %s", callname, machine);
|
||||
}
|
||||
if (!machine)
|
||||
machine = callname;
|
||||
}
|
||||
if (!machine && !(machine = getenv("ACKM")))
|
||||
|
@ -329,6 +326,8 @@ static void firstarg(char* argp)
|
|||
register char* name;
|
||||
|
||||
name = strrchr(argp, '/');
|
||||
if (!name)
|
||||
name = strrchr(argp, '\\');
|
||||
if (name && *(name + 1))
|
||||
{
|
||||
name++;
|
||||
|
|
|
@ -141,6 +141,7 @@ static void intrf(void) {
|
|||
new->t_stdin= YES ;
|
||||
} else
|
||||
if ( strcmp(ty_name,STD_OUT)==0 ) {
|
||||
fprintf(stderr, "setting stdout for %s\n", new->t_name);
|
||||
if ( new->t_stdout ) twice=YES ;
|
||||
new->t_stdout= YES ;
|
||||
} else
|
||||
|
|
|
@ -23,7 +23,7 @@ static char rcs_id[] = "$Id$";
|
|||
|
||||
#define ARG_MORE 40 /* The size of args chunks to allocate */
|
||||
|
||||
static int run_exec(trf*, const char*);
|
||||
static int run_exec(trf*);
|
||||
static void x_arg(char*);
|
||||
|
||||
static char** arglist; /* The first argument */
|
||||
|
@ -81,11 +81,11 @@ int runphase(trf* phase)
|
|||
x_arg(l_content(*elem));
|
||||
}
|
||||
x_arg((char*)0);
|
||||
result = run_exec(phase, prog);
|
||||
result = run_exec(phase);
|
||||
return result;
|
||||
}
|
||||
|
||||
static int run_exec(trf* phase, const char* prog)
|
||||
static int run_exec(trf* phase)
|
||||
{
|
||||
int status, child, waitchild;
|
||||
int oldstdin = -1;
|
||||
|
@ -101,7 +101,7 @@ static int run_exec(trf* phase, const char* prog)
|
|||
|
||||
oldstdin = dup(0);
|
||||
close(0);
|
||||
if (open(in.p_path, 0) != 0)
|
||||
if (open(in.p_path, O_RDONLY|O_BINARY) != 0)
|
||||
{
|
||||
error("cannot open %s", in.p_path);
|
||||
exit(1);
|
||||
|
@ -111,13 +111,11 @@ static int run_exec(trf* phase, const char* prog)
|
|||
if (phase->t_stdout)
|
||||
{
|
||||
if (!out.p_path)
|
||||
{
|
||||
fatal("no output file for %s", phase->t_name);
|
||||
}
|
||||
|
||||
oldstdout = dup(1);
|
||||
close(1);
|
||||
if (creat(out.p_path, 0666) != 1)
|
||||
if (open(out.p_path, O_CREAT|O_WRONLY|O_BINARY, 0666) != 1)
|
||||
{
|
||||
close(1);
|
||||
dup(2);
|
||||
|
@ -126,7 +124,7 @@ static int run_exec(trf* phase, const char* prog)
|
|||
}
|
||||
}
|
||||
|
||||
status = sys_system(prog, arglist);
|
||||
status = sys_system(phase->t_prog, (const char* const*) arglist);
|
||||
|
||||
if (oldstdin != -1)
|
||||
{
|
||||
|
@ -137,7 +135,7 @@ static int run_exec(trf* phase, const char* prog)
|
|||
|
||||
if (oldstdout != -1)
|
||||
{
|
||||
close(1);
|
||||
int i = close(1);
|
||||
dup2(oldstdout, 1);
|
||||
close(oldstdout);
|
||||
}
|
||||
|
@ -145,7 +143,7 @@ static int run_exec(trf* phase, const char* prog)
|
|||
if (status)
|
||||
{
|
||||
if (status & 0177)
|
||||
error("%s died with signal %d", prog, status & 0177);
|
||||
error("%s died with signal %d", phase->t_prog, status & 0177);
|
||||
|
||||
/* The assumption is that processes voluntarely
|
||||
dying with a non-zero status already produced
|
||||
|
|
Loading…
Reference in a new issue