From: Nick Ing-Simmons Date: Thu, 30 May 2002 14:40:11 +0000 (+0000) Subject: Play safe and avoid writes to stdio's buffer (for glibc2.3) X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=313e59c8f773fc5f3cb2659752fdcf7e00b2ec27;p=p5sagit%2Fp5-mst-13.2.git Play safe and avoid writes to stdio's buffer (for glibc2.3) p4raw-id: //depot/perlio@16895 --- diff --git a/perlio.c b/perlio.c index 73e3557..96aa0c9 100644 --- a/perlio.c +++ b/perlio.c @@ -2388,6 +2388,14 @@ PerlIO_funcs PerlIO_unix = { * stdio as a layer */ +#if defined(VMS) && !defined(STDIO_BUFFER_WRITABLE) +/* perl5.8 - This ensures the last minute VMS ungetc fix is not + broken by the last second glibc 2.3 fix + */ +#define STDIO_BUFFER_WRITABLE +#endif + + typedef struct { struct _PerlIO base; FILE *stdio; /* The stream */ @@ -2639,6 +2647,7 @@ PerlIOStdio_unread(pTHX_ PerlIO *f, const void *vbuf, Size_t count) SSize_t unread = 0; FILE *s = PerlIOSelf(f, PerlIOStdio)->stdio; +#ifdef STDIO_BUFFER_WRITABLE if (PerlIO_fast_gets(f) && PerlIO_has_base(f)) { STDCHAR *buf = ((STDCHAR *) vbuf) + count; STDCHAR *base = PerlIO_get_base(f); @@ -2658,7 +2667,9 @@ PerlIOStdio_unread(pTHX_ PerlIO *f, const void *vbuf, Size_t count) PerlSIO_clearerr(s); } } - else if (PerlIO_has_cntptr(f)) { + else +#endif + if (PerlIO_has_cntptr(f)) { /* We can get pointer to buffer but not its base Do ungetc() but check chars are ending up in the buffer @@ -2852,6 +2863,8 @@ PerlIOStdio_fill(pTHX_ PerlIO *f) return EOF; #if (defined(STDIO_PTR_LVALUE) && (defined(STDIO_CNT_LVALUE) || defined(STDIO_PTR_LVAL_SETS_CNT))) + +#ifdef STDIO_BUFFER_WRITABLE if (PerlIO_fast_gets(f) && PerlIO_has_base(f)) { /* Fake ungetc() to the real buffer in case system's ungetc goes elsewhere @@ -2867,7 +2880,9 @@ PerlIOStdio_fill(pTHX_ PerlIO *f) return 0; } } - else if (PerlIO_has_cntptr(f)) { + else +#endif + if (PerlIO_has_cntptr(f)) { STDCHAR ch = c; if (PerlIOStdio_unread(aTHX_ f,&ch,1) == 1) { return 0;