[Python-checkins] cpython: Define S_IFMT and S_IFLNK in pyport.h so posixmodule.c can use named constants

christian.heimes python-checkins at python.org
Sun Jun 23 23:56:56 CEST 2013


http://hg.python.org/cpython/rev/d26e3940fece
changeset:   84301:d26e3940fece
user:        Christian Heimes <christian at cheimes.de>
date:        Sun Jun 23 23:56:05 2013 +0200
summary:
  Define S_IFMT and S_IFLNK in pyport.h so posixmodule.c can use named constants instead
of arbitrary looking numbers.

files:
  Include/pyport.h      |  15 ++++++++-------
  Modules/posixmodule.c |   4 ++--
  2 files changed, 10 insertions(+), 9 deletions(-)


diff --git a/Include/pyport.h b/Include/pyport.h
--- a/Include/pyport.h
+++ b/Include/pyport.h
@@ -393,9 +393,15 @@
 #include <stat.h>
 #endif
 
-#if defined(PYCC_VACPP)
+#ifndef S_IFMT
 /* VisualAge C/C++ Failed to Define MountType Field in sys/stat.h */
-#define S_IFMT (S_IFDIR|S_IFCHR|S_IFREG)
+#define S_IFMT 0170000
+#endif
+
+#ifndef S_IFLNK
+/* Windows doesn't define S_IFLNK but posixmodule.c maps
+ * IO_REPARSE_TAG_SYMLINK to S_IFLNK */
+#  define S_IFLNK 0120000
 #endif
 
 #ifndef S_ISREG
@@ -410,11 +416,6 @@
 #define S_ISCHR(x) (((x) & S_IFMT) == S_IFCHR)
 #endif
 
-#ifndef S_ISBLK
-#define S_ISBLK(x) (((x) & S_IFMT) == S_IFBLK)
-#endif
-
-
 #ifdef __cplusplus
 /* Move this down here since some C++ #include's don't like to be included
    inside an extern "C" */
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -1405,9 +1405,9 @@
     result->st_ino = (((__int64)info->nFileIndexHigh)<<32) + info->nFileIndexLow;
     if (reparse_tag == IO_REPARSE_TAG_SYMLINK) {
         /* first clear the S_IFMT bits */
-        result->st_mode ^= (result->st_mode & 0170000);
+        result->st_mode ^= (result->st_mode & S_IFMT);
         /* now set the bits that make this a symlink */
-        result->st_mode |= 0120000;
+        result->st_mode |= S_IFLNK;
     }
 
     return 0;

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list