- }
- if ( ( rc = calloc( 1, sizeof( struct _PDCLIB_file_t ) ) ) == NULL )
- {
- /* no memory for another FILE */
- return NULL;
- }
- if ( ( rc->status = _PDCLIB_filemode( mode ) ) == 0 )
- {
- /* invalid mode */
- free( rc );
- return NULL;
- }
- rc->handle = _PDCLIB_open( filename, rc->status );
- if ( rc->handle == _PDCLIB_NOHANDLE )
- {
- /* OS open() failed */
- free( rc );
- return NULL;
- }
- /* 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 );
+
+ _PDCLIB_fd_t fd = _PDCLIB_open( filename, imode );
+ if(fd == _PDCLIB_NOHANDLE) {