diff options
Diffstat (limited to 'doio.c')
-rw-r--r-- | doio.c | 174 |
1 files changed, 0 insertions, 174 deletions
@@ -2039,177 +2039,3 @@ Perl_do_shmio(pTHX_ I32 optype, SV **mark, SV **sp) #endif /* SYSV IPC */ -#ifdef SOCKS_64BIT_BUG - -/** - ** getc and ungetc wrappers for the 64 bit problems with SOCKS 5 support - ** Workaround to the problem, that SOCKS maps a socket 'getc' to revc - ** without checking the ungetc buffer. - **/ - -/* Not threadsafe? */ -static S64_IOB *s64_buffer = (S64_IOB *) NULL; - -/* initialize the buffer area */ -/* required after a fork(2) call in order to remove side effects */ -void -Perl_do_s64_init_buffer(void) -{ - s64_buffer = (S64_IOB *) NULL; -} - -/* get a buffered stream pointer */ -STATIC S64_IOB* -S_s64_get_buffer(pTHX_ PerlIO *fp) -{ - S64_IOB *ptr = s64_buffer; - while( ptr && ptr->fp != fp) - ptr = ptr->next; - return( ptr); -} - -/* create a buffered stream pointer */ -STATIC S64_IOB* -S_s64_create_buffer(pTHX_ PerlIO *f) -{ - S64_IOB *ptr = malloc( sizeof( S64_IOB)); - if( ptr) { - ptr->fp = f; - ptr->cnt = ptr->size = 0; - ptr->buffer = (int *) NULL; - ptr->next = s64_buffer; - ptr->last = (S64_IOB *) NULL; - if( s64_buffer) s64_buffer->last = ptr; - s64_buffer = ptr; - } - return( ptr); -} - -/* delete a buffered stream pointer */ -void -Perl_do_s64_delete_buffer(pTHX_ PerlIO *f) -{ - S64_IOB *ptr = S_s64_get_buffer(aTHX_ f); - if( ptr) { - /* fix the stream pointer according to the bytes buffered */ - /* required, if this is called in a seek-context */ - if( ptr->cnt) fseek(f,-ptr->cnt,SEEK_CUR); - if( ptr->buffer) free( ptr->buffer); - if( ptr->last) - ptr->last->next = ptr->next; - else - s64_buffer = ptr->next; - free( ptr); - } -} - -/* internal buffer management */ - -#define S64_BUFFER_SIZE 32 - -STATIC int -S_s64_malloc(pTHX_ S64_IOB *ptr) -{ - if( ptr) { - if( !ptr->buffer) { - ptr->buffer = (int *) calloc( S64_BUFFER_SIZE, sizeof( int)); - ptr->size = ptr->cnt = 0; - } else { - ptr->buffer = (int *) realloc( ptr->buffer, - ptr->size + S64_BUFFER_SIZE); - } - - if( !ptr->buffer) - return( 0); - - ptr->size += S64_BUFFER_SIZE; - - return( 1); - } - - return( 0); -} - -/* SOCKS 64 bit getc replacement */ -int -Perl_do_s64_getc(pTHX_ PerlIO *f) -{ - S64_IOB *ptr = S_s64_get_buffer(aTHX_ f); - if( ptr) { - if( ptr->cnt) - return( ptr->buffer[--ptr->cnt]); - } - return( getc(f)); -} - -/* SOCKS 64 bit ungetc replacement */ -int -Perl_do_s64_ungetc(pTHX_ int ch, PerlIO *f) -{ - S64_IOB *ptr = S_s64_get_buffer(aTHX_ f); - - if( !ptr) ptr = S_s64_create_buffer(aTHX_ f); - if( !ptr) return( EOF); - if( !ptr->buffer || (ptr->buffer && ptr->cnt >= ptr->size)) - if( !S_s64_malloc(aTHX_ ptr)) return( EOF); - ptr->buffer[ptr->cnt++] = ch; - - return( ch); -} - -/* SOCKS 64 bit fread replacement */ -SSize_t -Perl_do_s64_fread(pTHX_ void *buf, SSize_t count, PerlIO* f) -{ - SSize_t len = 0; - char *bufptr = (char *) buf; - S64_IOB *ptr = S_s64_get_buffer(aTHX_ f); - if( ptr) { - while( ptr->cnt && count) { - *bufptr++ = ptr->buffer[--ptr->cnt]; - count--, len++; - } - } - if( count) - len += (SSize_t)fread(bufptr,1,count,f); - - return( len); -} - -/* SOCKS 64 bit fseek replacement */ -int -Perl_do_s64_seek(pTHX_ PerlIO* f, Off_t offset, int whence) -{ - S64_IOB *ptr = S_s64_get_buffer(aTHX_ f); - - /* Simply clear the buffer and seek if the position is absolute */ - if( SEEK_SET == whence || SEEK_END == whence) { - if( ptr) ptr->cnt = 0; - - /* In case of relative positioning clear the buffer and calculate */ - /* a fixed offset */ - } else if( SEEK_CUR == whence) { - if( ptr) { - offset -= (Off_t)ptr->cnt; - ptr->cnt = 0; - } - } - - /* leave out buffer untouched otherwise, because fseek will fail */ - /* seek now */ - return( fseeko( f, offset, whence)); -} - -/* SOCKS 64 bit ftell replacement */ -Off_t -Perl_do_s64_tell(pTHX_ PerlIO* f) -{ - Off_t offset = 0; - S64_IOB *ptr = S_s64_get_buffer(aTHX_ f); - if( ptr) - offset = ptr->cnt; - return( ftello(f) - offset); -} - -#endif /* SOCKS_64BIT_BUG */ - |