From b8f45f026ace3df864efac5d49a62be4a0fc9eae Mon Sep 17 00:00:00 2001 From: René 'Necoro' Neumann Date: Fri, 24 Jul 2009 21:30:40 +0200 Subject: First eix stuff --- portato/eix/eix_utils.pyx | 72 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 portato/eix/eix_utils.pyx (limited to 'portato/eix/eix_utils.pyx') 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 = 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 = 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 = 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 -- cgit v1.2.3-54-g00ecf tter'>committer
Commit message (Expand)AuthorFilesLines
2008-03-06Use 'nofork' instead of 'nolistener'René 'Necoro' Neumann1-3/+3
2008-03-05Install glade files into template dir and not data dirRené 'Necoro' Neumann2-2/+1
2008-03-05Added dependency listRené 'Necoro' Neumann3-117/+237