Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(7)

Side by Side Diff: Modules/posixmodule.c

Issue 21719: Returning Windows file attribute information via os.stat()
Patch Set: Created 5 years, 9 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/test/test_stat.py ('k') | Modules/_stat.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* POSIX module implementation */ 2 /* POSIX module implementation */
3 3
4 /* This file is also used for Windows NT/MS-Win. In that case the 4 /* This file is also used for Windows NT/MS-Win. In that case the
5 module actually calls itself 'nt', not 'posix', and a few 5 module actually calls itself 'nt', not 'posix', and a few
6 functions are either unimplemented or implemented differently. The source 6 functions are either unimplemented or implemented differently. The source
7 assumes that for Windows NT, the macro 'MS_WINDOWS' is defined independent 7 assumes that for Windows NT, the macro 'MS_WINDOWS' is defined independent
8 of the compiler used. Different compilers define their own feature 8 of the compiler used. Different compilers define their own feature
9 test macro, e.g. '__BORLANDC__' or '_MSC_VER'. */ 9 test macro, e.g. '__BORLANDC__' or '_MSC_VER'. */
10 10
(...skipping 1399 matching lines...) Expand 10 before | Expand all | Expand 10 after
1410 #endif 1410 #endif
1411 1411
1412 #ifdef MS_WINDOWS 1412 #ifdef MS_WINDOWS
1413 /* The CRT of Windows has a number of flaws wrt. its stat() implementation: 1413 /* The CRT of Windows has a number of flaws wrt. its stat() implementation:
1414 - time stamps are restricted to second resolution 1414 - time stamps are restricted to second resolution
1415 - file modification times suffer from forth-and-back conversions between 1415 - file modification times suffer from forth-and-back conversions between
1416 UTC and local time 1416 UTC and local time
1417 Therefore, we implement our own stat, based on the Win32 API directly. 1417 Therefore, we implement our own stat, based on the Win32 API directly.
1418 */ 1418 */
1419 #define HAVE_STAT_NSEC 1 1419 #define HAVE_STAT_NSEC 1
1420 #define HAVE_STRUCT_STAT_ST_FILE_ATTRIBUTES 1
1420 1421
1421 struct win32_stat{ 1422 struct win32_stat{
1422 unsigned long st_dev; 1423 unsigned long st_dev;
1423 __int64 st_ino; 1424 __int64 st_ino;
1424 unsigned short st_mode; 1425 unsigned short st_mode;
1425 int st_nlink; 1426 int st_nlink;
1426 int st_uid; 1427 int st_uid;
1427 int st_gid; 1428 int st_gid;
1428 unsigned long st_rdev; 1429 unsigned long st_rdev;
1429 __int64 st_size; 1430 __int64 st_size;
1430 time_t st_atime; 1431 time_t st_atime;
1431 int st_atime_nsec; 1432 int st_atime_nsec;
1432 time_t st_mtime; 1433 time_t st_mtime;
1433 int st_mtime_nsec; 1434 int st_mtime_nsec;
1434 time_t st_ctime; 1435 time_t st_ctime;
1435 int st_ctime_nsec; 1436 int st_ctime_nsec;
1437 unsigned long st_file_attributes;
1436 }; 1438 };
1437 1439
1438 static __int64 secs_between_epochs = 11644473600; /* Seconds between 1.1.1601 an d 1.1.1970 */ 1440 static __int64 secs_between_epochs = 11644473600; /* Seconds between 1.1.1601 an d 1.1.1970 */
1439 1441
1440 static void 1442 static void
1441 FILE_TIME_to_time_t_nsec(FILETIME *in_ptr, time_t *time_out, int* nsec_out) 1443 FILE_TIME_to_time_t_nsec(FILETIME *in_ptr, time_t *time_out, int* nsec_out)
1442 { 1444 {
1443 /* XXX endianness. Shouldn't matter, as all Windows implementations are litt le-endian */ 1445 /* XXX endianness. Shouldn't matter, as all Windows implementations are litt le-endian */
1444 /* Cannot simply cast and dereference in_ptr, 1446 /* Cannot simply cast and dereference in_ptr,
1445 since it might not be aligned properly */ 1447 since it might not be aligned properly */
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1490 FILE_TIME_to_time_t_nsec(&info->ftLastWriteTime, &result->st_mtime, &result- >st_mtime_nsec); 1492 FILE_TIME_to_time_t_nsec(&info->ftLastWriteTime, &result->st_mtime, &result- >st_mtime_nsec);
1491 FILE_TIME_to_time_t_nsec(&info->ftLastAccessTime, &result->st_atime, &result ->st_atime_nsec); 1493 FILE_TIME_to_time_t_nsec(&info->ftLastAccessTime, &result->st_atime, &result ->st_atime_nsec);
1492 result->st_nlink = info->nNumberOfLinks; 1494 result->st_nlink = info->nNumberOfLinks;
1493 result->st_ino = (((__int64)info->nFileIndexHigh)<<32) + info->nFileIndexLow ; 1495 result->st_ino = (((__int64)info->nFileIndexHigh)<<32) + info->nFileIndexLow ;
1494 if (reparse_tag == IO_REPARSE_TAG_SYMLINK) { 1496 if (reparse_tag == IO_REPARSE_TAG_SYMLINK) {
1495 /* first clear the S_IFMT bits */ 1497 /* first clear the S_IFMT bits */
1496 result->st_mode ^= (result->st_mode & S_IFMT); 1498 result->st_mode ^= (result->st_mode & S_IFMT);
1497 /* now set the bits that make this a symlink */ 1499 /* now set the bits that make this a symlink */
1498 result->st_mode |= S_IFLNK; 1500 result->st_mode |= S_IFLNK;
1499 } 1501 }
1502 result->st_file_attributes = info->dwFileAttributes;
1500 1503
1501 return 0; 1504 return 0;
1502 } 1505 }
1503 1506
1504 static BOOL 1507 static BOOL
1505 attributes_from_dir(LPCSTR pszFile, BY_HANDLE_FILE_INFORMATION *info, ULONG *rep arse_tag) 1508 attributes_from_dir(LPCSTR pszFile, BY_HANDLE_FILE_INFORMATION *info, ULONG *rep arse_tag)
1506 { 1509 {
1507 HANDLE hFindFile; 1510 HANDLE hFindFile;
1508 WIN32_FIND_DATAA FileData; 1511 WIN32_FIND_DATAA FileData;
1509 hFindFile = FindFirstFileA(pszFile, &FileData); 1512 hFindFile = FindFirstFileA(pszFile, &FileData);
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after
1953 {"st_rdev", "device type (if inode device)"}, 1956 {"st_rdev", "device type (if inode device)"},
1954 #endif 1957 #endif
1955 #ifdef HAVE_STRUCT_STAT_ST_FLAGS 1958 #ifdef HAVE_STRUCT_STAT_ST_FLAGS
1956 {"st_flags", "user defined flags for file"}, 1959 {"st_flags", "user defined flags for file"},
1957 #endif 1960 #endif
1958 #ifdef HAVE_STRUCT_STAT_ST_GEN 1961 #ifdef HAVE_STRUCT_STAT_ST_GEN
1959 {"st_gen", "generation number"}, 1962 {"st_gen", "generation number"},
1960 #endif 1963 #endif
1961 #ifdef HAVE_STRUCT_STAT_ST_BIRTHTIME 1964 #ifdef HAVE_STRUCT_STAT_ST_BIRTHTIME
1962 {"st_birthtime", "time of creation"}, 1965 {"st_birthtime", "time of creation"},
1966 #endif
1967 #ifdef HAVE_STRUCT_STAT_ST_FILE_ATTRIBUTES
1968 {"st_file_attributes", "Windows file attribute bits"},
1963 #endif 1969 #endif
1964 {0} 1970 {0}
1965 }; 1971 };
1966 1972
1967 #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE 1973 #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
1968 #define ST_BLKSIZE_IDX 16 1974 #define ST_BLKSIZE_IDX 16
1969 #else 1975 #else
1970 #define ST_BLKSIZE_IDX 15 1976 #define ST_BLKSIZE_IDX 15
1971 #endif 1977 #endif
1972 1978
(...skipping 18 matching lines...) Expand all
1991 #ifdef HAVE_STRUCT_STAT_ST_GEN 1997 #ifdef HAVE_STRUCT_STAT_ST_GEN
1992 #define ST_GEN_IDX (ST_FLAGS_IDX+1) 1998 #define ST_GEN_IDX (ST_FLAGS_IDX+1)
1993 #else 1999 #else
1994 #define ST_GEN_IDX ST_FLAGS_IDX 2000 #define ST_GEN_IDX ST_FLAGS_IDX
1995 #endif 2001 #endif
1996 2002
1997 #ifdef HAVE_STRUCT_STAT_ST_BIRTHTIME 2003 #ifdef HAVE_STRUCT_STAT_ST_BIRTHTIME
1998 #define ST_BIRTHTIME_IDX (ST_GEN_IDX+1) 2004 #define ST_BIRTHTIME_IDX (ST_GEN_IDX+1)
1999 #else 2005 #else
2000 #define ST_BIRTHTIME_IDX ST_GEN_IDX 2006 #define ST_BIRTHTIME_IDX ST_GEN_IDX
2007 #endif
2008
2009 #ifdef HAVE_STRUCT_STAT_ST_FILE_ATTRIBUTES
2010 #define ST_FILE_ATTRIBUTES_IDX (ST_BIRTHTIME_IDX+1)
2011 #else
2012 #define ST_FILE_ATTRIBUTES_IDX ST_BIRTHTIME_IDX
2001 #endif 2013 #endif
2002 2014
2003 static PyStructSequence_Desc stat_result_desc = { 2015 static PyStructSequence_Desc stat_result_desc = {
2004 "stat_result", /* name */ 2016 "stat_result", /* name */
2005 stat_result__doc__, /* doc */ 2017 stat_result__doc__, /* doc */
2006 stat_result_fields, 2018 stat_result_fields,
2007 10 2019 10
2008 }; 2020 };
2009 2021
2010 PyDoc_STRVAR(statvfs_result__doc__, 2022 PyDoc_STRVAR(statvfs_result__doc__,
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
2259 } else { 2271 } else {
2260 val = PyLong_FromLong((long)bsec); 2272 val = PyLong_FromLong((long)bsec);
2261 } 2273 }
2262 PyStructSequence_SET_ITEM(v, ST_BIRTHTIME_IDX, 2274 PyStructSequence_SET_ITEM(v, ST_BIRTHTIME_IDX,
2263 val); 2275 val);
2264 } 2276 }
2265 #endif 2277 #endif
2266 #ifdef HAVE_STRUCT_STAT_ST_FLAGS 2278 #ifdef HAVE_STRUCT_STAT_ST_FLAGS
2267 PyStructSequence_SET_ITEM(v, ST_FLAGS_IDX, 2279 PyStructSequence_SET_ITEM(v, ST_FLAGS_IDX,
2268 PyLong_FromLong((long)st->st_flags)); 2280 PyLong_FromLong((long)st->st_flags));
2281 #endif
2282 #ifdef HAVE_STRUCT_STAT_ST_FILE_ATTRIBUTES
2283 PyStructSequence_SET_ITEM(v, ST_FILE_ATTRIBUTES_IDX,
2284 PyLong_FromUnsignedLong(st->st_file_attributes));
2269 #endif 2285 #endif
2270 2286
2271 if (PyErr_Occurred()) { 2287 if (PyErr_Occurred()) {
2272 Py_DECREF(v); 2288 Py_DECREF(v);
2273 return NULL; 2289 return NULL;
2274 } 2290 }
2275 2291
2276 return v; 2292 return v;
2277 } 2293 }
2278 2294
(...skipping 10074 matching lines...) Expand 10 before | Expand all | Expand 10 after
12353 PyModule_AddObject(m, "_have_functions", list); 12369 PyModule_AddObject(m, "_have_functions", list);
12354 12370
12355 initialized = 1; 12371 initialized = 1;
12356 12372
12357 return m; 12373 return m;
12358 } 12374 }
12359 12375
12360 #ifdef __cplusplus 12376 #ifdef __cplusplus
12361 } 12377 }
12362 #endif 12378 #endif
OLDNEW
« no previous file with comments | « Lib/test/test_stat.py ('k') | Modules/_stat.c » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+