From e6942f9a09431ae3a071a1a9f0e983d1b7f8fcb2 Mon Sep 17 00:00:00 2001 From: "bernard.xiong@gmail.com" Date: Mon, 12 Nov 2012 02:08:27 +0000 Subject: [PATCH] Add more errno definitions. git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2401 bbd45198-f89e-11dd-88c7-29a3b14d5316 --- components/libc/minilibc/errno.h | 34 +++++++++++++++++++++++-------- components/libc/minilibc/rand.c | 7 +++---- components/libc/minilibc/stdint.h | 11 ++++++++++ components/libc/minilibc/string.c | 1 + components/libc/minilibc/string.h | 7 ------- 5 files changed, 41 insertions(+), 19 deletions(-) diff --git a/components/libc/minilibc/errno.h b/components/libc/minilibc/errno.h index 305b48871..74bed5196 100644 --- a/components/libc/minilibc/errno.h +++ b/components/libc/minilibc/errno.h @@ -47,13 +47,31 @@ #endif -#define EPERM 1 /* Not super-user */ -#define ESRCH 3 /* No such process */ -#define EINTR 4 /* Interrupted system call */ -#define ENFILE 23 /* Too many open files in system */ -#define EDEADLK 45 /* Deadlock condition */ -#define EBADMSG 77 /* Trying to read unreadable message */ -#define ETIMEDOUT 116 /* Connection timed out */ -#define ENOTSUP 134 /* Not supported */ +#define EPERM 1 /* Not super-user */ +#define ESRCH 3 /* No such process */ +#define EINTR 4 /* Interrupted system call */ +#define EFAULT 14 /* Bad address */ +#define ENFILE 23 /* Too many open files in system */ +#define ERANGE 34 /* Math result not representable */ +#define EDEADLK 45 /* Deadlock condition */ +#define EBADMSG 77 /* Trying to read unreadable message */ +#define EMSGSIZE 90 /* Message too long */ +#define ENOPROTOOPT 92 /* Protocol not available */ +#define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */ +#define EAFNOSUPPORT 97 /* Address family not supported by protocol */ +#define EADDRINUSE 98 /* Address already in use */ +#define ENETDOWN 100 /* Network is down */ +#define ENETUNREACH 101 /* Network is unreachable */ +#define ECONNABORTED 103 /* Software caused connection abort */ +#define ECONNRESET 104 /* Connection reset by peer */ +#define ENOBUFS 105 /* No buffer space available */ +#define ENOTCONN 107 /* Transport endpoint is not connected */ +#define EINPROGRESS 115 /* Operation now in progress */ +#define ETIMEDOUT 116 /* Connection timed out */ +#define EHOSTUNREACH 113 /* No route to host */ +#define EALREADY 114 /* Operation already in progress */ +#define ENOTSUP 134 /* Not supported */ +#define ENSRNOTFOUND 163 /* Domain name not found */ +#define EWOULDBLOCK EAGAIN /* Operation would block */ #endif diff --git a/components/libc/minilibc/rand.c b/components/libc/minilibc/rand.c index d97e91bdb..387d605d4 100644 --- a/components/libc/minilibc/rand.c +++ b/components/libc/minilibc/rand.c @@ -2,7 +2,7 @@ #include #include -static unsigned int seed=1; +static unsigned int _seed=1; /* Knuth's TAOCP section 3.6 */ #define M ((1U<<31) -1) @@ -10,7 +10,6 @@ static unsigned int seed=1; #define Q 44488 // M/A #define R 3399 // M%A; R < Q !!! -// FIXME: ISO C/SuS want a longer period int rand_r(unsigned int* seed) { int32_t X; @@ -24,12 +23,12 @@ int rand_r(unsigned int* seed) } int rand(void) { - return rand_r(&seed); + return rand_r(&_seed); } void srand(unsigned int i) { - seed=i; + _seed=i; } int random(void) __attribute__((alias("rand"))); diff --git a/components/libc/minilibc/stdint.h b/components/libc/minilibc/stdint.h index 6c8dd6bfa..11c07179a 100644 --- a/components/libc/minilibc/stdint.h +++ b/components/libc/minilibc/stdint.h @@ -32,4 +32,15 @@ typedef unsigned long long uint64_t; #define UINT16_MAX 0xffff #define UINT32_MAX 0xffffffffU +#ifndef __INT_MAX__ +#define __INT_MAX__ 2147483647 +#endif +#define INT_MIN (-1 - INT_MAX) +#define INT_MAX (__INT_MAX__) +#define UINT_MAX (INT_MAX * 2U + 1U) + +#define LONG_MAX ((long)(~0UL>>1)) +#define LONG_MIN (-LONG_MAX - 1) +#define ULONG_MAX (~0UL) + #endif diff --git a/components/libc/minilibc/string.c b/components/libc/minilibc/string.c index 52726f2cb..568e9795e 100644 --- a/components/libc/minilibc/string.c +++ b/components/libc/minilibc/string.c @@ -17,6 +17,7 @@ */ #include +#include #if !defined (RT_USING_NEWLIB) && defined (RT_USING_MINILIBC) #include "string.h" diff --git a/components/libc/minilibc/string.h b/components/libc/minilibc/string.h index f9cc9a659..4bfec8fec 100644 --- a/components/libc/minilibc/string.h +++ b/components/libc/minilibc/string.h @@ -28,13 +28,6 @@ #define SPECIAL (1 << 5) /* 0x */ #define LARGE (1 << 6) /* use 'ABCDEF' instead of 'abcdef' */ -#define INT_MAX ((int)(~0U>>1)) -#define INT_MIN (-INT_MAX - 1) -#define UINT_MAX (~0U) -#define LONG_MAX ((long)(~0UL>>1)) -#define LONG_MIN (-LONG_MAX - 1) -#define ULONG_MAX (~0UL) - #define _U 0x01 /* upper */ #define _L 0x02 /* lower */ #define _D 0x04 /* digit */ -- GitLab