[pypy-svn] r15365 - in pypy/dist/pypy/translator/c: . src test

cfbolz at codespeak.net cfbolz at codespeak.net
Fri Jul 29 18:30:26 CEST 2005


Author: cfbolz
Date: Fri Jul 29 18:30:24 2005
New Revision: 15365

Modified:
   pypy/dist/pypy/translator/c/extfunc.py
   pypy/dist/pypy/translator/c/src/ll_os.h
   pypy/dist/pypy/translator/c/test/test_extfunc.py
Log:
added os.ftruncate to the c backend


Modified: pypy/dist/pypy/translator/c/extfunc.py
==============================================================================
--- pypy/dist/pypy/translator/c/extfunc.py	(original)
+++ pypy/dist/pypy/translator/c/extfunc.py	Fri Jul 29 18:30:24 2005
@@ -18,6 +18,7 @@
     ll_os  .ll_os_fstat:   'LL_os_fstat',
     ll_os  .ll_os_lseek:   'LL_os_lseek',
     ll_os  .ll_os_isatty:  'LL_os_isatty',
+    ll_os  .ll_os_ftruncate:'LL_os_ftruncate',
     ll_time.ll_time_clock: 'LL_time_clock',
     ll_time.ll_time_sleep: 'LL_time_sleep',
     ll_time.ll_time_time:  'LL_time_time',

Modified: pypy/dist/pypy/translator/c/src/ll_os.h
==============================================================================
--- pypy/dist/pypy/translator/c/src/ll_os.h	(original)
+++ pypy/dist/pypy/translator/c/src/ll_os.h	Fri Jul 29 18:30:24 2005
@@ -160,3 +160,10 @@
     return (int)isatty((int)fd);
 }
 
+void LL_os_ftruncate(long fd, long length) { /*XXX add longfile support */
+    int res;
+    res = ftruncate((int)fd, (off_t)length);
+    if (res < 0) {
+	RAISE_OSERROR(errno);
+    }
+}

Modified: pypy/dist/pypy/translator/c/test/test_extfunc.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_extfunc.py	(original)
+++ pypy/dist/pypy/translator/c/test/test_extfunc.py	Fri Jul 29 18:30:24 2005
@@ -77,6 +77,22 @@
     assert open(filename, 'r').read() == "hello world\n"
     os.unlink(filename)
 
+def test_ftruncate():
+    filename = str(udir.join('test_open_read_write_close.txt'))
+    def does_stuff():
+        fd = os.open(filename, os.O_WRONLY | os.O_CREAT, 0777)
+        os.write(fd, "hello world\n")
+        os.close(fd)
+        fd = os.open(filename, os.O_RDWR, 0777)
+        os.ftruncate(fd, 5)
+        data = os.read(fd, 500)
+        assert data == "hello"
+        os.close(fd)
+    does_stuff()
+    f1 = compile(does_stuff, [])
+    f1()
+    os.unlink(filename)
+
 def test_os_stat():
     filename = str(py.magic.autopath())
     def call_stat():



More information about the Pypy-commit mailing list