"""
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)
int memcmp (void *s1, void *s2, 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)
int close (int fd)
cdef extern from "fcntl.h" :
int fcntl (int fd, int cmd, ...)
enum :
F_GETFL
F_SETFL
enum :
O_NONBLOCK
# set a specific flag(s) to the given value
cdef fcntl_set_flag (int fd, int flag, bint value)
cdef extern from "alloca.h" :
# XXX: this is unsafe because there is it may fail nastily for allocations that won't fit on the stack - SIGSEGV
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
#