From 5f937a7b8b1ba766ffada44d27f84ab1a43dc980 Mon Sep 17 00:00:00 2001 From: Hye-Shik Chang Date: Thu, 2 Jun 2005 13:09:30 +0000 Subject: Patch #1212117: Add optional attribute st_flags to os.stat_result when the member is available on the platform. (Contributed by Diego Petteno) --- Doc/lib/libos.tex | 1 + Misc/NEWS | 3 ++ Modules/posixmodule.c | 17 +++++++- configure | 112 +++++++++++++++++++++++++++++++++++++++++++++++++- configure.in | 1 + pyconfig.h.in | 3 ++ 6 files changed, 134 insertions(+), 3 deletions(-) diff --git a/Doc/lib/libos.tex b/Doc/lib/libos.tex index d38e9be..2d0327f 100644 --- a/Doc/lib/libos.tex +++ b/Doc/lib/libos.tex @@ -966,6 +966,7 @@ also be available: \member{st_blocks} (number of blocks allocated for file), \member{st_blksize} (filesystem blocksize), \member{st_rdev} (type of device if an inode device). +\member{st_flags} (user defined flags for file). On Mac OS systems, the following attributes may also be available: \member{st_rsize}, diff --git a/Misc/NEWS b/Misc/NEWS index 0ea2b54..196d762 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -88,6 +88,9 @@ Core and builtins Extension Modules ----------------- +- Patch #1212117: os.stat().st_flags is now accessible as a attribute + if available on the platform. + - Patch #1103951: Expose O_SHLOCK and O_EXLOCK in the posix module if available on the platform. diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 79d5e71..e4a0200 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -674,8 +674,8 @@ This object may be accessed either as a tuple of\n\ (mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime)\n\ or via the attributes st_mode, st_ino, st_dev, st_nlink, st_uid, and so on.\n\ \n\ -Posix/windows: If your platform supports st_blksize, st_blocks, or st_rdev,\n\ -they are available as attributes only.\n\ +Posix/windows: If your platform supports st_blksize, st_blocks, st_rdev,\n\ +or st_flags, they are available as attributes only.\n\ \n\ See os.stat for more information."); @@ -703,6 +703,9 @@ static PyStructSequence_Field stat_result_fields[] = { #ifdef HAVE_STRUCT_STAT_ST_RDEV {"st_rdev", "device type (if inode device)"}, #endif +#ifdef HAVE_STRUCT_STAT_ST_FLAGS + {"st_flags", "user defined flags for file"}, +#endif {0} }; @@ -724,6 +727,12 @@ static PyStructSequence_Field stat_result_fields[] = { #define ST_RDEV_IDX ST_BLOCKS_IDX #endif +#ifdef HAVE_STRUCT_STAT_ST_FLAGS +#define ST_FLAGS_IDX (ST_RDEV_IDX+1) +#else +#define ST_FLAGS_IDX ST_RDEV_IDX +#endif + static PyStructSequence_Desc stat_result_desc = { "stat_result", /* name */ stat_result__doc__, /* doc */ @@ -887,6 +896,10 @@ _pystat_fromstructstat(STRUCT_STAT st) PyStructSequence_SET_ITEM(v, ST_RDEV_IDX, PyInt_FromLong((long)st.st_rdev)); #endif +#ifdef HAVE_STRUCT_STAT_ST_FLAGS + PyStructSequence_SET_ITEM(v, ST_FLAGS_IDX, + PyInt_FromLong((long)st.st_flags)); +#endif if (PyErr_Occurred()) { Py_DECREF(v); diff --git a/configure b/configure index 0984980..2e45be0 100755 --- a/configure +++ b/configure @@ -1,5 +1,5 @@ #! /bin/sh -# From configure.in Revision: 1.483 . +# From configure.in Revision: 1.484 . # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.59 for python 2.5. # @@ -16414,6 +16414,116 @@ _ACEOF fi +echo "$as_me:$LINENO: checking for struct stat.st_flags" >&5 +echo $ECHO_N "checking for struct stat.st_flags... $ECHO_C" >&6 +if test "${ac_cv_member_struct_stat_st_flags+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default +int +main () +{ +static struct stat ac_aggr; +if (ac_aggr.st_flags) +return 0; + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_member_struct_stat_st_flags=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default +int +main () +{ +static struct stat ac_aggr; +if (sizeof ac_aggr.st_flags) +return 0; + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_member_struct_stat_st_flags=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_member_struct_stat_st_flags=no +fi +rm -f conftest.err conftest.$ac_objext conftest.$ac_ext +fi +rm -f conftest.err conftest.$ac_objext conftest.$ac_ext +fi +echo "$as_me:$LINENO: result: $ac_cv_member_struct_stat_st_flags" >&5 +echo "${ECHO_T}$ac_cv_member_struct_stat_st_flags" >&6 +if test $ac_cv_member_struct_stat_st_flags = yes; then + +cat >>confdefs.h <<_ACEOF +#define HAVE_STRUCT_STAT_ST_FLAGS 1 +_ACEOF + + +fi + echo "$as_me:$LINENO: checking for struct stat.st_blocks" >&5 echo $ECHO_N "checking for struct stat.st_blocks... $ECHO_C" >&6 if test "${ac_cv_member_struct_stat_st_blocks+set}" = set; then diff --git a/configure.in b/configure.in index 6f292f9..101fd44 100644 --- a/configure.in +++ b/configure.in @@ -2421,6 +2421,7 @@ AC_STRUCT_TM AC_STRUCT_TIMEZONE AC_CHECK_MEMBERS([struct stat.st_rdev]) AC_CHECK_MEMBERS([struct stat.st_blksize]) +AC_CHECK_MEMBERS([struct stat.st_flags]) AC_STRUCT_ST_BLOCKS AC_MSG_CHECKING(for time.h that defines altzone) diff --git a/pyconfig.h.in b/pyconfig.h.in index 1ce0397..a60e4da 100644 --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -489,6 +489,9 @@ /* Define to 1 if `st_blocks' is member of `struct stat'. */ #undef HAVE_STRUCT_STAT_ST_BLOCKS +/* Define to 1 if `st_flags' is member of `struct stat'. */ +#undef HAVE_STRUCT_STAT_ST_FLAGS + /* Define to 1 if `st_rdev' is member of `struct stat'. */ #undef HAVE_STRUCT_STAT_ST_RDEV -- cgit v0.12