From 9fca19ecc36f3225e79c4a811e1cd24883ae92dc Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Mon, 18 Sep 2006 06:59:48 +0000 Subject: [PATCH] * Added errno support to the kernel. --- cucul/cucul.c | 14 +++++++------- kernel/kernel.c | 7 +++++-- kernel/kernel.h | 14 ++++++++++---- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/cucul/cucul.c b/cucul/cucul.c index 64e6b55..dfe85f9 100644 --- a/cucul/cucul.c +++ b/cucul/cucul.c @@ -98,13 +98,13 @@ cucul_canvas_t * cucul_create_canvas(unsigned int width, unsigned int height) if(ret < 0) { -#if defined(HAVE_ERRNO_H) && !defined(__KERNEL__) +#if defined(HAVE_ERRNO_H) int saved_errno = errno; #endif free(cv->allattr); free(cv->allchars); free(cv); -#if defined(HAVE_ERRNO_H) && !defined(__KERNEL__) +#if defined(HAVE_ERRNO_H) errno = saved_errno; #endif return NULL; @@ -116,7 +116,7 @@ cucul_canvas_t * cucul_create_canvas(unsigned int width, unsigned int height) return cv; nomem: -#if defined(HAVE_ERRNO_H) && !defined(__KERNEL__) +#if defined(HAVE_ERRNO_H) errno = ENOMEM; #endif return NULL; @@ -152,7 +152,7 @@ int cucul_set_canvas_size(cucul_canvas_t *cv, unsigned int width, { if(cv->refcount) { -#if defined(HAVE_ERRNO_H) && !defined(__KERNEL__) +#if defined(HAVE_ERRNO_H) errno = EBUSY; #endif return -1; @@ -246,7 +246,7 @@ int cucul_free_canvas(cucul_canvas_t *cv) if(cv->refcount) { -#if defined(HAVE_ERRNO_H) && !defined(__KERNEL__) +#if defined(HAVE_ERRNO_H) errno = EBUSY; #endif return -1; @@ -316,7 +316,7 @@ int _cucul_set_canvas_size(cucul_canvas_t *cv, unsigned int width, new_size * sizeof(uint32_t)); if(!cv->allchars[f] || !cv->allattr[f]) { -#if defined(HAVE_ERRNO_H) && !defined(__KERNEL__) +#if defined(HAVE_ERRNO_H) errno = ENOMEM; #endif return -1; @@ -405,7 +405,7 @@ int _cucul_set_canvas_size(cucul_canvas_t *cv, unsigned int width, new_size * sizeof(uint32_t)); if(!cv->allchars[f] || !cv->allattr[f]) { -#if defined(HAVE_ERRNO_H) && !defined(__KERNEL__) +#if defined(HAVE_ERRNO_H) errno = ENOMEM; #endif return -1; diff --git a/kernel/kernel.c b/kernel/kernel.c index 7241d96..fb7d84f 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -2,6 +2,7 @@ * libcucul Canvas for ultrafast compositing of Unicode letters * libcaca Colour ASCII-Art library * Copyright (c) 2006 Sam Hocevar + * 2006 Jean-Yves Lamoureux * All Rights Reserved * * $Id$ @@ -332,6 +333,10 @@ double sqrt(double x) return ret; } +/* errno.h stuff */ +int errno = 0; + +/* arpa/inet.h functions */ /* XXX FIXME Converts only from little endian to big endian (x86) */ unsigned int htonl(unsigned int hostlong) @@ -345,6 +350,4 @@ unsigned short htons(unsigned short hostlong) return ((hostlong&0xFF00)>>8)|((hostlong&0x00FF)<<8); } - - #endif /* __KERNEL__ */ diff --git a/kernel/kernel.h b/kernel/kernel.h index 2f79c54..2faac3f 100644 --- a/kernel/kernel.h +++ b/kernel/kernel.h @@ -17,8 +17,6 @@ * that must be used when building libcucul and libcaca into a kernel. */ -#ifndef __KERNEL_H_ -#define __KERNEL_H_ /* Various defines */ #define NULL ((void *)0) #define BUFSIZ 4096 @@ -108,7 +106,6 @@ int sscanf(const char *str, const char *format, ...); void usleep(unsigned long usec); int getpid(void); - /* time.h functions */ int gettimeofday(struct timeval *tv, struct timezone *tz); int time(void *); @@ -118,8 +115,17 @@ double cos(double x); double sin(double x); double sqrt(double x); +/* errno.h functions */ +#define ENOENT 2 /* No such file or directory */ +#define ENOMEM 12 /* Out of memory */ +#define EBUSY 16 /* Device or resource busy */ +#define ENODEV 19 /* No such device */ +#define EINVAL 22 /* Invalid argument */ +#define ENOTTY 25 /* Not a typewriter */ +#define ENOSYS 38 /* Function not implemented */ +extern int errno; + /* arpa/inet.h functions */ unsigned int htonl(unsigned int hostlong); unsigned short htons(unsigned short hostlong); -#endif /* __KERNEL_H_ */