For consistency, use "cdef extern" everywhere instead of "cdef import"
[invirt/packages/python-afs.git] / afs / afs.pyx
index 77456b4..f7f167b 100644 (file)
@@ -5,8 +5,8 @@ General PyAFS utilities, such as error handling
 import sys
 
 # otherwise certain headers are unhappy
-cdef import from "netinet/in.h": pass
-cdef import from "afs/vice.h": pass
+cdef extern from "netinet/in.h": pass
+cdef extern from "afs/vice.h": pass
 
 cdef int _init = 0
 
@@ -19,6 +19,24 @@ cdef extern int pioctl_read(char *dir, afs_int32 op, void *buffer, unsigned shor
     blob.out_size = size
     blob.out = buffer
     code = pioctl(dir, op, &blob, follow)
+    # This might work with the rest of OpenAFS, but I'm not convinced
+    # the rest of it is consistent
+    if code == -1:
+        raise OSError(errno, strerror(errno))
+    pyafs_error(code)
+    return code
+
+cdef extern int pioctl_write(char *dir, afs_int32 op, char *buffer, afs_int32 follow) except -1:
+    cdef ViceIoctl blob
+    cdef afs_int32 code
+    blob.cin = buffer
+    blob.in_size = 1 + strlen(buffer)
+    blob.out_size = 0
+    code = pioctl(dir, op, &blob, follow)
+    # This might work with the rest of OpenAFS, but I'm not convinced
+    # the rest of it is consistent
+    if code == -1:
+        raise OSError(errno, strerror(errno))
     pyafs_error(code)
     return code