qmsk/net/libc.pxd
author Tero Marttila <terom@fixme.fi>
Sun, 16 Aug 2009 21:13:36 +0300
changeset 12 314d47bdd4d9
parent 10 94b0d5a208c1
child 13 a1091632a8a7
permissions -rw-r--r--
full range of send/write operations
"""
    Libc stuff
"""

cdef extern from "stdint.h" :
    # yes, these are "wrong"
    ctypedef unsigned char uint8_t
    ctypedef unsigned short uint16_t
    ctypedef unsigned int uint32_t
    
    ctypedef signed char int8_t
    ctypedef signed short int16_t
    ctypedef signed int int32_t

cdef extern from "sys/types.h" :
    # potentially wrong...
    ctypedef signed long ssize_t

# <linux/types.h>
cdef extern from "linux/types.h" :
    ctypedef uint8_t __u8
    ctypedef uint16_t __u16
    ctypedef uint32_t __u32
    
    ctypedef int8_t __s8
    ctypedef int16_t __s16
    ctypedef int32_t __s32

cdef extern from "errno.h" :
    int errno
    
cdef extern from "string.h" :
    void* memcpy (void *dest, void *src, size_t n)
    void* memset (void *s, int c, size_t n)

    char* strerror (int errno)

cdef extern from "unistd.h" :
    ssize_t read (int fd, void *buf, size_t count)
    ssize_t write (int fd, void *buf, size_t count)

cdef extern from "alloca.h" :
    void* alloca (size_t size)

cdef extern from "sys/uio.h" :
    struct iovec :
        void *iov_base
        size_t iov_len
    
    ssize_t readv (int fd, iovec *iov, int iovcnt)
    ssize_t writev (int fd, iovec *iov, int iovcnt)

## general errno-based errors
#cdef class Errno (py.OSError) :
#    """
#        Some libc function returned an error code:
#
#            func        - the name of the function called
#            err         - the system error code
#            strerror    - human-readable error code -> message
#    """
#
#    cdef readonly char *func
#    cdef readonly int err
#    cdef readonly object strerror
#
#cdef class GAIError (py.OSError) :
#    """
#        Some libc GAI function returnd an error code:
#
#            func        - the name of the function called
#            err         - the GAI_* error code
#            strerror    - human-readable error code -> message
#    """
#
#    cdef readonly char *func
#    cdef readonly int err
#    cdef readonly object strerror
#