/* ----------------------------------------------------------------------------- Function: FS_FindFirstFile() -Searches a directory for a file. Parameters: path -[in] Pointer to a NUL-terminated string that specifies a valid directory or path and file name. musthave -[in] File or directory must have these attributes. canthave- [in] File or directory can not have these attributes. Returns: On success string of file name or directory, otherwise NULL. Notes: ----------------------------------------------------------------------------- */ PUBLIC char *FS_FindFirst( const char *path, W32 musthave, W32 canthave ) { struct dirent *d; char *p; p; if( fdir ) { Com_Printf( "FS_FindFirst without close\n" ); return NULL; } FS_FilePath( (char *)path, findbase ); my_strlcpy( (char *)findpattern, FS_SkipPath( (char *)path ), sizeof( findpattern ) ); if( ! *findbase ) { if( (fdir = opendir( "." )) == NULL ) { return NULL; } } else { if( (fdir = opendir( findbase )) == NULL ) { return NULL; } } while( (d = readdir( fdir )) != NULL ) { if( ! *findpattern || glob_match( findpattern, d->d_name ) ) { if( ! *findbase ) { my_strlcpy( findpath, d->d_name, sizeof( findpath ) ); } else { my_snprintf( findpath, sizeof( findpath ), "%s/%s", findbase, d->d_name ); } if( CompareAttributes( findpath, musthave, canthave ) ) { return findpath; } } } return NULL; }
/* ----------------------------------------------------------------------------- Function: FS_FindFirstFile() -Searches a directory for a file. Parameters: path -[in] Pointer to a NUL-terminated string that specifies a valid directory or path and file name. musthave -[in] File or directory must have these attributes. canthave- [in] File or directory can not have these attributes. Returns: On success string of file name or directory, otherwise NULL. Notes: ----------------------------------------------------------------------------- */ PUBLIC char *FS_FindFirst( const char *path, W32 musthave, W32 canthave ) { WIN32_FIND_DATA FindFileData; if( FindHandle ) { printf( "FS_FindFirst without close\n" ); return NULL; } FS_FilePath( path, findbase ); FindHandle = FindFirstFile( path, &FindFileData ); if( FindHandle == INVALID_HANDLE_VALUE ) { return NULL; } if( CompareAttributes( FindFileData.dwFileAttributes, musthave, canthave ) ) { if( ! *findbase ) { cs_strlcpy( findpath, FindFileData.cFileName, sizeof( findpath ) ); } else { cs_snprintf( findpath, sizeof( findpath ), "%s/%s", findbase, FindFileData.cFileName ); } return findpath; } return FS_FindNext( musthave, canthave ); }