- /* Adding to list of open files */
- rc->next = _PDCLIB_filelist;
- _PDCLIB_filelist = rc;
- /* Setting buffer, and mark as internal. TODO: Check for unbuffered */
- if ( ( rc->buffer = malloc( BUFSIZ ) ) == NULL )
- {
- free( rc );
- return NULL;
- }
- if ( ( rc->ungetbuf = malloc( _PDCLIB_UNGETCBUFSIZE ) ) == NULL )
- {
- free( rc->buffer );
- free( rc );
- return NULL;
- }
+ /* Setting pointers into the memory block allocated above */
+ rc->ungetbuf = (unsigned char *)rc + sizeof( struct _PDCLIB_file_t );
+ rc->filename = (char *)rc->ungetbuf + _PDCLIB_UNGETCBUFSIZE;
+ rc->buffer = rc->filename + filename_len;
+ /* Copying filename to FILE structure */
+ strcpy( rc->filename, filename );
+ /* Initializing the rest of the structure */