Problem in calling _stat() on Cygwin 1.7
Dave Lee
mailtolky@yahoo.com.hk
Sat Feb 27 11:57:00 GMT 2010
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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cygcheck.out
Type: application/octet-stream
Size: 23101 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin/attachments/20100227/f6d2b442/attachment.obj>
-------------- next part --------------
--
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
More information about the Cygwin
mailing list