GDFS FS_OpenFile( char *p_pFilePath ) { char *pFileName; char FileName[ GDD_FS_FNAMESIZE ]; char FilePath[ 256 ]; GDFS_DIRREC Directory; static Uint32 DirectoryBuffer[ GDFS_DIRREC_SIZE( 64 ) ]; GDFS File; /* Save the direcotry used before entering */ Directory = gdFsCreateDirhn( DirectoryBuffer, 64 ); gdFsLoadDir( ".", Directory ); /* For an absolute path, begin with the root directory */ if( p_pFilePath[ 0 ] == '/' ) { gdFsSetDir( g_RootDirectory ); } /* Don't modify the input file path */ strncpy( FilePath, p_pFilePath, strlen( p_pFilePath ) ); FilePath[ strlen( p_pFilePath ) ] = '\0'; /* Break the path down for GDFS to consume */ pFileName = strtok( FilePath, "/" ); File = NULL; while( pFileName != NULL ) { GDFS_DIRINFO FileInformation; strcpy( FileName, pFileName ); if( gdFsGetDirInfo( pFileName, &FileInformation ) != GDD_ERR_OK ) { LOG_Debug( "FILE: \"%s\" invalid", FileName ); goto OpenFileEnd; } if( FileInformation.flag & GDD_FF_DIRECTORY ) { gdFsChangeDir( FileName ); } pFileName = strtok( NULL, "/" ); } File = gdFsOpen( FileName, NULL ); OpenFileEnd: /* Restore the directory used before entering the function */ gdFsSetDir( Directory ); return File; }
char streamReader_open(streamReader *pThis, const char *fileName, int fatal) { #ifndef DREAMCAST #ifdef USE_IFOPEN pThis->fileHandle = ifopen(fileName, "rb"); #else pThis->fileHandle = fopen(fileName, "rb"); #endif #else pThis->fileHandle = gdFsOpen(fileName, NULL); #endif if (pThis->fileHandle) { pThis->currentSector = 0; streamReader_feedBuffer(pThis); return 1; } else { if (fatal) { printf("FATAL: Can't find %s\n", fileName); exit(-1); } return 0; } }