#pragma prototyped noticed
/*
*/
#if defined(__STDPP__directive) && defined(__STDPP__hide)
#else
#define utime ______utime
#define utimes ______utimes
#endif
#include <ast.h>
#include <error.h>
#include <tm.h>
#if _win32_botch
#include <ls.h>
#include <utime.h>
#if __CYGWIN__
#include <ast_windows.h>
#endif
#endif
#if defined(__STDPP__directive) && defined(__STDPP__hide)
#else
#endif
#ifndef MAX_PATH
#endif
/*
* these workarounds assume each system call foo() has a _foo() entry
* which is true for __CYGWIN__ and __EMX__ (both gnu based)
*
* the workarounds handle:
*
* (1) .exe suffix inconsistencies
* (3) bogus getpagesize() return values
* (4) a fork() bug that screws up shell fork()+script
*
* NOTE: Not all workarounds can be handled by unix syscall intercepts.
* In particular, { ksh nmake } have workarounds for case-ignorant
* filesystems and { libast } has workarounds for win32 locale info.
*/
extern int _access(const char*, int);
extern unsigned int _alarm(unsigned int);
extern int _close(int);
extern int _link(const char*, const char*);
extern int _open(const char*, int, ...);
extern long _pathconf(const char*, int);
extern int _rename(const char*, const char*);
extern int _unlink(const char*);
#if defined(__EXPORT__)
#define extern __EXPORT__
#endif
#else
#endif
#else
#endif
#else
#endif
#else
#endif
#else
#endif
#if CONVERT
#else
#endif
#else
#endif
#else
#endif
#else
#endif
#else
#endif
#if _lib_spawn_mode
#else
#endif
#else
#endif
#else
#endif
#else
#endif
#else
#endif
#else
#endif
static char*
{
register int c;
while (s > path)
if ((c = *--s) == '.')
return (char*)s + 1;
else if (c == '/' || c == '\\')
break;
return 0;
}
static int
{
char* s;
int n;
int oerrno;
return 0;
if (physical || strlen(path) >= size || !(s = pathcanon(strcpy(buf, path), size, PATH_PHYSICAL|PATH_DOTDOT|PATH_EXISTS)))
strcpy(s, ".exe");
return 1;
}
/*
* return 0 if path is magic, -1 otherwise
* ux!=0 set to 1 if path is unix executable
* ux!=0 also retains errno for -1 return
*/
static int
{
int fd;
int r;
int n;
int m;
int oerrno;
#if CONVERT
#else
#endif
{
#if CONVERT
if (ux)
n = sizeof(buf);
else
#endif
n = 2;
r = (m = sysread(fd, buf, n)) >= 2 && (buf[1] == 0x5a && (buf[0] == 0x4c || buf[0] == 0x4d) || ux && buf[0] == '#' && buf[1] == '!' && (*ux = 1) && !(ux = 0)) ? 0 : -1;
if (ux)
{
if (r)
else
*ux = 0;
}
}
else if (!ux)
r = -1;
{
r = -1;
}
else
{
r = 0;
*ux = 0;
}
return r;
}
extern int
{
int r;
int oerrno;
{
}
return r;
}
#endif
extern unsigned int
alarm(unsigned int s)
{
unsigned int n;
unsigned int r;
static unsigned int a;
if (a <= n)
r = 0;
else
r = a - n;
a = n + s - 1;
(void)sysalarm(s);
return r;
}
#endif
extern int
{
int r;
int oerrno;
{
}
{
{
}
}
return r;
}
#endif
#if _lib_spawn_mode
/*
* can anyone get const prototype args straight?
*/
#include <process.h>
#endif
#if CONVERT
/*
* this intercept converts dos env vars to unix
* we'd rather intercept main but can't twist cc to do it
* getuid() gets ksh to do the right thing and
* that's our main concern
*
* DOSPATHVARS='a b c' convert { a b c }
*/
static int convertinit;
/*
* convertvars[0] names the list of env var names
* convertvars[i] are not converted
*/
static int
convert(register const char* d, const char* s)
{
register const char* t;
register const char* v;
int i;
for (i = 0; i < elementsof(convertvars); i++)
{
for (v = convertvars[i], t = s; *t && *t == *v; t++, v++);
if (*t == '=' && *v == 0)
return 0;
}
for (;;)
{
while (*d == ' ' || *d == '\t')
d++;
if (!*d)
break;
for (t = s; *t && *t == *d; d++, t++);
if (*t == '=' && (*d == ' ' || *d == '\t' || *d == 0))
return t - s + 1;
while (*d && *d != ' ' && *d != '\t')
d++;
}
return 0;
}
getuid(void)
{
register char* d;
register char* s;
register char* t;
register char** e;
int n;
int m;
for (e = environ; s = *e; e++)
if ((n = convert(d, s)) && (m = cygwin_win32_to_posix_path_list_buf_size(s + n)) > 0)
{
if (!(t = malloc(n + m + 1)))
break;
*e = t;
memcpy(t, s, n);
cygwin_win32_to_posix_path_list(s + n, t + n);
}
return sysgetuid();
}
#endif
#ifndef _P_OVERLAY
#endif
static pid_t
{
register char* s;
register char** p;
register char** v;
void* m1;
void* m2;
int oerrno;
int ux;
int n;
int pgrp;
#endif
#if CONVERT
char* d;
char* t;
int m;
#endif
#if DEBUG
static int trace;
#endif
{
/*
* 2004-02-29 cygwin _P_DETACH is useless:
* spawn*() returns 0 instead of the spawned pid
* spawned { pgid sid } are the same as the parent
*/
pgrp = 1;
}
else
pgrp = 0;
#endif
if (!envv)
#if DEBUG
if (!trace)
#endif
{
else
}
return -1;
{
return -1;
}
{
return -1;
#else
ux = 1;
p = (char**)argv;
while (*p++);
{
return -1;
}
m1 = v;
p = v;
*p++ = (char*)path;
*p++ = (char*)path;
if (*argv)
argv++;
while (*p++ = (char*)*argv++);
argv = (char* const*)v;
#endif
}
/*
* the win32 dll search order is
* (1) the directory of path
* (2) .
* (3) /c/(WINNT|WINDOWS)/system32 /c/(WINNT|WINDOWS)
* (4) the directories on $PATH
* there are no cygwin dlls in (3), so if (1) and (2) fail
* to produce the required dlls its up to (4)
*
* the standard allows PATH to be anything once the path
* to an executable is determined; this code ensures that PATH
* contains /bin so that at least the cygwin dll, required
* by all cygwin executables, will be found
*/
if (p = (char**)envv)
{
n = 1;
while (s = *p++)
{
s += 5;
do
{
{
n = 0;
break;
}
} while (s);
if (n)
{
n = 0;
*(p - 1) = tmp;
}
break;
}
if (n)
{
n = p - (char**)envv + 1;
p = (char**)envv;
if (v = (char**)malloc(n * sizeof(char*)))
{
m2 = v;
envv = (char* const*)v;
while (*v++ = *p++);
}
}
#if CONVERT
for (p = (char**)envv; s = *p; p++)
if ((n = convert(d, s)) && (m = cygwin_posix_to_win32_path_list_buf_size(s + n)) > 0)
{
if (!(t = malloc(n + m + 1)))
break;
*p = t;
memcpy(t, s, n);
cygwin_posix_to_win32_path_list(s + n, t + n);
}
#endif
}
#if DEBUG
{
for (n = 0; argv[n]; n++)
if (trace == 'e')
{
for (n = 0; envv[n]; n++)
}
}
#endif
#if _lib_spawn_mode
if (mode != _P_OVERLAY)
{
#endif
}
else
#endif
{
if (pgrp)
setpgid(0, 0);
#endif
}
if (m1)
if (m2)
return pid;
}
extern pid_t
{
}
#endif
#if _lib_spawn_mode
extern pid_t
{
}
#endif
#endif
extern size_t
getpagesize(void)
{
return 64 * 1024;
}
#endif
extern int
{
int r;
int oerrno;
{
}
return r;
}
#endif
/*
* this should intercept the important cases
* dup*() and exec*() fd's will not be intercepted
*/
typedef struct Exe_test_s
{
int test;
} Exe_test_t;
extern int
{
int r;
int oerrno;
{
{
return r;
{
}
return 0;
}
}
}
extern ssize_t
{
exe[fd]->test = n >= 2 && ((unsigned char*)buf)[1] == 0x5a && (((unsigned char*)buf)[0] == 0x4c || ((unsigned char*)buf)[0] == 0x4d) && !lseek(fd, (off_t)0, SEEK_CUR);
}
#endif
extern int
{
int fd;
int mode;
int oerrno;
#endif
{
}
#endif
{
if (!suffix(path) && !fstat(fd, &st) && (exe[fd] || (exe[fd] = (Exe_test_t*)malloc(sizeof(Exe_test_t)))))
{
}
}
#endif
return fd;
}
#endif
extern long
{
return -1;
}
#endif
extern int
{
int r;
int oerrno;
{
}
return r;
}
#endif
extern int
{
int r;
int oerrno;
{
}
return r;
}
#endif
extern int
{
int r;
int oerrno;
{
}
return r;
}
#endif
extern int
{
int r;
int drive;
int mask;
int suffix;
int stop;
int oerrno;
unsigned long base;
static int count = 0;
#if __CYGWIN__
goto try_unlink;
goto try_unlink;
for (;;)
{
hp = CreateFile(path, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL|FILE_FLAG_DELETE_ON_CLOSE, NULL);
if (hp != INVALID_HANDLE_VALUE)
{
return 0;
}
if (GetLastError() != ERROR_FILE_NOT_FOUND)
break;
{
return -1;
}
}
#else
{
return -1;
}
#else
return -1;
#endif
drive = 'C':
#endif
/*
* rename to a `deleted' path just in case the file is open
* otherwise directory readers may choke on phantom entries
*/
{
goto try_delete;
}
goto try_unlink;
tmp[DELETED_DIR_2] = 0;
{
tmp[DELETED_DIR_1] = 0;
{
goto try_unlink;
}
if (r)
goto try_unlink;
errno = 0;
}
{
goto try_delete;
}
#if !__CYGWIN__
{
#if !_win32_botch_access
#endif
goto try_unlink;
}
#endif
do
{
{
goto try_delete;
}
if (++suffix > 0xfff)
suffix = 0;
#if __CYGWIN__
hp = CreateFile(path, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL|FILE_FLAG_DELETE_ON_CLOSE, NULL);
if (hp != INVALID_HANDLE_VALUE)
{
return 0;
}
#endif
}
#endif
#if __CYGWIN__
/*
* cygwin refuses to set st_ctime for some operations
* this rejects that refusal
*/
static void
{
int oerrno;
if (sysstat(path, &fs) || (fs.st_mode & S_IWUSR) || syschmod(path, (fs.st_mode | S_IWUSR) & S_IPERM))
hp = CreateFile(tmp, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
{
GetSystemTime(&st);
}
}
#else
#define ctime_now(p)
#endif
extern int
{
int r;
int oerrno;
{
}
if (!r)
return r;
}
extern int
{
int r;
int oerrno;
{
}
if (!r)
return r;
}
#endif
#endif
/*
* some systems (sun) miss a few functions required by their
* own bsd-like macros
*/
#if !_lib_bzero || defined(bzero)
void
{
memset(b, 0, n);
}
#endif
#if !_lib_getpagesize || defined(getpagesize)
#ifndef OMITTED
#endif
#ifdef _SC_PAGESIZE
#else
#ifndef _AST_PAGESIZE
#endif
#endif
int
{
return _AST_PAGESIZE;
}
#endif
#ifndef OMITTED
#endif
/*
* a few _imp__FUNCTION symbols are needed to avoid
* static link multiple definitions
*/
#ifndef strtod
#endif
#endif
#ifndef OMITTED
#endif