X-Git-Url: http://git.jankratochvil.net/?p=reactos.git;a=blobdiff_plain;f=lib%2Fcrtdll%2Fsys_stat%2Fstat.c;h=a6e9d72a365d6b06d29a274b198c56c1d9dc4451;hp=f12d4b13b4babe735815f2844bad9da805a1a421;hb=03af8776dc14167b078911b0c7c5327d1bcdd128;hpb=f4077c1bf64ef89d74a8d4822d2d7aada3ba9927 diff --git a/lib/crtdll/sys_stat/stat.c b/lib/crtdll/sys_stat/stat.c index f12d4b1..a6e9d72 100644 --- a/lib/crtdll/sys_stat/stat.c +++ b/lib/crtdll/sys_stat/stat.c @@ -1,55 +1,51 @@ #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include -int _stat( const char *path, struct stat *buffer ) +int _stat(const char* path, struct stat* buffer) { - WIN32_FIND_DATA wfd; - HANDLE fh; - fh = FindFirstFile (path,&wfd); - if ( fh == INVALID_HANDLE_VALUE ) - { - __set_errno(ENOFILE); - return -1; - } - if ( ! (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) - { - int fd = _open(path,_O_RDONLY); - int ret; - - ret = fstat(fd,buffer); - _close(fd); + HANDLE fh; + WIN32_FIND_DATA wfd; - return ret; - } - buffer->st_ctime = FileTimeToUnixTime( &wfd.ftCreationTime,NULL); - buffer->st_atime = FileTimeToUnixTime( &wfd.ftLastAccessTime,NULL); - buffer->st_mtime = FileTimeToUnixTime( &wfd.ftLastWriteTime,NULL); + fh = FindFirstFile(path, &wfd); + if (fh == INVALID_HANDLE_VALUE) { + __set_errno(ENOFILE); + return -1; + } + if (!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { + int fd = _open(path, _O_RDONLY); + int ret; + ret = fstat(fd, buffer); + _close(fd); + return ret; + } + buffer->st_ctime = FileTimeToUnixTime(&wfd.ftCreationTime,NULL); + buffer->st_atime = FileTimeToUnixTime(&wfd.ftLastAccessTime,NULL); + buffer->st_mtime = FileTimeToUnixTime(&wfd.ftLastWriteTime,NULL); - if (buffer->st_atime ==0) - buffer->st_atime = buffer->st_mtime; - if (buffer->st_ctime ==0) - buffer->st_ctime = buffer->st_mtime; + if (buffer->st_atime ==0) + buffer->st_atime = buffer->st_mtime; + if (buffer->st_ctime ==0) + buffer->st_ctime = buffer->st_mtime; - buffer->st_mode = S_IREAD; - if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) - buffer->st_mode |= S_IFDIR; - else - buffer->st_mode |= S_IFREG; - if ( ! (wfd.dwFileAttributes & FILE_ATTRIBUTE_READONLY)) - buffer->st_mode |= S_IWRITE | S_IEXEC; + buffer->st_mode = S_IREAD; + if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) + buffer->st_mode |= S_IFDIR; + else + buffer->st_mode |= S_IFREG; + if (!(wfd.dwFileAttributes & FILE_ATTRIBUTE_READONLY)) + buffer->st_mode |= S_IWRITE | S_IEXEC; - buffer->st_size = wfd.nFileSizeLow; - buffer->st_nlink = 1; - if (FindNextFile(fh,&wfd)) - { - __set_errno(ENOFILE); - FindClose(fh); - return -1; - } - return 0; + buffer->st_size = wfd.nFileSizeLow; + buffer->st_nlink = 1; + if (FindNextFile(fh, &wfd)) { + __set_errno(ENOFILE); + FindClose(fh); + return -1; + } + return 0; }