Author: Ronan Lamy <[email protected]>
Branch: rposix-for-3
Changeset: r83550:464d641a9035
Date: 2016-04-06 20:32 +0100
http://bitbucket.org/pypy/pypy/changeset/464d641a9035/
Log: Add wrapper for fstatat()
diff --git a/rpython/rlib/rposix_stat.py b/rpython/rlib/rposix_stat.py
--- a/rpython/rlib/rposix_stat.py
+++ b/rpython/rlib/rposix_stat.py
@@ -23,6 +23,7 @@
from rpython.rlib.rarithmetic import intmask
from rpython.rlib.rposix import (
replace_os_function, handle_posix_error, _as_bytes0)
+from rpython.rlib import rposix
_WIN32 = sys.platform.startswith('win')
_LINUX = sys.platform.startswith('linux')
@@ -504,6 +505,23 @@
path = traits.as_str0(path)
return win32_xstat(traits, path, traverse=False)
+if rposix.HAVE_FSTATAT:
+ from rpython.rlib.rposix import AT_FDCWD, AT_SYMLINK_NOFOLLOW
+ c_fstatat = rffi.llexternal('fstatat',
+ [rffi.INT, rffi.CCHARP, STAT_STRUCT, rffi.INT], rffi.INT,
+ compilation_info=compilation_info,
+ save_err=rffi.RFFI_SAVE_ERRNO, macro=True)
+
+ def fstatat(pathname, dir_fd=AT_FDCWD, follow_symlinks=True):
+ if follow_symlinks:
+ flags = 0
+ else:
+ flags = AT_SYMLINK_NOFOLLOW
+ with lltype.scoped_alloc(STAT_STRUCT.TO) as stresult:
+ error = c_fstatat(dir_fd, pathname, stresult, flags)
+ handle_posix_error('fstatat', error)
+ return build_stat_result(stresult)
+
@replace_os_function('fstatvfs')
def fstatvfs(fd):
with lltype.scoped_alloc(STATVFS_STRUCT.TO) as stresult:
diff --git a/rpython/rlib/test/test_rposix_stat.py
b/rpython/rlib/test/test_rposix_stat.py
--- a/rpython/rlib/test/test_rposix_stat.py
+++ b/rpython/rlib/test/test_rposix_stat.py
@@ -56,3 +56,13 @@
except OSError, e:
py.test.skip("the underlying os.fstatvfs() failed: %s" % e)
rposix_stat.fstatvfs(0)
+
[email protected]("not hasattr(rposix_stat, 'fstatat')")
+def test_fstatat(tmpdir):
+ tmpdir.join('file').write('text')
+ dirfd = os.open(str(tmpdir), os.O_RDONLY)
+ try:
+ result = rposix_stat.fstatat('file', dir_fd=dirfd,
follow_symlinks=False)
+ finally:
+ os.close(dirfd)
+ assert result.st_atime == tmpdir.join('file').atime()
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit