Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 110 lines (99 sloc) 2.265 kB
09eee3c @gfx Initial commit from CPAN version 0.70
authored
1 /* missing functions copied from perlio.c */
2
3 #include "perlioutil.h"
4
5 #if defined(WIN32)
6
7 PerlIO_funcs *
8 PerlIO_find_layer(pTHX_ const char *name, STRLEN len, int load)
9 {
10 dVAR;
11 IV i;
12 if ((SSize_t) len <= 0)
13 len = strlen(name);
14 for (i = 0; i < PL_known_layers->cur; i++) {
15 PerlIO_funcs * const f = PL_known_layers->array[i].funcs;
16 if (memEQ(f->name, name, len) && f->name[len] == 0) {
17 PerlIO_debug("%.*s => %p\n", (int) len, name, (void*)f);
18 return f;
19 }
20 }
21 if (load && PL_subname && PL_def_layerlist
22 && PL_def_layerlist->cur >= 2) {
23 if (PL_in_load_module) {
24 Perl_croak(aTHX_ "Recursive call to Perl_load_module in PerlIO_find_layer");
25 return NULL;
26 } else {
27 SV * const pkgsv = newSVpvs("PerlIO");
28 SV * const layer = newSVpvn(name, len);
29 CV * const cv = get_cv("PerlIO::Layer::NoWarnings", FALSE);
30 ENTER;
31 SAVEINT(PL_in_load_module);
32 if (cv) {
33 SAVEGENERICSV(PL_warnhook);
34 PL_warnhook = (SV *) (SvREFCNT_inc_simple_NN(cv));
35 }
36 PL_in_load_module++;
37 /*
38 * The two SVs are magically freed by load_module
39 */
40 Perl_load_module(aTHX_ 0, pkgsv, NULL, layer, NULL);
41 PL_in_load_module--;
42 LEAVE;
43 return PerlIO_find_layer(aTHX_ name, len, 0);
44 }
45 }
46 PerlIO_debug("Cannot find %.*s\n", (int) len, name);
47 return NULL;
48 }
49
50
51 int
52 PerlIOUnix_oflags(const char *mode)
53 {
54 int oflags = -1;
55 if (*mode == IoTYPE_IMPLICIT || *mode == IoTYPE_NUMERIC)
56 mode++;
57 switch (*mode) {
58 case 'r':
59 oflags = O_RDONLY;
60 if (*++mode == '+') {
61 oflags = O_RDWR;
62 mode++;
63 }
64 break;
65
66 case 'w':
67 oflags = O_CREAT | O_TRUNC;
68 if (*++mode == '+') {
69 oflags |= O_RDWR;
70 mode++;
71 }
72 else
73 oflags |= O_WRONLY;
74 break;
75
76 case 'a':
77 oflags = O_CREAT | O_APPEND;
78 if (*++mode == '+') {
79 oflags |= O_RDWR;
80 mode++;
81 }
82 else
83 oflags |= O_WRONLY;
84 break;
85 }
86 if (*mode == 'b') {
87 oflags |= O_BINARY;
88 oflags &= ~O_TEXT;
89 mode++;
90 }
91 else if (*mode == 't') {
92 oflags |= O_TEXT;
93 oflags &= ~O_BINARY;
94 mode++;
95 }
96 /*
97 * Always open in binary mode
98 */
99 oflags |= O_BINARY;
100 if (*mode || oflags == -1) {
101 SETERRNO(EINVAL, LIB_INVARG);
102 oflags = -1;
103 }
104 return oflags;
105 }
106
107
108
109 #endif /* WIN32 */
Something went wrong with that request. Please try again.