fork download
  1. /* -------------------- f_size.h --------------------------- */
  2. /* (see also: f_size.c furtehr below) */
  3.  
  4. #ifdef _cplusplus
  5. extern "C" {
  6. #endif
  7.  
  8. #ifndef FSIZE_H
  9. #define FSIZE_H
  10.  
  11. #if defined(_WIN32) || defined(_WIN64) || defined(__WINDOWS__) || defined(__TOS_WIN__)
  12.  
  13. #define OS_FSIZE_WIN32
  14. #define WIN32_LEAN_AND_MEAN
  15. #include <windows.h>
  16.  
  17. #elif defined(__linux__) || defined(__unix__) || defined(__unix) \
  18. || defined(__CYGWIN__) || (defined(__APPLE__) && defined(__MACH__))
  19.  
  20. #define OS_FSIZE_POSIX
  21.  
  22. #include <sys/types.h>
  23. #include <sys/stat.h>
  24. #include <unistd.h>
  25.  
  26. #endif
  27.  
  28. #include <inttypes.h>
  29.  
  30. extern int64_t f_size( const char *fname );
  31. #endif
  32.  
  33. #ifdef _cplusplus
  34. }
  35. # endif
  36.  
  37. /* -------------------- f_size.c --------------------------- */
  38.  
  39. #include "f_size.h"
  40.  
  41. #if defined( OS_FSIZE_WIN32 )
  42. int64_t f_size( const char *fname )
  43. {
  44. int64_t fsize = -1;
  45.  
  46. LARGE_INTEGER nLargeInteger;
  47. HANDLE hFile = CreateFile(
  48. fname,
  49. GENERIC_READ,
  50. FILE_SHARE_READ,
  51. NULL,
  52. OPEN_EXISTING,
  53. FILE_ATTRIBUTE_READONLY,
  54. NULL
  55. );
  56. if ( hFile != INVALID_HANDLE_VALUE ) {
  57. if ( GetFileSizeEx(hFile, &nLargeInteger) ) {
  58. fsize = (int64_t) nLargeInteger.QuadPart;
  59. }
  60. }
  61.  
  62. return fsize;
  63. }
  64.  
  65. #else
  66. int64_t f_size( const char *fname )
  67. {
  68. struct stat64 info;
  69. if ( 0 == stat64(fname, &info) ) {
  70. return info.st_size;
  71. }
  72.  
  73. return -1;
  74. }
  75.  
  76. #endif
  77.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c:38:20: fatal error: f_size.h: No such file or directory
 #include "f_size.h"
                    ^
compilation terminated.
stdout
Standard output is empty