void PerlIO_set_ptrcnt(PerlIO *f, STDCHAR *ptr, int cnt) { dTHX; #ifdef FILE_bufsiz STDCHAR *e = FILE_base(f) + FILE_bufsiz(f); int ec = e - ptr; if (ptr > e + 1 && ckWARN_d(WARN_INTERNAL)) Perl_warner(aTHX_ WARN_INTERNAL, "Setting ptr %p > end+1 %p\n", ptr, e + 1); if (cnt != ec && ckWARN_d(WARN_INTERNAL)) Perl_warner(aTHX_ WARN_INTERNAL, "Setting cnt to %d, ptr implies %d\n",cnt,ec); #endif #if defined(USE_STDIO_PTR) && defined(STDIO_PTR_LVALUE) FILE_ptr(f) = ptr; #else Perl_croak(aTHX_ "Cannot set 'ptr' of FILE * on this system"); #endif #if defined(USE_STDIO_PTR) && defined(STDIO_CNT_LVALUE) && defined (STDIO_PTR_LVAL_NOCHANGE_CNT) FILE_cnt(f) = cnt; #else #if defined(STDIO_PTR_LVAL_SETS_CNT) assert (FILE_cnt(f) == cnt); #else Perl_croak(aTHX_ "Cannot set 'cnt' of FILE * on this system when setting 'ptr'"); #endif #endif }
STDCHAR * PerlIO_get_ptr(PerlIO *f) { #ifdef FILE_ptr return FILE_ptr(f); #else dTHX; Perl_croak(aTHX_ "Cannot get 'ptr' of FILE * on this system"); return NULL; #endif }
char * str_gets(register STR *str, register FILE *fp) { #if defined(USE_STDIO_PTR) && defined(STDIO_PTR_LVALUE) && defined(STDIO_CNT_LVALUE) /* Here is some breathtakingly efficient cheating */ register char *bp; /* we're going to steal some values */ register int cnt; /* from the stdio struct and put EVERYTHING */ register STDCHAR *ptr; /* in the innermost loop into registers */ register char newline = '\n'; /* (assuming at least 6 registers) */ int i; int bpx; #if defined(VMS) /* An ungetc()d char is handled separately from the regular * buffer, so we getc() it back out and stuff it in the buffer. */ i = getc(fp); if (i == EOF) return Nullch; *(--((*fp)->_ptr)) = (unsigned char) i; (*fp)->_cnt++; #endif cnt = FILE_cnt(fp); /* get count into register */ str->str_nok = 0; /* invalidate number */ str->str_pok = 1; /* validate pointer */ if (str->str_len <= cnt) /* make sure we have the room */ GROWSTR(&(str->str_ptr), &(str->str_len), cnt+1); bp = str->str_ptr; /* move these two too to registers */ ptr = FILE_ptr(fp); for (;;) { while (--cnt >= 0) { if ((*bp++ = *ptr++) == newline) if (bp <= str->str_ptr || bp[-2] != '\\') goto thats_all_folks; else { line++; bp -= 2; } } FILE_cnt(fp) = cnt; /* deregisterize cnt and ptr */ FILE_ptr(fp) = ptr; i = getc(fp); /* get more characters */ cnt = FILE_cnt(fp); ptr = FILE_ptr(fp); /* reregisterize cnt and ptr */ bpx = bp - str->str_ptr; /* prepare for possible relocation */ GROWSTR(&(str->str_ptr), &(str->str_len), str->str_cur + cnt + 1); bp = str->str_ptr + bpx; /* reconstitute our pointer */ if (i == newline) { /* all done for now? */ *bp++ = i; goto thats_all_folks; } else if (i == EOF) /* all done for ever? */ goto thats_all_folks; *bp++ = i; /* now go back to screaming loop */ } thats_all_folks: FILE_cnt(fp) = cnt; /* put these back or we're in trouble */ FILE_ptr(fp) = ptr; *bp = '\0'; str->str_cur = bp - str->str_ptr; /* set length */ #else /* USE_STDIO_PTR && STDIO_PTR_LVALUE && STDIO_CNT_LVALUE */ /* The big, slow, and stupid way */ static char buf[4192]; if (fgets(buf, sizeof buf, fp) != Nullch) str_set(str, buf); else str_set(str, No); #endif /* USE_STDIO_PTR && STDIO_PTR_LVALUE && STDIO_CNT_LVALUE */ return str->str_cur ? str->str_ptr : Nullch; }