This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Problem in calling _stat() on Cygwin 1.7


Hello all,

I was testing a program written by someone else that calls _stat() (note the leading underscore). However it was not giving an expected result. Consider this sample program.
 
FILE statex.c:

#include <sys/stat.h>
#include <assert.h>

int
main (void)
{
    struct stat s;

    assert (_stat ("/bin/ls", &s) == 0);

    int exe_bits = (s.st_mode & S_IXUSR) &&
                   (s.st_mode & S_IXGRP) &&
                   (s.st_mode & S_IXOTH);

    assert (exe_bits);

    return 0;
}


Then I typed this command:

$ gcc -o statex statex.c

$ ls -l /bin/ls
-rwxr-xr-x 1 testusr Administrators 129536 2008-12-18 06:16 /bin/ls

$ ./statex
assertion "exe_bits" failed: file "statex.c", line 15, function: main
Aborted (core dumped)

---------

I debugged with gdb and concluded that the _stat() was not filling the stat structure correctly. However, if I called stat() instead of _stat(), then there was no problem - no assertion failure, structure was filled correctly.

I suspected maybe I should not use struct stat, so I tried other variations, such as stat32, stat64, _stat32, _stat64, ... However only struct stat led to correct compilation (and gave wrong result).

Is it a problem with _stat(), or did I make a mistake in the 2nd argument in calling _stat()?

Thanks for help.

Dave Lee.



      

Attachment: cygcheck.out
Description: Binary data

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]