Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
2.0 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef LINUX_SUPPORT_H
  8. #define LINUX_SUPPORT_H
  9. #include <ctype.h> // tolower()
  10. #include <limits.h> // PATH_MAX define
  11. #include <string.h> //strcmp, strcpy
  12. #include <sys/stat.h> // stat()
  13. #include <unistd.h>
  14. #include <dirent.h> // scandir()
  15. #include <stdlib.h>
  16. #include <stdio.h>
  17. #include "tier0/platform.h"
  18. #define FILE_ATTRIBUTE_DIRECTORY S_IFDIR
  19. typedef struct
  20. {
  21. // public data
  22. int dwFileAttributes;
  23. char cFileName[PATH_MAX]; // the file name returned from the call
  24. char cBaseDir[PATH_MAX]; // the root dir for this find
  25. int numMatches;
  26. int curMatch;
  27. struct dirent **namelist;
  28. } FIND_DATA;
  29. #define WIN32_FIND_DATA FIND_DATA
  30. HANDLE FindFirstFile( const char *findName, FIND_DATA *dat);
  31. bool FindNextFile(HANDLE handle, FIND_DATA *dat);
  32. bool FindClose(HANDLE handle);
  33. // findFileInDirCaseInsensitive looks for the specified file. It returns
  34. // false if no directory separator is found. Otherwise it looks for the
  35. // requested file by scanning the specified directory and doing a case
  36. // insensitive match. If the file exists (in any case) then the correctly cased
  37. // filename will be returned in the user's buffer and 'true' will be returned.
  38. // If the file does not exist then the filename will be lowercased and 'false'
  39. // will be returned.
  40. // This function uses a static buffer for internal purposes and is therefore
  41. // not thread safe, so it must only be called from the main thread.
  42. bool findFileInDirCaseInsensitive( const char *file, OUT_Z_BYTECAP(bufSize) char* output, size_t bufSize );
  43. // The _safe version of this function should be preferred since it always infers
  44. // the directory size correctly.
  45. template<size_t bufSize>
  46. bool findFileInDirCaseInsensitive_safe( const char *file, OUT_Z_ARRAY char (&output)[bufSize] )
  47. {
  48. return findFileInDirCaseInsensitive( file, output, bufSize );
  49. }
  50. #endif // LINUX_SUPPORT_H