char *getS0( picoMemStream_t *fp ) { char *s; int i, c, len, pos; if ( flen == FLEN_ERROR ) return NULL; pos = _pico_memstream_tell( fp ); for ( i = 1; ; i++ ) { c = _pico_memstream_getc( fp ); if ( c <= 0 ) break; } if ( c < 0 ) { flen = FLEN_ERROR; return NULL; } if ( i == 1 ) { if ( _pico_memstream_seek( fp, pos + 2, PICO_SEEK_SET )) flen = FLEN_ERROR; else flen += 2; return NULL; } len = i + ( i & 1 ); s = _pico_alloc( len ); if ( !s ) { flen = FLEN_ERROR; return NULL; } if ( _pico_memstream_seek( fp, pos, PICO_SEEK_SET )) { flen = FLEN_ERROR; return NULL; } if ( 1 != _pico_memstream_read( fp, s, len )) { flen = FLEN_ERROR; return NULL; } flen += len; return s; }
void *getbytes( picoMemStream_t *fp, size_t size ) { void *data; if ( flen == FLEN_ERROR ) return NULL; if ( size < 0 ) { flen = FLEN_ERROR; return NULL; } data = _pico_alloc( size ); if ( !data ) { flen = FLEN_ERROR; return NULL; } if ( 1 != _pico_memstream_read( fp, data, size )) { flen = FLEN_ERROR; _pico_free( data ); return NULL; } flen += size; return data; }