1 #define PERL_NO_GET_CONTEXT
11 struct _PerlIO base; /* Base "class" info */
17 PerlIOScalar_pushed(PerlIO *f, const char *mode, SV *arg)
19 PerlIOScalar *b = PerlIOSelf(f,PerlIOScalar);
20 return PerlIOBase_pushed(f,mode,arg);
24 PerlIOScalar_popped(PerlIO *f)
26 PerlIOScalar *s = PerlIOSelf(f,PerlIOScalar);
37 PerlIOScalar_close(PerlIO *f)
40 IV code = PerlIOBase_close(f);
41 PerlIOScalar *s = PerlIOSelf(f,PerlIOScalar);
42 PerlIOBase(f)->flags &= ~(PERLIO_F_RDBUF|PERLIO_F_WRBUF);
47 PerlIOScalar_fileno(PerlIO *f)
53 PerlIOScalar_seek(PerlIO *f, Off_t offset, int whence)
55 PerlIOScalar *s = PerlIOSelf(f,PerlIOScalar);
62 s->posn = offset + s->posn;
65 s->posn = offset + SvCUR(s->var);
68 if (s->posn > SvCUR(s->var))
71 (void) SvGROW(s->var,s->posn);
77 PerlIOScalar_tell(PerlIO *f)
79 PerlIOScalar *s = PerlIOSelf(f,PerlIOScalar);
84 PerlIOScalar_unread(PerlIO *f, const void *vbuf, Size_t count)
87 PerlIOScalar *s = PerlIOSelf(f,PerlIOScalar);
88 char *dst = SvGROW(s->var,s->posn+count);
89 Move(vbuf,dst,count,char);
91 SvCUR_set(s->var,s->posn);
97 PerlIOScalar_write(PerlIO *f, const void *vbuf, Size_t count)
99 if (PerlIOBase(f)->flags & PERLIO_F_CANWRITE)
101 return PerlIOScalar_unread(f,vbuf,count);
107 PerlIOScalar_fill(PerlIO *f)
113 PerlIOScalar_flush(PerlIO *f)
119 PerlIOScalar_get_base(PerlIO *f)
121 PerlIOScalar *s = PerlIOSelf(f,PerlIOScalar);
122 if (PerlIOBase(f)->flags & PERLIO_F_CANREAD)
125 return (STDCHAR *)SvPV_nolen(s->var);
127 return (STDCHAR *) Nullch;
131 PerlIOScalar_get_ptr(PerlIO *f)
133 if (PerlIOBase(f)->flags & PERLIO_F_CANREAD)
135 PerlIOScalar *s = PerlIOSelf(f,PerlIOScalar);
136 return PerlIOScalar_get_base(f)+s->posn;
138 return (STDCHAR *) Nullch;
142 PerlIOScalar_get_cnt(PerlIO *f)
144 if (PerlIOBase(f)->flags & PERLIO_F_CANREAD)
146 PerlIOScalar *s = PerlIOSelf(f,PerlIOScalar);
147 return SvCUR(s->var) - s->posn;
153 PerlIOScalar_bufsiz(PerlIO *f)
155 if (PerlIOBase(f)->flags & PERLIO_F_CANREAD)
157 PerlIOScalar *s = PerlIOSelf(f,PerlIOScalar);
158 return SvCUR(s->var);
164 PerlIOScalar_set_ptrcnt(PerlIO *f, STDCHAR *ptr, SSize_t cnt)
166 PerlIOScalar *s = PerlIOSelf(f,PerlIOScalar);
167 s->posn = SvCUR(s->var)-cnt;
171 PerlIOScalar_open(pTHX_ PerlIO_funcs *self, AV *layers, IV n, const char *mode, int fd, int imode, int perm, PerlIO *f, int narg, SV **args)
180 sv_upgrade(var,SVt_PV);
181 f = PerlIO_allocate(aTHX);
182 s = PerlIOSelf(PerlIO_push(aTHX_ f,self,mode,PerlIOArg),PerlIOScalar);
183 s->var = SvREFCNT_inc(var);
185 PerlIOBase(f)->flags |= PERLIO_F_OPEN;
193 PerlIO_funcs PerlIO_scalar = {
195 sizeof(PerlIOScalar),
213 PerlIOBase_setlinebuf,
214 PerlIOScalar_get_base,
216 PerlIOScalar_get_ptr,
217 PerlIOScalar_get_cnt,
218 PerlIOScalar_set_ptrcnt,
222 #endif /* Layers available */
224 MODULE = PerlIO::Scalar PACKAGE = PerlIO::Scalar
229 PerlIO_define_layer(aTHX_ &PerlIO_scalar);