summaryrefslogtreecommitdiff
path: root/portato/eix/eix_utils.pyx
diff options
context:
space:
mode:
Diffstat (limited to 'portato/eix/eix_utils.pyx')
-rw-r--r--portato/eix/eix_utils.pyx72
1 files changed, 72 insertions, 0 deletions
diff --git a/portato/eix/eix_utils.pyx b/portato/eix/eix_utils.pyx
new file mode 100644
index 0000000..57fa5d7
--- /dev/null
+++ b/portato/eix/eix_utils.pyx
@@ -0,0 +1,72 @@
+class EndOfFileError (IOError):
+
+ def __init__ (self, filename = None):
+ self.message = "End of file reached while not expecting it"
+ self.filename = filename
+
+ def __str__ (self):
+ if self.filename is not None:
+ return "%s: %s" % (self.message, self.filename)
+ else:
+ return self.message
+
+cdef char* strdup (char * other) except NULL:
+ cdef size_t len
+ cdef char* new
+
+ if other is NULL:
+ return NULL
+
+ len = strlen(other)
+ new = <char*>PyMem_Malloc(len+1)
+
+ if new is NULL:
+ raise MemoryError, "Malloc of new string copy"
+ return NULL
+
+ return strcpy(new, other)
+
+
+cdef File* fopen (char* path, char* mode) except NULL:
+ cdef File* f
+
+ f = <File*> PyMem_Malloc(sizeof(File))
+
+ if f is NULL:
+ raise MemoryError, "Malloc of File"
+ return NULL
+
+ f.file = c_fopen(path, mode)
+
+ if f.file is NULL:
+ raise IOError, (errno, strerror(errno), path)
+ return NULL
+
+ f.name = strdup(path)
+
+ if f.name is NULL:
+ return NULL
+
+ return f
+
+cdef void fclose (File* f):
+ c_fclose(f.file)
+ ffree(f.name)
+ PyMem_Free(f)
+
+cdef void ffree (void* p):
+ PyMem_Free(p)
+
+cdef char* fget (File* f, size_t n) except NULL:
+ cdef char* buf
+ buf = <char*> PyMem_Malloc(n)
+
+ if buf is NULL:
+ raise MemoryError, "Malloc"
+ return NULL
+
+ if (fread(buf, 1, n, f.file) != n):
+ PyMem_Free(buf)
+ raise EndOfFileError, f.name
+
+ return buf
it/portato/gui/qt/windows.py?id=6fdf641424e50fb7515b843612b0625e31c4cf02&follow=1'>Added Qt-Terminalnecoro4-4/+213 2007-04-06First qt draftnecoro6-1/+796 2007-04-04showed masked packages unmasked by the user similar to stable marked testing ...necoro5-13/+40 2007-03-31changed changelognecoro1-1/+2 2007-03-31Some small changes for etcproposals 1.1necoro1-2/+2 2007-03-31Some small changes for etcproposals 1.1necoro2-3/+3 2007-03-31Some small changes for etcproposals 1.1necoro1-6/+13 2007-03-31Allowed Plugins to have a menunecoro7-201/+315 2007-03-15Added etc-proposals pluginnecoro7-28/+121 2007-03-10Added USE_EXPAND-supportnecoro5-11/+63 2007-03-10Added plugin-data to about-dialognecoro3-197/+264