summaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
authoreban <eban@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2000-05-13 16:13:31 +0000
committereban <eban@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2000-05-13 16:13:31 +0000
commit6d53b692ab91c8817736cdec78b388e6e4990806 (patch)
tree3a84f886c14e2a9a8fe65c664b4f4805e2cbc2d4 /win32
parent9da4f78db46764be6dae5e7e83ff48cbecb3fb23 (diff)
support mingw32.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@688 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'win32')
-rw-r--r--win32/win32.c37
-rw-r--r--win32/win32.h7
2 files changed, 37 insertions, 7 deletions
diff --git a/win32/win32.c b/win32/win32.c
index a1e6d25ff3..6cafce993f 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -1169,7 +1169,7 @@ NtMakeCmdVector (char *cmdline, char ***vec, int InputCmd)
}
-#if 1
+#if !defined __MINGW32__
//
// UNIX compatible directory access functions for NT
//
@@ -1183,7 +1183,7 @@ NtMakeCmdVector (char *cmdline, char ***vec, int InputCmd)
//
DIR *
-opendir(char *filename)
+opendir(const char *filename)
{
DIR *p;
long len;
@@ -1524,8 +1524,8 @@ valid_filename(char *s)
// if we can prevent perl from trying to do stdio on sockets.
//
-EXTERN_C int __cdecl _alloc_osfhnd(void);
-EXTERN_C int __cdecl _set_osfhnd(int fh, long value);
+//EXTERN_C int __cdecl _alloc_osfhnd(void);
+//EXTERN_C int __cdecl _set_osfhnd(int fh, long value);
EXTERN_C void __cdecl _lock_fhandle(int);
EXTERN_C void __cdecl _unlock_fhandle(int);
EXTERN_C void __cdecl _unlock(int);
@@ -1534,18 +1534,23 @@ typedef struct {
long osfhnd; /* underlying OS file HANDLE */
char osfile; /* attributes of file (e.g., open in text mode?) */
char pipech; /* one char buffer for handles opened on pipes */
-#if defined (_MT) && !defined (DLL_FOR_WIN32S)
int lockinitflag;
CRITICAL_SECTION lock;
-#endif /* defined (_MT) && !defined (DLL_FOR_WIN32S) */
} ioinfo;
+#if !defined _CRTIMP
+#define _CRTIMP __declspec(dllimport)
+#endif
+
EXTERN_C _CRTIMP ioinfo * __pioinfo[];
#define IOINFO_L2E 5
#define IOINFO_ARRAY_ELTS (1 << IOINFO_L2E)
#define _pioinfo(i) (__pioinfo[i >> IOINFO_L2E] + (i & (IOINFO_ARRAY_ELTS - 1)))
-#define _osfile(i) (_pioinfo(i)->osfile)
+
+#define _osfhnd(i) (_pioinfo(i)->osfhnd)
+#define _osfile(i) (_pioinfo(i)->osfile)
+#define _pipech(i) (_pioinfo(i)->pipech)
#define FOPEN 0x01 /* file handle open */
#define FNOINHERIT 0x10 /* file handle opened O_NOINHERIT */
@@ -1553,6 +1558,20 @@ EXTERN_C _CRTIMP ioinfo * __pioinfo[];
#define FDEV 0x40 /* file handle refers to device */
#define FTEXT 0x80 /* file handle is in text mode */
+#define _set_osfhnd(fh, osfh) (void)(_osfhnd(fh) = osfh)
+
+static int
+_alloc_osfhnd(void)
+{
+ HANDLE hF = CreateFile("NUL", 0, 0, NULL, OPEN_ALWAYS, 0, NULL);
+ int fh = _open_osfhandle((long)hF, 0);
+ CloseHandle(hF);
+ if (fh == -1)
+ return fh;
+ EnterCriticalSection(&(_pioinfo(fh)->lock));
+ return fh;
+}
+
static int
my_open_osfhandle(long osfhandle, int flags)
{
@@ -1622,7 +1641,9 @@ myfdopen (int fd, const char *mode)
void
myfdclose(FILE *fp)
{
+#if !defined __MINGW32__
_free_osfhnd(fileno(fp));
+#endif
fclose(fp);
}
@@ -1639,7 +1660,9 @@ char *
mystrerror(int e)
{
static char buffer[512];
+#if !defined __MINGW32__
extern int sys_nerr;
+#endif
DWORD source = 0;
if (e < 0 || e > sys_nerr) {
diff --git a/win32/win32.h b/win32/win32.h
index cbcf4e8117..0bfe711a79 100644
--- a/win32/win32.h
+++ b/win32/win32.h
@@ -9,6 +9,7 @@
*
*/
+#undef EXTERN
#if defined(IMPORT)
#define EXTERN extern __declspec(dllimport)
#elif defined(EXPORT)
@@ -163,6 +164,12 @@ extern "C++" {
#define strncasecmp _strnicmp
/* these are defined in nt.c */
+#ifdef __MINGW32__
+struct timezone {
+ int tz_minuteswest;
+ int tz_dsttime;
+};
+#endif
extern int NtMakeCmdVector(char *, char ***, int);
extern void NtInitialize(int *, char ***);
extern char *NtGetLib(void);