X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=win32%2Fwin32io.c;h=a3981c000a889fbaedcdde49774a20280ecd4961;hb=3e2a970dfeb55332005c7648ee670aa10bb9b414;hp=8e74608d3c71171d6399df8055f990f46ac346c3;hpb=5833650dbdc313b4d5a31e4d3a0c7cbd0afff7f2;p=p5sagit%2Fp5-mst-13.2.git diff --git a/win32/win32io.c b/win32/win32io.c index 8e74608..a3981c0 100644 --- a/win32/win32io.c +++ b/win32/win32io.c @@ -10,11 +10,15 @@ #include #include "EXTERN.h" #include "perl.h" + +#ifdef PERLIO_LAYERS + #include "perliol.h" #define NO_XSLOCKS #include "XSUB.h" + /* Bottom-most level for Win32 case */ typedef struct @@ -48,9 +52,9 @@ PerlIOWin32_fileno(pTHX_ PerlIO *f) } IV -PerlIOWin32_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg) +PerlIOWin32_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg, PerlIO_funcs *tab) { - IV code = PerlIOBase_pushed(aTHX_ f,mode,arg); + IV code = PerlIOBase_pushed(aTHX_ f,mode,arg,tab); if (*PerlIONext(f)) { PerlIOWin32 *s = PerlIOSelf(f,PerlIOWin32); @@ -179,7 +183,7 @@ PerlIOWin32_open(pTHX_ PerlIO_funcs *self, PerlIO_list_t *layers, IV n, const ch } } if (h != INVALID_HANDLE_VALUE) - fd = win32_open_osfhandle((long) h, PerlIOUnix_oflags(tmode)); + fd = win32_open_osfhandle((intptr_t) h, PerlIOUnix_oflags(tmode)); if (fd >= 0) { PerlIOWin32 *s; @@ -252,9 +256,13 @@ PerlIOWin32_seek(pTHX_ PerlIO *f, Off_t offset, int whence) { static const DWORD where[3] = { FILE_BEGIN, FILE_CURRENT, FILE_END }; PerlIOWin32 *s = PerlIOSelf(f,PerlIOWin32); - DWORD high = (sizeof(offset) > sizeof(DWORD)) ? (DWORD)(offset >> 32) : 0; +#if Off_t_size >= 8 + DWORD high = (DWORD)(offset >> 32); +#else + DWORD high = 0; +#endif DWORD low = (DWORD) offset; - DWORD res = SetFilePointer(s->h,low,&high,where[whence]); + DWORD res = SetFilePointer(s->h,(LONG)low,(LONG *)&high,where[whence]); if (res != 0xFFFFFFFF || GetLastError() != NO_ERROR) { return 0; @@ -270,10 +278,14 @@ PerlIOWin32_tell(pTHX_ PerlIO *f) { PerlIOWin32 *s = PerlIOSelf(f,PerlIOWin32); DWORD high = 0; - DWORD res = SetFilePointer(s->h,0,&high,FILE_CURRENT); + DWORD res = SetFilePointer(s->h,0,(LONG *)&high,FILE_CURRENT); if (res != 0xFFFFFFFF || GetLastError() != NO_ERROR) { +#if Off_t_size >= 8 return ((Off_t) high << 32) | res; +#else + return res; +#endif } return (Off_t) -1; } @@ -284,13 +296,19 @@ PerlIOWin32_close(pTHX_ PerlIO *f) PerlIOWin32 *s = PerlIOSelf(f,PerlIOWin32); if (s->refcnt == 1) { - if (CloseHandle(s->h)) + IV code = 0; +#if 0 + /* This does not do pipes etc. correctly */ + if (!CloseHandle(s->h)) { s->h = INVALID_HANDLE_VALUE; return -1; } +#else + PerlIOBase(f)->flags &= ~PERLIO_F_OPEN; + return win32_close(s->fd); +#endif } - PerlIOBase(f)->flags &= ~PERLIO_F_OPEN; return 0; } @@ -299,15 +317,15 @@ PerlIOWin32_dup(pTHX_ PerlIO *f, PerlIO *o, CLONE_PARAMS *params, int flags) { PerlIOWin32 *os = PerlIOSelf(f,PerlIOWin32); HANDLE proc = GetCurrentProcess(); - HANDLE new; + HANDLE new; if (DuplicateHandle(proc, os->h, proc, &new, 0, FALSE, DUPLICATE_SAME_ACCESS)) { char mode[8]; - int fd = win32_open_osfhandle((long) new, PerlIOUnix_oflags(PerlIO_modestr(o,mode))); - if (fd >= 0) + int fd = win32_open_osfhandle((intptr_t) new, PerlIOUnix_oflags(PerlIO_modestr(o,mode))); + if (fd >= 0) { f = PerlIOBase_dup(aTHX_ f, o, params, flags); - if (f) + if (f) { PerlIOWin32 *fs = PerlIOSelf(f,PerlIOWin32); fs->h = new; @@ -330,13 +348,15 @@ PerlIOWin32_dup(pTHX_ PerlIO *f, PerlIO *o, CLONE_PARAMS *params, int flags) return f; } -PerlIO_funcs PerlIO_win32 = { +PERLIO_FUNCS_DECL(PerlIO_win32) = { + sizeof(PerlIO_funcs), "win32", sizeof(PerlIOWin32), PERLIO_K_RAW, PerlIOWin32_pushed, PerlIOWin32_popped, PerlIOWin32_open, + PerlIOBase_binmode, NULL, /* getarg */ PerlIOWin32_fileno, PerlIOWin32_dup, @@ -359,5 +379,5 @@ PerlIO_funcs PerlIO_win32 = { NULL, /* set_ptrcnt */ }; - +#endif