From: Nick Ing-Simmons Date: Sat, 16 Jun 2001 16:44:35 +0000 (+0000) Subject: Work-in-progress win32 layer semi-functional, checking X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0c4128adc5f62cd332ae4fa5bc8999c95d611d36;p=p5sagit%2Fp5-mst-13.2.git Work-in-progress win32 layer semi-functional, checking for UNIX breakage. p4raw-id: //depot/perlio@10632 --- diff --git a/perlio.c b/perlio.c index de16b2b..a3da82e 100644 --- a/perlio.c +++ b/perlio.c @@ -764,10 +764,16 @@ PerlIO_default_layers(pTHX) if (!PerlIO_def_layerlist) { const char *s = (PL_tainting) ? Nullch : PerlEnv_getenv("PERLIO"); - PerlIO_def_layerlist = PerlIO_list_alloc(); - - PerlIO_define_layer(aTHX_ &PerlIO_raw); + PerlIO_funcs *osLayer = &PerlIO_unix; + PerlIO_def_layerlist = PerlIO_list_alloc(); +#ifdef WIN32 + osLayer = &PerlIO_win32; PerlIO_define_layer(aTHX_ &PerlIO_unix); +#else + osLayer = &PerlIO_unix; +#endif + PerlIO_define_layer(aTHX_ osLayer); + PerlIO_define_layer(aTHX_ &PerlIO_raw); PerlIO_define_layer(aTHX_ &PerlIO_perlio); PerlIO_define_layer(aTHX_ &PerlIO_stdio); PerlIO_define_layer(aTHX_ &PerlIO_crlf); @@ -776,7 +782,7 @@ PerlIO_default_layers(pTHX) #endif PerlIO_define_layer(aTHX_ &PerlIO_utf8); PerlIO_define_layer(aTHX_ &PerlIO_byte); - PerlIO_list_push(PerlIO_def_layerlist,PerlIO_find_layer(aTHX_ PerlIO_unix.name,0,0),&PL_sv_undef); + PerlIO_list_push(PerlIO_def_layerlist,PerlIO_find_layer(aTHX_ osLayer->name,0,0),&PL_sv_undef); if (s) { PerlIO_parse_layers(aTHX_ PerlIO_def_layerlist,s); @@ -1887,6 +1893,8 @@ int PerlIOUnix_oflags(const char *mode) { int oflags = -1; + if (*mode == 'I' || *mode == '#') + mode++; switch(*mode) { case 'r': @@ -2617,7 +2625,7 @@ PerlIOBuf_open(pTHX_ PerlIO_funcs *self, PerlIO_list_t *layers, IV n, const char if (*mode == 'I') { init = 1; - mode++; + /* mode++; */ } f = (*tab->Open)(aTHX_ tab, layers, n-1, mode,fd,imode,perm,NULL,narg,args); if (f) diff --git a/perliol.h b/perliol.h index e9f6a97..b659de0 100644 --- a/perliol.h +++ b/perliol.h @@ -107,7 +107,9 @@ EXT PerlIO_funcs PerlIO_pending; #ifdef HAS_MMAP EXT PerlIO_funcs PerlIO_mmap; #endif - +#ifdef WIN32 +EXT PerlIO_funcs PerlIO_win32; +#endif extern PerlIO *PerlIO_allocate(pTHX); extern SV *PerlIO_arg_fetch(PerlIO_list_t *av,IV n); #define PerlIOArg PerlIO_arg_fetch(layers,n) @@ -169,6 +171,8 @@ extern STDCHAR *PerlIOBuf_get_ptr (PerlIO *f); extern SSize_t PerlIOBuf_get_cnt (PerlIO *f); extern void PerlIOBuf_set_ptrcnt (PerlIO *f, STDCHAR *ptr, SSize_t cnt); +extern int PerlIOUnix_oflags (const char *mode); + /*--------------------------------------------------------------------------------------*/ #endif /* _PERLIOL_H */ diff --git a/win32/win32io.c b/win32/win32io.c index e75919f..b707172 100644 --- a/win32/win32io.c +++ b/win32/win32io.c @@ -10,7 +10,7 @@ #include #include "EXTERN.h" #include "perl.h" -#include "perllio.h" +#include "perliol.h" #define NO_XSLOCKS #include "XSUB.h" @@ -131,7 +131,7 @@ PerlIOWin32_open(pTHX_ PerlIO_funcs *self, PerlIO_list_t *layers, IV n, const ch { mode++; } - if (*mode || oflags == -1) + if (*mode || create == -1) { SETERRNO(EINVAL,LIB$_INVARG); return NULL; @@ -142,7 +142,7 @@ PerlIOWin32_open(pTHX_ PerlIO_funcs *self, PerlIO_list_t *layers, IV n, const ch if (h == INVALID_HANDLE_VALUE) { if (create == TRUNCATE_EXISTING) - h = CreateFile(path,access,share = OPEN_ALWAYS,NULL,create,attr,NULL); + h = CreateFile(path,access,share,NULL,(create = OPEN_ALWAYS),attr,NULL); } } else @@ -160,32 +160,41 @@ PerlIOWin32_open(pTHX_ PerlIO_funcs *self, PerlIO_list_t *layers, IV n, const ch *f = &s->base; return f; } - if (*mode == 'I') + } + if (*mode == 'I') + { + mode++; + switch(fd) { - mode++; - switch(fd) - { - case 0: - h = GetStandardHandle(STD_INPUT_HANDLE); - break; - case 1: - h = GetStandardHandle(STD_OUTPUT_HANDLE); - break; - case 2: - h = GetStandardHandle(STD_ERROR_HANDLE); - break; - } + case 0: + h = GetStdHandle(STD_INPUT_HANDLE); + break; + case 1: + h = GetStdHandle(STD_OUTPUT_HANDLE); + break; + case 2: + h = GetStdHandle(STD_ERROR_HANDLE); + break; } } } if (h != INVALID_HANDLE_VALUE) + fd = win32_open_osfhandle((long) h, PerlIOUnix_oflags(tmode)); + if (fd >= 0) { PerlIOWin32 *s; if (!f) f = PerlIO_allocate(aTHX); s = PerlIOSelf(PerlIO_push(aTHX_ f,self,tmode,PerlIOArg),PerlIOWin32); - s->ioh = h; + s->h = h; + s->fd = fd; s->refcnt = 1; + if (fd >= 0) + { + fdtable[fd] = s; + if (fd > max_open_fd) + max_open_fd = fd; + } return f; } if (f) @@ -202,7 +211,7 @@ PerlIOWin32_read(PerlIO *f, void *vbuf, Size_t count) DWORD len; if (!(PerlIOBase(f)->flags & PERLIO_F_CANREAD)) return 0; - if (ReadFile(s->h,vbuf,count,&len,NULL) + if (ReadFile(s->h,vbuf,count,&len,NULL)) { return len; } @@ -227,7 +236,7 @@ PerlIOWin32_write(PerlIO *f, const void *vbuf, Size_t count) { PerlIOWin32 *s = PerlIOSelf(f,PerlIOWin32); DWORD len; - if (WriteFile(s->h,vbuf,count,&len,NULL) + if (WriteFile(s->h,vbuf,count,&len,NULL)) { return len; }