[pypy-commit] pypy rposix-for-3: Add fchmodat(), fchownat()
rlamy
pypy.commits at gmail.com
Thu Mar 24 02:13:43 EDT 2016
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: rposix-for-3
Changeset: r83312:ef94621301a9
Date: 2016-03-24 06:07 +0000
http://bitbucket.org/pypy/pypy/changeset/ef94621301a9/
Log: Add fchmodat(), fchownat()
diff --git a/rpython/rlib/rposix.py b/rpython/rlib/rposix.py
--- a/rpython/rlib/rposix.py
+++ b/rpython/rlib/rposix.py
@@ -1739,6 +1739,7 @@
AT_SYMLINK_NOFOLLOW = rffi_platform.DefinedConstantInteger('AT_SYMLINK_NOFOLLOW')
AT_EACCESS = rffi_platform.DefinedConstantInteger('AT_EACCESS')
AT_REMOVEDIR = rffi_platform.DefinedConstantInteger('AT_REMOVEDIR')
+ AT_EMPTY_PATH = rffi_platform.DefinedConstantInteger('AT_EMPTY_PATH')
UTIME_NOW = rffi_platform.DefinedConstantInteger('UTIME_NOW')
UTIME_OMIT = rffi_platform.DefinedConstantInteger('UTIME_OMIT')
TIMESPEC = rffi_platform.Struct('struct timespec', [
@@ -1772,6 +1773,34 @@
error = c_faccessat(dir_fd, pathname, mode, flags)
return error == 0
+if HAVE_FCHMODAT:
+ c_fchmodat = external('fchmodat',
+ [rffi.INT, rffi.CCHARP, rffi.INT, rffi.INT], rffi.INT,
+ save_err=rffi.RFFI_SAVE_ERRNO,)
+
+ def fchmodat(path, mode, dir_fd=AT_FDCWD, follow_symlinks=True):
+ if follow_symlinks:
+ flag = 0
+ else:
+ flag = AT_SYMLINK_NOFOLLOW
+ error = c_fchmodat(dir_fd, path, mode, flag)
+ handle_posix_error('fchmodat', error)
+
+if HAVE_FCHOWNAT:
+ c_fchownat = external('fchownat',
+ [rffi.INT, rffi.CCHARP, rffi.INT, rffi.INT, rffi.INT], rffi.INT,
+ save_err=rffi.RFFI_SAVE_ERRNO,)
+
+ def fchownat(path, owner, group, dir_fd=AT_FDCWD,
+ follow_symlinks=True, empty_path=False):
+ flag = 0
+ if not follow_symlinks:
+ flag |= AT_SYMLINK_NOFOLLOW
+ if empty_path:
+ flag |= AT_EMPTY_PATH
+ error = c_fchownat(dir_fd, path, owner, group, flag)
+ handle_posix_error('fchownat', error)
+
if HAVE_LINKAT:
c_linkat = external('linkat',
[rffi.INT, rffi.CCHARP, rffi.INT, rffi.CCHARP, rffi.INT], rffi.INT)
diff --git a/rpython/rlib/test/test_rposix.py b/rpython/rlib/test/test_rposix.py
--- a/rpython/rlib/test/test_rposix.py
+++ b/rpython/rlib/test/test_rposix.py
@@ -508,6 +508,16 @@
finally:
os.close(dirfd)
+ def test_fchmodat(self):
+ def f(dirfd):
+ return rposix.fchmodat('test_open_ascii', 0777, dirfd)
+
+ dirfd = os.open(os.path.dirname(self.ufilename), os.O_RDONLY)
+ try:
+ interpret(f, [dirfd]) # does not crash
+ finally:
+ os.close(dirfd)
+
class TestPosixUnicode(BasePosixUnicodeOrAscii):
def _get_filename(self):
More information about the pypy-commit
mailing list