summaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
Diffstat (limited to 'win32')
-rw-r--r--win32/Makefile7
-rw-r--r--win32/config.status4
-rw-r--r--win32/ruby.def8
-rw-r--r--win32/win32.c152
-rw-r--r--win32/win32.h9
5 files changed, 62 insertions, 118 deletions
diff --git a/win32/Makefile b/win32/Makefile
index f84c96bc3f..7573ef62cf 100644
--- a/win32/Makefile
+++ b/win32/Makefile
@@ -18,8 +18,8 @@ LDFLAGS = $(CFLAGS) -Fm
#LDFLAGS = $(CFLAGS) -Fm
XLDFLAGS =
#EXTLIBS =
-LIBS = advapi32.lib wsock32.lib $(EXTLIBS)
-MISSING = crypt.obj alloca.obj win32.obj fnmatch.obj isinf.obj isnan.obj
+LIBS = user32.lib advapi32.lib wsock32.lib $(EXTLIBS)
+MISSING = crypt.obj alloca.obj win32.obj isinf.obj isnan.obj
LDSHARED =
DLDFLAGS =
SOLIBS =
@@ -166,9 +166,6 @@ isinf.obj: missing/isinf.c
isnan.obj: missing/isnan.c
$(CC) -I. $(CFLAGS) $(CPPFLAGS) -c missing/isnan.c
-fnmatch.obj: missing/fnmatch.c
- $(CC) -I. $(CFLAGS) $(CPPFLAGS) -c missing/fnmatch.c
-
memcmp.obj: missing/memcmp.c
$(CC) $(CFLAGS) $(CPPFLAGS) -c missing/memcmp.c
diff --git a/win32/config.status b/win32/config.status
index 9b959ff4bb..6f77f19b01 100644
--- a/win32/config.status
+++ b/win32/config.status
@@ -7,7 +7,7 @@ s%@FFLAGS@%%g
s%@DEFS@%
-DUSE_THREAD -DSIZEOF_INT=4 -DSIZEOF_SHORT=2 -DSIZEOF_LONG=4 -DSIZEOF_VOIDP=4 -DSIZEOF_FLOAT=4 -DSIZEOF_DOUBLE=8 -DHAVE_PROTOTYPES=1 -DHAVE_STDARG_PROTOTYPES=1 -DHAVE_STDLIB_H=1 -DHAVE_LIMITS_H=1 -DHAVE_SYS_FILE_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_ST_RDEV=1 -DGETGROUPS_T=int -DRETSIGTYPE=void -DHAVE_ALLOCA=1 -DHAVE_FMOD=1 -DHAVE_WAITPID=1 -DHAVE_GETCWD=1 -DHAVE_CHSIZE=1 -DHAVE_GETGROUPS=1 -DHAVE_GETLOGIN=1 -DRSHIFT=\(x,y\)\ \(\(x\)\>\>y\) -DFILE_COUNT=_cnt -DDLEXT=\".dll\" -DRUBY_LIB=\"/usr/local/lib/ruby/1.4\" -DRUBY_ARCHLIB=\"/usr/local/lib/ruby/1.4/i386-mswin32\" -DRUBY_PLATFORM=\"i386-mswin32\" %g
s%@LDFLAGS@%%g
-s%@LIBS@%advapi32.lib wsock32.lib%g
+s%@LIBS@%user32.lib advapi32.lib wsock32.lib%g
s%@exec_prefix@%${prefix}%g
s%@prefix@%/usr/local%g
s%@program_transform_name@%s,x,x,%g
@@ -35,7 +35,7 @@ s%@RANLIB@%rem%g
s%@AR@%lib -nologo%g
s%@LN_S@%%g
s%@SET_MAKE@%%g
-s%@LIBOBJS@% crypt.obj alloca.obj win32.obj fnmatch.obj isinf.obj isnan.obj%g
+s%@LIBOBJS@% crypt.obj alloca.obj win32.obj isinf.obj isnan.obj%g
s%@ALLOCA@%%g
s%@DEFAULT_KCODE@%%g
s%@EXEEXT@%.exe%g
diff --git a/win32/ruby.def b/win32/ruby.def
index 1c79697fd7..97ac63c74b 100644
--- a/win32/ruby.def
+++ b/win32/ruby.def
@@ -31,6 +31,7 @@ EXPORTS
rb_eSystemCallError
rb_eZeroDivError
rb_mErrno
+ ruby_nerrs
;eval.c
rb_cProc
ruby_frame
@@ -98,8 +99,6 @@ EXPORTS
definekey
encrypt
crypt
-;missing/fnmatch.c
- fnmatch
;missing/isinf.c
isinf
;missing/isnan.c
@@ -134,6 +133,7 @@ EXPORTS
mygetservbyname
mygetservbyport
myget_osfhandle
+ win32_getcwd
win32_getenv
;array.c
rb_mem_clear
@@ -283,6 +283,7 @@ EXPORTS
rb_funcall
rb_funcall2
rb_funcall3
+ rb_call_super
rb_backtrace
rb_frame_last_func
rb_obj_instance_eval
@@ -326,6 +327,7 @@ EXPORTS
rb_file_s_expand_path
;gc.c
xmalloc
+ xfree
xcalloc
xrealloc
rb_global_variable
@@ -373,7 +375,7 @@ EXPORTS
rb_fdopen
rb_file_open
rb_file_sysopen
- rb_io_synchronized
+ rb_io_synchronized
rb_p
rb_gets
rb_str_setter
diff --git a/win32/win32.c b/win32/win32.c
index a28006ce86..a1e6d25ff3 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -229,7 +229,6 @@ char *getlogin()
struct {
int inuse;
int pid;
- HANDLE oshandle;
FILE *pipe;
} MyPopenRecord[MYPOPENSIZE];
@@ -495,7 +494,7 @@ mypopen (char *cmd, char *mode)
int p[2];
BOOL fRet;
- HANDLE hInFile, hOutFile, hStdin, hStdout;
+ HANDLE hInFile, hOutFile;
LPCSTR lpApplicationName = NULL;
LPTSTR lpCommandLine;
LPTSTR lpCmd2 = NULL;
@@ -509,23 +508,11 @@ mypopen (char *cmd, char *mode)
sa.lpSecurityDescriptor = NULL;
sa.bInheritHandle = TRUE;
- if (!reading) {
- FILE *fp;
-
- fp = (_popen)(cmd, mode);
-
- MyPopenRecord[slot].inuse = TRUE;
- MyPopenRecord[slot].pipe = fp;
- MyPopenRecord[slot].pid = -1;
-
- if (!fp)
- rb_fatal("cannot open pipe \"%s\" (%s)", cmd, strerror(errno));
- return fp;
- }
-
fRet = CreatePipe(&hInFile, &hOutFile, &sa, 2048L);
- if (!fRet)
- rb_fatal("cannot open pipe \"%s\" (%s)", cmd, strerror(errno));
+ if (!fRet) {
+ errno = GetLastError();
+ rb_sys_fail("mypopen: CreatePipe");
+ }
memset(&aStartupInfo, 0, sizeof (STARTUPINFO));
memset(&aProcessInformation, 0, sizeof (PROCESS_INFORMATION));
@@ -533,93 +520,63 @@ mypopen (char *cmd, char *mode)
aStartupInfo.dwFlags = STARTF_USESTDHANDLES;
if (reading) {
- aStartupInfo.hStdInput = GetStdHandle(STD_OUTPUT_HANDLE);//hStdin;
- aStartupInfo.hStdError = INVALID_HANDLE_VALUE;
- //for save
- DuplicateHandle(GetCurrentProcess(), GetStdHandle(STD_OUTPUT_HANDLE),
- GetCurrentProcess(), &hStdout,
- 0, FALSE, DUPLICATE_SAME_ACCESS
- );
- //for redirect
- DuplicateHandle(GetCurrentProcess(), GetStdHandle(STD_INPUT_HANDLE),
- GetCurrentProcess(), &hStdin,
- 0, TRUE, DUPLICATE_SAME_ACCESS
- );
+ aStartupInfo.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
aStartupInfo.hStdOutput = hOutFile;
}
else {
- aStartupInfo.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE); //hStdout;
- aStartupInfo.hStdError = INVALID_HANDLE_VALUE;
- // for save
- DuplicateHandle(GetCurrentProcess(), GetStdHandle(STD_INPUT_HANDLE),
- GetCurrentProcess(), &hStdin,
- 0, FALSE, DUPLICATE_SAME_ACCESS
- );
- //for redirect
- DuplicateHandle(GetCurrentProcess(), GetStdHandle(STD_OUTPUT_HANDLE),
- GetCurrentProcess(), &hStdout,
- 0, TRUE, DUPLICATE_SAME_ACCESS
- );
- aStartupInfo.hStdInput = hInFile;
+ aStartupInfo.hStdInput = hInFile;
+ aStartupInfo.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
}
+ aStartupInfo.hStdError = GetStdHandle(STD_ERROR_HANDLE);
dwCreationFlags = (NORMAL_PRIORITY_CLASS);
lpCommandLine = cmd;
if (NtHasRedirection(cmd) || isInternalCmd(cmd)) {
lpApplicationName = getenv("COMSPEC");
- lpCmd2 = malloc(strlen(lpApplicationName) + 1 + strlen(cmd) + sizeof (" /c "));
- if (lpCmd2 == NULL)
- rb_fatal("Mypopen: malloc failed");
+ lpCmd2 = xmalloc(strlen(lpApplicationName) + 1 + strlen(cmd) + sizeof (" /c "));
sprintf(lpCmd2, "%s %s%s", lpApplicationName, " /c ", cmd);
lpCommandLine = lpCmd2;
}
fRet = CreateProcess(lpApplicationName, lpCommandLine, &sa, &sa,
sa.bInheritHandle, dwCreationFlags, NULL, NULL, &aStartupInfo, &aProcessInformation);
+ errno = GetLastError();
+
+ if (lpCmd2)
+ free(lpCmd2);
if (!fRet) {
CloseHandle(hInFile);
CloseHandle(hOutFile);
- rb_fatal("cannot fork for \"%s\" (%s)", cmd, strerror(errno));
+ return NULL;
}
CloseHandle(aProcessInformation.hThread);
if (reading) {
- HANDLE hDummy;
-
fd = _open_osfhandle((long)hInFile, (_O_RDONLY | pipemode));
CloseHandle(hOutFile);
- DuplicateHandle(GetCurrentProcess(), hStdout,
- GetCurrentProcess(), &hDummy,
- 0, TRUE, (DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE)
- );
}
else {
- HANDLE hDummy;
-
- fd = _open_osfhandle((long)hOutFile, (_O_WRONLY | pipemode));
+ fd = _open_osfhandle((long)hOutFile, (_O_WRONLY | pipemode));
CloseHandle(hInFile);
- DuplicateHandle(GetCurrentProcess(), hStdin,
- GetCurrentProcess(), &hDummy,
- 0, TRUE, (DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE)
- );
}
- if (fd == -1)
- rb_fatal("cannot open pipe \"%s\" (%s)", cmd, strerror(errno));
-
-
- if ((fp = (FILE *) fdopen(fd, mode)) == NULL)
- return NULL;
+ if (fd == -1) {
+ CloseHandle(reading ? hInFile : hOutFile);
+ CloseHandle(aProcessInformation.hProcess);
+ rb_sys_fail("mypopen: _open_osfhandle");
+ }
- if (lpCmd2)
- free(lpCmd2);
+ if ((fp = (FILE *) fdopen(fd, mode)) == NULL) {
+ _close(fd);
+ CloseHandle(aProcessInformation.hProcess);
+ rb_sys_fail("mypopen: fdopen");
+ }
MyPopenRecord[slot].inuse = TRUE;
MyPopenRecord[slot].pipe = fp;
- MyPopenRecord[slot].oshandle = (reading ? hInFile : hOutFile);
MyPopenRecord[slot].pid = (int)aProcessInformation.hProcess;
return fp;
}
@@ -671,14 +628,13 @@ mypclose(FILE *fp)
}
}
}
+ CloseHandle((HANDLE)MyPopenRecord[i].pid);
#endif
-
//
// close the pipe
//
- // Closehandle() is done by fclose().
- //CloseHandle(MyPopenRecord[i].oshandle);
+
fflush(fp);
fclose(fp);
@@ -1218,12 +1174,6 @@ NtMakeCmdVector (char *cmdline, char ***vec, int InputCmd)
// UNIX compatible directory access functions for NT
//
-//
-// File names are converted to lowercase if the
-// CONVERT_TO_LOWER_CASE variable is defined.
-//
-
-#define CONVERT_TO_LOWER_CASE
#define PATHLEN 1024
//
@@ -1246,34 +1196,19 @@ opendir(char *filename)
char root[PATHLEN];
char volname[PATHLEN];
DWORD serial, maxname, flags;
- BOOL downcase;
- char *dummy;
//
// check to see if we\'ve got a directory
//
- if (stat (filename, &sbuf) < 0 ||
- sbuf.st_mode & _S_IFDIR == 0) {
+ if ((stat (filename, &sbuf) < 0 ||
+ sbuf.st_mode & _S_IFDIR == 0) &&
+ (!isalpha(filename[0]) || filename[1] != ':' || filename[2] != '\0' ||
+ ((1 << (filename[0] & 0x5f) - 'A') & GetLogicalDrives()) == 0)) {
return NULL;
}
//
- // check out the file system characteristics
- //
- if (GetFullPathName(filename, PATHLEN, root, &dummy)) {
- if (dummy = strchr(root, '\\'))
- *++dummy = '\0';
- if (GetVolumeInformation(root, volname, PATHLEN,
- &serial, &maxname, &flags, 0, 0)) {
- downcase = !(flags & FS_CASE_SENSITIVE);
- }
- }
- else {
- downcase = TRUE;
- }
-
- //
// Get us a DIR structure
//
@@ -1287,7 +1222,7 @@ opendir(char *filename)
strcpy(scanname, filename);
- if (index("/\\", *(scanname + strlen(scanname) - 1)) == NULL)
+ if (index("/\\:", *CharPrev(scanname, scanname + strlen(scanname))) == NULL)
strcat(scanname, "/*");
else
strcat(scanname, "*");
@@ -1309,8 +1244,6 @@ opendir(char *filename)
idx = strlen(FindData.cFileName)+1;
p->start = ALLOC_N(char, idx);
strcpy (p->start, FindData.cFileName);
- if (downcase)
- strlwr(p->start);
p->nfiles++;
//
@@ -1334,8 +1267,6 @@ opendir(char *filename)
rb_fatal ("opendir: malloc failed!\n");
}
strcpy(&p->start[idx], FindData.cFileName);
- if (downcase)
- strlwr(&p->start[idx]);
p->nfiles++;
idx += len+1;
}
@@ -1609,7 +1540,7 @@ typedef struct {
#endif /* defined (_MT) && !defined (DLL_FOR_WIN32S) */
} ioinfo;
-EXTERN_C ioinfo * __pioinfo[];
+EXTERN_C _CRTIMP ioinfo * __pioinfo[];
#define IOINFO_L2E 5
#define IOINFO_ARRAY_ELTS (1 << IOINFO_L2E)
@@ -1617,6 +1548,7 @@ EXTERN_C ioinfo * __pioinfo[];
#define _osfile(i) (_pioinfo(i)->osfile)
#define FOPEN 0x01 /* file handle open */
+#define FNOINHERIT 0x10 /* file handle opened O_NOINHERIT */
#define FAPPEND 0x20 /* file handle opened O_APPEND */
#define FDEV 0x40 /* file handle refers to device */
#define FTEXT 0x80 /* file handle is in text mode */
@@ -1636,6 +1568,9 @@ my_open_osfhandle(long osfhandle, int flags)
if (flags & O_TEXT)
fileflags |= FTEXT;
+ if (flags & O_NOINHERIT)
+ fileflags |= FNOINHERIT;
+
/* attempt to allocate a C Runtime file handle */
if ((fh = _alloc_osfhnd()) == -1) {
errno = EMFILE; /* too many open files */
@@ -1687,7 +1622,8 @@ myfdopen (int fd, const char *mode)
void
myfdclose(FILE *fp)
{
- fclose(fp);
+ _free_osfhnd(fileno(fp));
+ fclose(fp);
}
@@ -1829,6 +1765,10 @@ myselect (int nfds, fd_set *rd, fd_set *wr, fd_set *ex,
if (!NtSocketsInitialized++) {
StartSockets();
}
+ if (nfds == 0 && timeout) {
+ Sleep(timeout->tv_sec * 1000 + timeout->tv_usec / 1000);
+ return 0;
+ }
if ((r = select (nfds, rd, wr, ex, timeout)) == SOCKET_ERROR) {
errno = WSAGetLastError();
switch (errno) {
@@ -2266,7 +2206,7 @@ gettimeofday(struct timeval *tv, struct timezone *tz)
}
char *
-getcwd(buffer, size)
+win32_getcwd(buffer, size)
char *buffer;
int size;
{
@@ -2281,7 +2221,7 @@ getcwd(buffer, size)
return NULL;
}
- for (bp = buffer; *bp != '\0'; bp++) {
+ for (bp = buffer; *bp != '\0'; bp = CharNext(bp)) {
if (*bp == '\\') {
*bp = '/';
}
diff --git a/win32/win32.h b/win32/win32.h
index 04cb192c43..cbcf4e8117 100644
--- a/win32/win32.h
+++ b/win32/win32.h
@@ -87,7 +87,7 @@
#undef leave
#if defined(__cplusplus)
-}
+extern "C++" {
#endif
#include <stdio.h>
@@ -103,7 +103,7 @@
#include <malloc.h>
#if defined(__cplusplus)
-extern "C" {
+}
#endif
#define UIDTYPE int
@@ -387,6 +387,11 @@ extern char *mystrerror(int);
#endif
#define get_osfhandle myget_osfhandle
+#ifdef getcwd
+#undef getcwd
+#endif
+#define getcwd win32_getcwd
+
#ifdef getenv
#undef getenv
#endif