for UNIX breakage.
p4raw-id: //depot/perlio@10632
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);
#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);
PerlIOUnix_oflags(const char *mode)
{
int oflags = -1;
+ if (*mode == 'I' || *mode == '#')
+ mode++;
switch(*mode)
{
case 'r':
if (*mode == 'I')
{
init = 1;
- mode++;
+ /* mode++; */
}
f = (*tab->Open)(aTHX_ tab, layers, n-1, mode,fd,imode,perm,NULL,narg,args);
if (f)
#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)
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 */
#include <sys/stat.h>
#include "EXTERN.h"
#include "perl.h"
-#include "perllio.h"
+#include "perliol.h"
#define NO_XSLOCKS
#include "XSUB.h"
{
mode++;
}
- if (*mode || oflags == -1)
+ if (*mode || create == -1)
{
SETERRNO(EINVAL,LIB$_INVARG);
return NULL;
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
*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)
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;
}
{
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;
}