stat() does not work for me on Cygwin/Windows

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dissectcode2
    New Member
    • Apr 2009
    • 32

    stat() does not work for me on Cygwin/Windows

    Does anyone know about this problem? I tried using the "old" _stat for Cygwin/Windows but that doesn't help.

    The problem I am having is st_size is ALWAYS 16777216 for any file I am stat'ing and that value is incorrect anyway. Here is an example of the code:

    Code:
    char *filename = "C:\\Program Files\\Somedir\\medfile.txt";
    int ret;
    
    #if OS == LINUX
        struct  stat sbuf;
        ret = stat( filename, &sbuf );
    #elif OS == CYGWIN
        struct _stat sbuf;
        ret = _stat( filename, &sbuf );
    #endif
    
    printf("ret : %d, sbuf.st_size: %dl \n\n", ret, sbuf.st_size);
    result is :

    0, 16777216


    btw - using the FILE functions, I get the correct sizes; e.g.
    Code:
    sizeFile = (UINT32)ftell( fp );
    but I don't want to open and close the file just to get the size.

    helpppp
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Your file should be:

    Code:
    char *filename = "C:\\Program\\Files\\Somedir\\medfile.txt";
    I would just opne the file and do a seek to the end followed by a tell. That will give you the number of bytes in the file.

    Comment

    • dissectcode2
      New Member
      • Apr 2009
      • 32

      #3
      There is a \\ between Program and Files? I tried the \\ in every other spot, and it is the same error (actually that is how I have it in my code, correctly)

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        There is no \\ between Program and files. It's a typo.

        Comment

        • BillyTKid
          New Member
          • Aug 2010
          • 7

          #5
          try %ld in printf, not %dl

          Comment

          Working...