diff options
| author | Bernard Xiong <[email protected]> | 2013-01-08 18:13:32 -0800 |
|---|---|---|
| committer | Bernard Xiong <[email protected]> | 2013-01-08 18:13:32 -0800 |
| commit | accace98e05eda28c116eb04502eb92d01b6ef1e (patch) | |
| tree | 4a425c96e0be3980779c8205c7c3fe2f1a144630 /components/libc | |
| parent | 1fab41d48a490f6483582147500d43f4ca889a8e (diff) | |
| parent | 02b8e9366f362926799bfaecc0891830ba62f646 (diff) | |
Merge pull request #8 from mbbill/correct_crlf
Correct crlf
Diffstat (limited to 'components/libc')
| -rw-r--r-- | components/libc/SConscript | 26 | ||||
| -rw-r--r-- | components/libc/minilibc/SConscript | 26 | ||||
| -rw-r--r-- | components/libc/minilibc/ctype.c | 106 | ||||
| -rw-r--r-- | components/libc/minilibc/ctype.h | 44 | ||||
| -rw-r--r-- | components/libc/minilibc/errno.h | 154 | ||||
| -rw-r--r-- | components/libc/minilibc/inttypes.h | 12 | ||||
| -rw-r--r-- | components/libc/minilibc/math.c | 338 | ||||
| -rw-r--r-- | components/libc/minilibc/math.h | 8 | ||||
| -rw-r--r-- | components/libc/minilibc/qsort.c | 88 | ||||
| -rw-r--r-- | components/libc/minilibc/stddef.h | 14 | ||||
| -rw-r--r-- | components/libc/minilibc/stdint.h | 92 | ||||
| -rw-r--r-- | components/libc/minilibc/stdio.h | 16 | ||||
| -rw-r--r-- | components/libc/minilibc/stdlib.c | 154 | ||||
| -rw-r--r-- | components/libc/minilibc/stdlib.h | 74 | ||||
| -rw-r--r-- | components/libc/minilibc/sys/time.h | 86 | ||||
| -rw-r--r-- | components/libc/minilibc/time.c | 438 | ||||
| -rw-r--r-- | components/libc/minilibc/time.h | 12 | ||||
| -rw-r--r-- | components/libc/newlib/libc.h | 42 | ||||
| -rw-r--r-- | components/libc/newlib/sys/dirent.h | 114 | ||||
| -rw-r--r-- | components/libc/newlib/sys/statfs.h | 26 |
20 files changed, 935 insertions, 935 deletions
diff --git a/components/libc/SConscript b/components/libc/SConscript index e8c7d1a6b5..19494ea7c2 100644 --- a/components/libc/SConscript +++ b/components/libc/SConscript @@ -1,13 +1,13 @@ -# for libc component
-import os
-Import('RTT_ROOT')
-
-objs = []
-list = os.listdir(os.path.join(RTT_ROOT, 'components', 'libc'))
-
-for d in list:
- path = os.path.join(RTT_ROOT, 'components', 'libc', d)
- if os.path.isfile(os.path.join(path, 'SConscript')):
- objs = objs + SConscript(os.path.join(d, 'SConscript'))
-
-Return('objs')
+# for libc component +import os +Import('RTT_ROOT') + +objs = [] +list = os.listdir(os.path.join(RTT_ROOT, 'components', 'libc')) + +for d in list: + path = os.path.join(RTT_ROOT, 'components', 'libc', d) + if os.path.isfile(os.path.join(path, 'SConscript')): + objs = objs + SConscript(os.path.join(d, 'SConscript')) + +Return('objs') diff --git a/components/libc/minilibc/SConscript b/components/libc/minilibc/SConscript index d0cc5059c5..42f41a311d 100644 --- a/components/libc/minilibc/SConscript +++ b/components/libc/minilibc/SConscript @@ -1,13 +1,13 @@ -Import('RTT_ROOT')
-from building import *
-
-src = Glob('*.c')
-CPPPATH = [RTT_ROOT + '/components/libc/minilibc']
-CPPDEFINES = ['RT_USING_MINILIBC']
-group = DefineGroup('minilibc', src,
- depend = ['RT_USING_MINILIBC'],
- CPPPATH = CPPPATH,
- CPPDEFINES = CPPDEFINES
- )
-
-Return('group')
+Import('RTT_ROOT') +from building import * + +src = Glob('*.c') +CPPPATH = [RTT_ROOT + '/components/libc/minilibc'] +CPPDEFINES = ['RT_USING_MINILIBC'] +group = DefineGroup('minilibc', src, + depend = ['RT_USING_MINILIBC'], + CPPPATH = CPPPATH, + CPPDEFINES = CPPDEFINES + ) + +Return('group') diff --git a/components/libc/minilibc/ctype.c b/components/libc/minilibc/ctype.c index 4fd2dc8fb5..fed8f583a6 100644 --- a/components/libc/minilibc/ctype.c +++ b/components/libc/minilibc/ctype.c @@ -1,53 +1,53 @@ -/*
- * File : ctype.c
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) 2008, RT-Thread Development Team
- *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
- *
- * Change Logs:
- * Date Author Notes
- * 2008-08-14 Bernard the first version
- */
-
-#include <rtthread.h>
-#include <sys/types.h>
-
-#if !defined (RT_USING_NEWLIB) && defined (RT_USING_MINILIBC)
-#include "ctype.h"
-
-int isprint (int ch)
-{
- ch&=0x7f;
- return (ch>=32 && ch<127);
-}
-
-int isalpha(int ch)
-{
- return (unsigned int)((ch | 0x20) - 'a') < 26u;
-}
-
-int isdigit (int ch)
-{
- return (unsigned int)(ch - '0') < 10u;
-}
-
-int isspace(int ch)
-{
- switch(ch)
- {
- case ' ':
- case '\n':
- case '\f':
- case '\r':
- case '\t':
- case '\v':
- return 1;
- default:
- return 0;
- }
-}
-
-#endif
+/* + * File : ctype.c + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2008, RT-Thread Development Team + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rt-thread.org/license/LICENSE + * + * Change Logs: + * Date Author Notes + * 2008-08-14 Bernard the first version + */ + +#include <rtthread.h> +#include <sys/types.h> + +#if !defined (RT_USING_NEWLIB) && defined (RT_USING_MINILIBC) +#include "ctype.h" + +int isprint (int ch) +{ + ch&=0x7f; + return (ch>=32 && ch<127); +} + +int isalpha(int ch) +{ + return (unsigned int)((ch | 0x20) - 'a') < 26u; +} + +int isdigit (int ch) +{ + return (unsigned int)(ch - '0') < 10u; +} + +int isspace(int ch) +{ + switch(ch) + { + case ' ': + case '\n': + case '\f': + case '\r': + case '\t': + case '\v': + return 1; + default: + return 0; + } +} + +#endif diff --git a/components/libc/minilibc/ctype.h b/components/libc/minilibc/ctype.h index 9909b4a0b0..6b93490d36 100644 --- a/components/libc/minilibc/ctype.h +++ b/components/libc/minilibc/ctype.h @@ -1,22 +1,22 @@ -/*
- * File : ctype.h
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) 2008, RT-Thread Development Team
- *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
- *
- * Change Logs:
- * Date Author Notes
- * 2008-08-14 Bernard the first version
- */
-#ifndef __CTYPE_H__
-#define __CTYPE_H__
-
-int isprint(int c) __attribute__ ((__const__));
-int isalpha (int c) __attribute__ ((__const__));
-int isdigit (int ch) __attribute__ ((__const__));
-int isspace(int ch) __attribute__ ((__const__));
-
-#endif
+/* + * File : ctype.h + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2008, RT-Thread Development Team + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rt-thread.org/license/LICENSE + * + * Change Logs: + * Date Author Notes + * 2008-08-14 Bernard the first version + */ +#ifndef __CTYPE_H__ +#define __CTYPE_H__ + +int isprint(int c) __attribute__ ((__const__)); +int isalpha (int c) __attribute__ ((__const__)); +int isdigit (int ch) __attribute__ ((__const__)); +int isspace(int ch) __attribute__ ((__const__)); + +#endif diff --git a/components/libc/minilibc/errno.h b/components/libc/minilibc/errno.h index 74bed5196b..74b8296241 100644 --- a/components/libc/minilibc/errno.h +++ b/components/libc/minilibc/errno.h @@ -1,77 +1,77 @@ -#ifndef __ERRNO_H__
-#define __ERRNO_H__
-
-#ifdef RT_USING_DFS
-
-#include <dfs_def.h>
-
-/* using device error codes */
-#define ENOENT DFS_STATUS_ENOENT
-#define EIO DFS_STATUS_EIO
-#define ENXIO DFS_STATUS_ENXIO
-#define EBADF DFS_STATUS_EBADF
-#define EAGAIN DFS_STATUS_EAGAIN
-#define ENOMEM DFS_STATUS_ENOMEM
-#define EBUSY DFS_STATUS_EBUSY
-#define EEXIST DFS_STATUS_EEXIST
-#define EXDEV DFS_STATUS_EXDEV
-#define ENODEV DFS_STATUS_ENODEV
-#define ENOTDIR DFS_STATUS_ENOTDIR
-#define EISDIR DFS_STATUS_EISDIR
-#define EINVAL DFS_STATUS_EINVAL
-#define ENOSPC DFS_STATUS_ENOSPC
-#define EROFS DFS_STATUS_EROFS
-#define ENOSYS DFS_STATUS_ENOSYS
-#define ENOTEMPTY DFS_STATUS_ENOTEMPTY
-
-#else
-
-/* error codes */
-#define ENOENT 2 /* No such file or directory */
-#define EIO 5 /* I/O error */
-#define ENXIO 6 /* No such device or address */
-#define EBADF 9 /* Bad file number */
-#define EAGAIN 11 /* Try again */
-#define ENOMEM 12 /* no memory */
-#define EBUSY 16 /* Device or resource busy */
-#define EEXIST 17 /* File exists */
-#define EXDEV 18 /* Cross-device link */
-#define ENODEV 19 /* No such device */
-#define ENOTDIR 20 /* Not a directory */
-#define EISDIR 21 /* Is a directory */
-#define EINVAL 22 /* Invalid argument */
-#define ENOSPC 28 /* No space left on device */
-#define EROFS 30 /* Read-only file system */
-#define ENOSYS 38 /* Function not implemented */
-#define ENOTEMPTY 39 /* Directory not empty */
-
-#endif
-
-#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
+#ifndef __ERRNO_H__ +#define __ERRNO_H__ + +#ifdef RT_USING_DFS + +#include <dfs_def.h> + +/* using device error codes */ +#define ENOENT DFS_STATUS_ENOENT +#define EIO DFS_STATUS_EIO +#define ENXIO DFS_STATUS_ENXIO +#define EBADF DFS_STATUS_EBADF +#define EAGAIN DFS_STATUS_EAGAIN +#define ENOMEM DFS_STATUS_ENOMEM +#define EBUSY DFS_STATUS_EBUSY +#define EEXIST DFS_STATUS_EEXIST +#define EXDEV DFS_STATUS_EXDEV +#define ENODEV DFS_STATUS_ENODEV +#define ENOTDIR DFS_STATUS_ENOTDIR +#define EISDIR DFS_STATUS_EISDIR +#define EINVAL DFS_STATUS_EINVAL +#define ENOSPC DFS_STATUS_ENOSPC +#define EROFS DFS_STATUS_EROFS +#define ENOSYS DFS_STATUS_ENOSYS +#define ENOTEMPTY DFS_STATUS_ENOTEMPTY + +#else + +/* error codes */ +#define ENOENT 2 /* No such file or directory */ +#define EIO 5 /* I/O error */ +#define ENXIO 6 /* No such device or address */ +#define EBADF 9 /* Bad file number */ +#define EAGAIN 11 /* Try again */ +#define ENOMEM 12 /* no memory */ +#define EBUSY 16 /* Device or resource busy */ +#define EEXIST 17 /* File exists */ +#define EXDEV 18 /* Cross-device link */ +#define ENODEV 19 /* No such device */ +#define ENOTDIR 20 /* Not a directory */ +#define EISDIR 21 /* Is a directory */ +#define EINVAL 22 /* Invalid argument */ +#define ENOSPC 28 /* No space left on device */ +#define EROFS 30 /* Read-only file system */ +#define ENOSYS 38 /* Function not implemented */ +#define ENOTEMPTY 39 /* Directory not empty */ + +#endif + +#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/inttypes.h b/components/libc/minilibc/inttypes.h index e734f7a8e7..84e036a043 100644 --- a/components/libc/minilibc/inttypes.h +++ b/components/libc/minilibc/inttypes.h @@ -1,6 +1,6 @@ -#ifndef __INTTYPES_H__
-#define __INTTYPES_H__
-
-#include "stdint.h"
-
-#endif
+#ifndef __INTTYPES_H__ +#define __INTTYPES_H__ + +#include "stdint.h" + +#endif diff --git a/components/libc/minilibc/math.c b/components/libc/minilibc/math.c index 8fdce039e5..bcba6051a8 100644 --- a/components/libc/minilibc/math.c +++ b/components/libc/minilibc/math.c @@ -1,169 +1,169 @@ -#include <math.h>
-
-/*
- * COPYRIGHT: See COPYING in the top level directory
- * PROJECT: ReactOS CRT
- * FILE: lib/crt/math/cos.c
- * PURPOSE: Generic C Implementation of cos
- * PROGRAMMER: Timo Kreuzer ([email protected])
- */
-
-#define PRECISION 9
-#define M_PI 3.141592653589793238462643
-
-static double cos_off_tbl[] = {0.0, -M_PI/2., 0, -M_PI/2.};
-static double cos_sign_tbl[] = {1,-1,-1,1};
-
-static double sin_off_tbl[] = {0.0, -M_PI/2., 0, -M_PI/2.};
-static double sin_sign_tbl[] = {1,-1,-1,1};
-
-double sin(double x)
-{
- int quadrant;
- double x2, result;
-
- /* Calculate the quadrant */
- quadrant = x * (2./M_PI);
-
- /* Get offset inside quadrant */
- x = x - quadrant * (M_PI/2.);
-
- /* Normalize quadrant to [0..3] */
- quadrant = (quadrant - 1) & 0x3;
-
- /* Fixup value for the generic function */
- x += sin_off_tbl[quadrant];
-
- /* Calculate the negative of the square of x */
- x2 = - (x * x);
-
- /* This is an unrolled taylor series using <PRECISION> iterations
- * Example with 4 iterations:
- * result = 1 - x^2/2! + x^4/4! - x^6/6! + x^8/8!
- * To save multiplications and to keep the precision high, it's performed
- * like this:
- * result = 1 - x^2 * (1/2! - x^2 * (1/4! - x^2 * (1/6! - x^2 * (1/8!))))
- */
-
- /* Start with 0, compiler will optimize this away */
- result = 0;
-
-#if (PRECISION >= 10)
- result += 1./(1.*2*3*4*5*6*7*8*9*10*11*12*13*14*15*16*17*18*19*20);
- result *= x2;
-#endif
-#if (PRECISION >= 9)
- result += 1./(1.*2*3*4*5*6*7*8*9*10*11*12*13*14*15*16*17*18);
- result *= x2;
-#endif
-#if (PRECISION >= 8)
- result += 1./(1.*2*3*4*5*6*7*8*9*10*11*12*13*14*15*16);
- result *= x2;
-#endif
-#if (PRECISION >= 7)
- result += 1./(1.*2*3*4*5*6*7*8*9*10*11*12*13*14);
- result *= x2;
-#endif
-#if (PRECISION >= 6)
- result += 1./(1.*2*3*4*5*6*7*8*9*10*11*12);
- result *= x2;
-#endif
-#if (PRECISION >= 5)
- result += 1./(1.*2*3*4*5*6*7*8*9*10);
- result *= x2;
-#endif
- result += 1./(1.*2*3*4*5*6*7*8);
- result *= x2;
-
- result += 1./(1.*2*3*4*5*6);
- result *= x2;
-
- result += 1./(1.*2*3*4);
- result *= x2;
-
- result += 1./(1.*2);
- result *= x2;
-
- result += 1;
-
- /* Apply correct sign */
- result *= sin_sign_tbl[quadrant];
-
- return result;
-}
-
-double cos(double x)
-{
- int quadrant;
- double x2, result;
-
- /* Calculate the quadrant */
- quadrant = x * (2./M_PI);
-
- /* Get offset inside quadrant */
- x = x - quadrant * (M_PI/2.);
-
- /* Normalize quadrant to [0..3] */
- quadrant = quadrant & 0x3;
-
- /* Fixup value for the generic function */
- x += cos_off_tbl[quadrant];
-
- /* Calculate the negative of the square of x */
- x2 = - (x * x);
-
- /* This is an unrolled taylor series using <PRECISION> iterations
- * Example with 4 iterations:
- * result = 1 - x^2/2! + x^4/4! - x^6/6! + x^8/8!
- * To save multiplications and to keep the precision high, it's performed
- * like this:
- * result = 1 - x^2 * (1/2! - x^2 * (1/4! - x^2 * (1/6! - x^2 * (1/8!))))
- */
-
- /* Start with 0, compiler will optimize this away */
- result = 0;
-
-#if (PRECISION >= 10)
- result += 1./(1.*2*3*4*5*6*7*8*9*10*11*12*13*14*15*16*17*18*19*20);
- result *= x2;
-#endif
-#if (PRECISION >= 9)
- result += 1./(1.*2*3*4*5*6*7*8*9*10*11*12*13*14*15*16*17*18);
- result *= x2;
-#endif
-#if (PRECISION >= 8)
- result += 1./(1.*2*3*4*5*6*7*8*9*10*11*12*13*14*15*16);
- result *= x2;
-#endif
-#if (PRECISION >= 7)
- result += 1./(1.*2*3*4*5*6*7*8*9*10*11*12*13*14);
- result *= x2;
-#endif
-#if (PRECISION >= 6)
- result += 1./(1.*2*3*4*5*6*7*8*9*10*11*12);
- result *= x2;
-#endif
-#if (PRECISION >= 5)
- result += 1./(1.*2*3*4*5*6*7*8*9*10);
- result *= x2;
-#endif
- result += 1./(1.*2*3*4*5*6*7*8);
- result *= x2;
-
- result += 1./(1.*2*3*4*5*6);
- result *= x2;
-
- result += 1./(1.*2*3*4);
- result *= x2;
-
- result += 1./(1.*2);
- result *= x2;
-
- result += 1;
-
- /* Apply correct sign */
- result *= cos_sign_tbl[quadrant];
-
- return result;
-}
-
+#include <math.h> + +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS CRT + * FILE: lib/crt/math/cos.c + * PURPOSE: Generic C Implementation of cos + * PROGRAMMER: Timo Kreuzer ([email protected]) + */ + +#define PRECISION 9 +#define M_PI 3.141592653589793238462643 + +static double cos_off_tbl[] = {0.0, -M_PI/2., 0, -M_PI/2.}; +static double cos_sign_tbl[] = {1,-1,-1,1}; + +static double sin_off_tbl[] = {0.0, -M_PI/2., 0, -M_PI/2.}; +static double sin_sign_tbl[] = {1,-1,-1,1}; + +double sin(double x) +{ + int quadrant; + double x2, result; + + /* Calculate the quadrant */ + quadrant = x * (2./M_PI); + + /* Get offset inside quadrant */ + x = x - quadrant * (M_PI/2.); + + /* Normalize quadrant to [0..3] */ + quadrant = (quadrant - 1) & 0x3; + + /* Fixup value for the generic function */ + x += sin_off_tbl[quadrant]; + + /* Calculate the negative of the square of x */ + x2 = - (x * x); + + /* This is an unrolled taylor series using <PRECISION> iterations + * Example with 4 iterations: + * result = 1 - x^2/2! + x^4/4! - x^6/6! + x^8/8! + * To save multiplications and to keep the precision high, it's performed + * like this: + * result = 1 - x^2 * (1/2! - x^2 * (1/4! - x^2 * (1/6! - x^2 * (1/8!)))) + */ + + /* Start with 0, compiler will optimize this away */ + result = 0; + +#if (PRECISION >= 10) + result += 1./(1.*2*3*4*5*6*7*8*9*10*11*12*13*14*15*16*17*18*19*20); + result *= x2; +#endif +#if (PRECISION >= 9) + result += 1./(1.*2*3*4*5*6*7*8*9*10*11*12*13*14*15*16*17*18); + result *= x2; +#endif +#if (PRECISION >= 8) + result += 1./(1.*2*3*4*5*6*7*8*9*10*11*12*13*14*15*16); + result *= x2; +#endif +#if (PRECISION >= 7) + result += 1./(1.*2*3*4*5*6*7*8*9*10*11*12*13*14); + result *= x2; +#endif +#if (PRECISION >= 6) + result += 1./(1.*2*3*4*5*6*7*8*9*10*11*12); + result *= x2; +#endif +#if (PRECISION >= 5) + result += 1./(1.*2*3*4*5*6*7*8*9*10); + result *= x2; +#endif + result += 1./(1.*2*3*4*5*6*7*8); + result *= x2; + + result += 1./(1.*2*3*4*5*6); + result *= x2; + + result += 1./(1.*2*3*4); + result *= x2; + + result += 1./(1.*2); + result *= x2; + + result += 1; + + /* Apply correct sign */ + result *= sin_sign_tbl[quadrant]; + + return result; +} + +double cos(double x) +{ + int quadrant; + double x2, result; + + /* Calculate the quadrant */ + quadrant = x * (2./M_PI); + + /* Get offset inside quadrant */ + x = x - quadrant * (M_PI/2.); + + /* Normalize quadrant to [0..3] */ + quadrant = quadrant & 0x3; + + /* Fixup value for the generic function */ + x += cos_off_tbl[quadrant]; + + /* Calculate the negative of the square of x */ + x2 = - (x * x); + + /* This is an unrolled taylor series using <PRECISION> iterations + * Example with 4 iterations: + * result = 1 - x^2/2! + x^4/4! - x^6/6! + x^8/8! + * To save multiplications and to keep the precision high, it's performed + * like this: + * result = 1 - x^2 * (1/2! - x^2 * (1/4! - x^2 * (1/6! - x^2 * (1/8!)))) + */ + + /* Start with 0, compiler will optimize this away */ + result = 0; + +#if (PRECISION >= 10) + result += 1./(1.*2*3*4*5*6*7*8*9*10*11*12*13*14*15*16*17*18*19*20); + result *= x2; +#endif +#if (PRECISION >= 9) + result += 1./(1.*2*3*4*5*6*7*8*9*10*11*12*13*14*15*16*17*18); + result *= x2; +#endif +#if (PRECISION >= 8) + result += 1./(1.*2*3*4*5*6*7*8*9*10*11*12*13*14*15*16); + result *= x2; +#endif +#if (PRECISION >= 7) + result += 1./(1.*2*3*4*5*6*7*8*9*10*11*12*13*14); + result *= x2; +#endif +#if (PRECISION >= 6) + result += 1./(1.*2*3*4*5*6*7*8*9*10*11*12); + result *= x2; +#endif +#if (PRECISION >= 5) + result += 1./(1.*2*3*4*5*6*7*8*9*10); + result *= x2; +#endif + result += 1./(1.*2*3*4*5*6*7*8); + result *= x2; + + result += 1./(1.*2*3*4*5*6); + result *= x2; + + result += 1./(1.*2*3*4); + result *= x2; + + result += 1./(1.*2); + result *= x2; + + result += 1; + + /* Apply correct sign */ + result *= cos_sign_tbl[quadrant]; + + return result; +} + diff --git a/components/libc/minilibc/math.h b/components/libc/minilibc/math.h index ac480d534a..e2ce6f8e71 100644 --- a/components/libc/minilibc/math.h +++ b/components/libc/minilibc/math.h @@ -1,4 +1,4 @@ -#ifndef __STDIO_H__
-#define __STDIO_H__
-
-#endif
+#ifndef __STDIO_H__ +#define __STDIO_H__ + +#endif diff --git a/components/libc/minilibc/qsort.c b/components/libc/minilibc/qsort.c index 04ef8163eb..f412986e1d 100644 --- a/components/libc/minilibc/qsort.c +++ b/components/libc/minilibc/qsort.c @@ -1,44 +1,44 @@ -#include <sys/types.h>
-#include <stdlib.h>
-
-static void exch(char* base,size_t size,size_t a,size_t b) {
- char* x=base+a*size;
- char* y=base+b*size;
- while (size) {
- char z=*x;
- *x=*y;
- *y=z;
- --size; ++x; ++y;
- }
-}
-
-/* Quicksort with 3-way partitioning, ala Sedgewick */
-/* Blame him for the scary variable names */
-/* http://www.cs.princeton.edu/~rs/talks/QuicksortIsOptimal.pdf */
-static void quicksort(char* base,size_t size,ssize_t l,ssize_t r,
- int (*compar)(const void*,const void*)) {
- ssize_t i=l-1, j=r, p=l-1, q=r, k;
- char* v=base+r*size;
- if (r<=l) return;
- for (;;) {
- while (++i != r && compar(base+i*size,v)<0) ;
- while (compar(v,base+(--j)*size)<0) if (j == l) break;
- if (i >= j) break;
- exch(base,size,i,j);
- if (compar(base+i*size,v)==0) exch(base,size,++p,i);
- if (compar(v,base+j*size)==0) exch(base,size,j,--q);
- }
- exch(base,size,i,r); j = i-1; ++i;
- for (k=l; k<p; k++, j--) exch(base,size,k,j);
- for (k=r-1; k>q; k--, i++) exch(base,size,i,k);
- quicksort(base,size,l,j,compar);
- quicksort(base,size,i,r,compar);
-}
-
-void qsort(void* base,size_t nmemb,size_t size,int (*compar)(const void*,const void*)) {
- /* check for integer overflows */
- if (nmemb >= (((size_t)-1)>>1) ||
- size >= (((size_t)-1)>>1)) return;
- if (nmemb>1)
- quicksort(base,size,0,nmemb-1,compar);
-}
+#include <sys/types.h> +#include <stdlib.h> + +static void exch(char* base,size_t size,size_t a,size_t b) { + char* x=base+a*size; + char* y=base+b*size; + while (size) { + char z=*x; + *x=*y; + *y=z; + --size; ++x; ++y; + } +} + +/* Quicksort with 3-way partitioning, ala Sedgewick */ +/* Blame him for the scary variable names */ +/* http://www.cs.princeton.edu/~rs/talks/QuicksortIsOptimal.pdf */ +static void quicksort(char* base,size_t size,ssize_t l,ssize_t r, + int (*compar)(const void*,const void*)) { + ssize_t i=l-1, j=r, p=l-1, q=r, k; + char* v=base+r*size; + if (r<=l) return; + for (;;) { + while (++i != r && compar(base+i*size,v)<0) ; + while (compar(v,base+(--j)*size)<0) if (j == l) break; + if (i >= j) break; + exch(base,size,i,j); + if (compar(base+i*size,v)==0) exch(base,size,++p,i); + if (compar(v,base+j*size)==0) exch(base,size,j,--q); + } + exch(base,size,i,r); j = i-1; ++i; + for (k=l; k<p; k++, j--) exch(base,size,k,j); + for (k=r-1; k>q; k--, i++) exch(base,size,i,k); + quicksort(base,size,l,j,compar); + quicksort(base,size,i,r,compar); +} + +void qsort(void* base,size_t nmemb,size_t size,int (*compar)(const void*,const void*)) { + /* check for integer overflows */ + if (nmemb >= (((size_t)-1)>>1) || + size >= (((size_t)-1)>>1)) return; + if (nmemb>1) + quicksort(base,size,0,nmemb-1,compar); +} diff --git a/components/libc/minilibc/stddef.h b/components/libc/minilibc/stddef.h index 4991b0b19f..8068277117 100644 --- a/components/libc/minilibc/stddef.h +++ b/components/libc/minilibc/stddef.h @@ -1,7 +1,7 @@ -#ifndef __STDDEF_H__
-#define __STDDEF_H__
-
-#include <sys/types.h>
-typedef signed long ptrdiff_t;
-
-#endif
+#ifndef __STDDEF_H__ +#define __STDDEF_H__ + +#include <sys/types.h> +typedef signed long ptrdiff_t; + +#endif diff --git a/components/libc/minilibc/stdint.h b/components/libc/minilibc/stdint.h index 11c07179a6..2d9e292b7c 100644 --- a/components/libc/minilibc/stdint.h +++ b/components/libc/minilibc/stdint.h @@ -1,46 +1,46 @@ -#ifndef __STDINT_H__
-#define __STDINT_H__
-
-#include <rtthread.h>
-
-typedef rt_int8_t int8_t;
-typedef rt_uint8_t uint8_t;
-typedef rt_int16_t int16_t;
-typedef rt_uint16_t uint16_t;
-typedef rt_int32_t int32_t;
-typedef rt_uint32_t uint32_t;
-typedef long long int64_t;
-typedef unsigned long long uint64_t;
-
-/*
- * 7.18.2 Limits of specified-width integer types.
- *
- * The following object-like macros specify the minimum and maximum limits
- * of integer types corresponding to the typedef names defined above.
- */
-
-/* 7.18.2.1 Limits of exact-width integer types */
-#define INT8_MIN (-0x7f - 1)
-#define INT16_MIN (-0x7fff - 1)
-#define INT32_MIN (-0x7fffffff - 1)
-
-#define INT8_MAX 0x7f
-#define INT16_MAX 0x7fff
-#define INT32_MAX 0x7fffffff
-
-#define UINT8_MAX 0xff
-#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
+#ifndef __STDINT_H__ +#define __STDINT_H__ + +#include <rtthread.h> + +typedef rt_int8_t int8_t; +typedef rt_uint8_t uint8_t; +typedef rt_int16_t int16_t; +typedef rt_uint16_t uint16_t; +typedef rt_int32_t int32_t; +typedef rt_uint32_t uint32_t; +typedef long long int64_t; +typedef unsigned long long uint64_t; + +/* + * 7.18.2 Limits of specified-width integer types. + * + * The following object-like macros specify the minimum and maximum limits + * of integer types corresponding to the typedef names defined above. + */ + +/* 7.18.2.1 Limits of exact-width integer types */ +#define INT8_MIN (-0x7f - 1) +#define INT16_MIN (-0x7fff - 1) +#define INT32_MIN (-0x7fffffff - 1) + +#define INT8_MAX 0x7f +#define INT16_MAX 0x7fff +#define INT32_MAX 0x7fffffff + +#define UINT8_MAX 0xff +#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/stdio.h b/components/libc/minilibc/stdio.h index 45d98dbc9b..160b4d2c78 100644 --- a/components/libc/minilibc/stdio.h +++ b/components/libc/minilibc/stdio.h @@ -1,8 +1,8 @@ -#ifndef __STDIO_H__
-#define __STDIO_H__
-
-#define BUFSIZ 128
-#define EOF (-1)
-
-#endif
-
+#ifndef __STDIO_H__ +#define __STDIO_H__ + +#define BUFSIZ 128 +#define EOF (-1) + +#endif + diff --git a/components/libc/minilibc/stdlib.c b/components/libc/minilibc/stdlib.c index 7185f56bb7..51cb07fee0 100644 --- a/components/libc/minilibc/stdlib.c +++ b/components/libc/minilibc/stdlib.c @@ -1,77 +1,77 @@ -/*
- * File : stdlib.c
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) 2008, RT-Thread Development Team
- *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
- *
- * Change Logs:
- * Date Author Notes
- * 2008-08-14 Bernard the first version
- */
-
-#include <rtthread.h>
-
-#if !defined (RT_USING_NEWLIB) && defined (RT_USING_MINILIBC)
-#include "stdlib.h"
-
-int atoi(const char* s)
-{
- long int v=0;
- int sign=1;
- while ( *s == ' ' || (unsigned int)(*s - 9) < 5u) s++;
- switch (*s)
- {
- case '-':
- sign=-1;
- case '+':
- ++s;
- }
- while ((unsigned int) (*s - '0') < 10u)
- {
- v=v*10+*s-'0';
- ++s;
- }
- return sign==-1?-v:v;
-}
-
-long int atol(const char* s)
-{
- long int v=0;
- int sign=0;
- while ( *s == ' ' || (unsigned int)(*s - 9) < 5u) ++s;
- switch (*s)
- {
- case '-': sign=-1;
- case '+': ++s;
- }
- while ((unsigned int) (*s - '0') < 10u)
- {
- v=v*10+*s-'0'; ++s;
- }
- return sign?-v:v;
-}
-
-void *malloc(size_t size)
-{
- return rt_malloc(size);
-}
-
-void free(void *ptr)
-{
- rt_free(ptr);
-}
-
-void *realloc(void *ptr, size_t size)
-{
- return rt_realloc(ptr, size);
-}
-
-void *calloc(size_t nelem, size_t elsize)
-{
- return rt_calloc(nelem, elsize);
-}
-
-#endif
+/* + * File : stdlib.c + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2008, RT-Thread Development Team + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rt-thread.org/license/LICENSE + * + * Change Logs: + * Date Author Notes + * 2008-08-14 Bernard the first version + */ + +#include <rtthread.h> + +#if !defined (RT_USING_NEWLIB) && defined (RT_USING_MINILIBC) +#include "stdlib.h" + +int atoi(const char* s) +{ + long int v=0; + int sign=1; + while ( *s == ' ' || (unsigned int)(*s - 9) < 5u) s++; + switch (*s) + { + case '-': + sign=-1; + case '+': + ++s; + } + while ((unsigned int) (*s - '0') < 10u) + { + v=v*10+*s-'0'; + ++s; + } + return sign==-1?-v:v; +} + +long int atol(const char* s) +{ + long int v=0; + int sign=0; + while ( *s == ' ' || (unsigned int)(*s - 9) < 5u) ++s; + switch (*s) + { + case '-': sign=-1; + case '+': ++s; + } + while ((unsigned int) (*s - '0') < 10u) + { + v=v*10+*s-'0'; ++s; + } + return sign?-v:v; +} + +void *malloc(size_t size) +{ + return rt_malloc(size); +} + +void free(void *ptr) +{ + rt_free(ptr); +} + +void *realloc(void *ptr, size_t size) +{ + return rt_realloc(ptr, size); +} + +void *calloc(size_t nelem, size_t elsize) +{ + return rt_calloc(nelem, elsize); +} + +#endif diff --git a/components/libc/minilibc/stdlib.h b/components/libc/minilibc/stdlib.h index 08f7e0d07b..4e87537d3f 100644 --- a/components/libc/minilibc/stdlib.h +++ b/components/libc/minilibc/stdlib.h @@ -1,37 +1,37 @@ -/*
- * File : stdlib.h
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) 2008, RT-Thread Development Team
- *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
- *
- * Change Logs:
- * Date Author Notes
- * 2008-08-14 Bernard the first version
- */
-
-#ifndef __STDLIB_H__
-#define __STDLIB_H__
-
-#include <sys/types.h>
-
-#if !defined (RT_USING_NEWLIB) && defined (RT_USING_MINILIBC)
-int atoi(const char *nptr);
-long int atol(const char *nptr);
-
-int rand(void);
-int rand_r(unsigned int *seed);
-void srand(unsigned int seed);
-
-void qsort(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *));
-
-void *malloc(size_t size);
-void free(void *ptr);
-void *realloc(void *ptr, size_t size);
-void *calloc(size_t nelem, size_t elsize);
-void abort(void);
-#endif
-
-#endif
+/* + * File : stdlib.h + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2008, RT-Thread Development Team + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rt-thread.org/license/LICENSE + * + * Change Logs: + * Date Author Notes + * 2008-08-14 Bernard the first version + */ + +#ifndef __STDLIB_H__ +#define __STDLIB_H__ + +#include <sys/types.h> + +#if !defined (RT_USING_NEWLIB) && defined (RT_USING_MINILIBC) +int atoi(const char *nptr); +long int atol(const char *nptr); + +int rand(void); +int rand_r(unsigned int *seed); +void srand(unsigned int seed); + +void qsort(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *)); + +void *malloc(size_t size); +void free(void *ptr); +void *realloc(void *ptr, size_t size); +void *calloc(size_t nelem, size_t elsize); +void abort(void); +#endif + +#endif diff --git a/components/libc/minilibc/sys/time.h b/components/libc/minilibc/sys/time.h index 4cd5cb8ba8..3df6d8c570 100644 --- a/components/libc/minilibc/sys/time.h +++ b/components/libc/minilibc/sys/time.h @@ -1,43 +1,43 @@ -#ifndef _SYS_TIME_H_
-#define _SYS_TIME_H_
-
-#include <sys/types.h>
-
-/*
- * Structure returned by gettimeofday(2) system call,
- * and used in other calls.
- */
-struct timeval {
- long tv_sec; /* seconds */
- long tv_usec; /* and microseconds */
-};
-
-/*
- * Structure defined by POSIX.1b to be like a timeval.
- */
-struct timespec {
- time_t tv_sec; /* seconds */
- long tv_nsec; /* and nanoseconds */
-};
-
-struct timezone {
- int tz_minuteswest; /* minutes west of Greenwich */
- int tz_dsttime; /* type of dst correction */
-};
-
-struct tm {
- int tm_sec; /* Seconds. [0-60] (1 leap second) */
- int tm_min; /* Minutes. [0-59] */
- int tm_hour; /* Hours. [0-23] */
- int tm_mday; /* Day. [1-31] */
- int tm_mon; /* Month. [0-11] */
- int tm_year; /* Year - 1900. */
- int tm_wday; /* Day of week. [0-6] */
- int tm_yday; /* Days in year.[0-365] */
- int tm_isdst; /* DST. [-1/0/1]*/
-
- long int tm_gmtoff; /* Seconds east of UTC. */
- const char *tm_zone; /* Timezone abbreviation. */
-};
-
-#endif
+#ifndef _SYS_TIME_H_ +#define _SYS_TIME_H_ + +#include <sys/types.h> + +/* + * Structure returned by gettimeofday(2) system call, + * and used in other calls. + */ +struct timeval { + long tv_sec; /* seconds */ + long tv_usec; /* and microseconds */ +}; + +/* + * Structure defined by POSIX.1b to be like a timeval. + */ +struct timespec { + time_t tv_sec; /* seconds */ + long tv_nsec; /* and nanoseconds */ +}; + +struct timezone { + int tz_minuteswest; /* minutes west of Greenwich */ + int tz_dsttime; /* type of dst correction */ +}; + +struct tm { + int tm_sec; /* Seconds. [0-60] (1 leap second) */ + int tm_min; /* Minutes. [0-59] */ + int tm_hour; /* Hours. [0-23] */ + int tm_mday; /* Day. [1-31] */ + int tm_mon; /* Month. [0-11] */ + int tm_year; /* Year - 1900. */ + int tm_wday; /* Day of week. [0-6] */ + int tm_yday; /* Days in year.[0-365] */ + int tm_isdst; /* DST. [-1/0/1]*/ + + long int tm_gmtoff; /* Seconds east of UTC. */ + const char *tm_zone; /* Timezone abbreviation. */ +}; + +#endif diff --git a/components/libc/minilibc/time.c b/components/libc/minilibc/time.c index 84dbd3b84f..8faa3e0470 100644 --- a/components/libc/minilibc/time.c +++ b/components/libc/minilibc/time.c @@ -1,219 +1,219 @@ -#include <time.h>
-
-/* days per month -- nonleap! */
-const short __spm[13] =
- { 0,
- (31),
- (31+28),
- (31+28+31),
- (31+28+31+30),
- (31+28+31+30+31),
- (31+28+31+30+31+30),
- (31+28+31+30+31+30+31),
- (31+28+31+30+31+30+31+31),
- (31+28+31+30+31+30+31+31+30),
- (31+28+31+30+31+30+31+31+30+31),
- (31+28+31+30+31+30+31+31+30+31+30),
- (31+28+31+30+31+30+31+31+30+31+30+31),
- };
-static long int timezone;
-static const char days[] = "Sun Mon Tue Wed Thu Fri Sat ";
-static const char months[] = "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ";
-
-/* seconds per day */
-#define SPD 24*60*60
-
-int __isleap(int year)
-{
- /* every fourth year is a leap year except for century years that are
- * not divisible by 400. */
- /* return (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)); */
- return (!(year % 4) && ((year % 100) || !(year % 400)));
-}
-
-struct tm *gmtime_r(const time_t *timep, struct tm *r)
-{
- time_t i;
- register time_t work = *timep % (SPD);
- r->tm_sec = work % 60;
- work /= 60;
- r->tm_min = work % 60;
- r->tm_hour = work / 60;
- work = *timep / (SPD);
- r->tm_wday = (4 + work) % 7;
- for (i = 1970;; ++i)
- {
- register time_t k = __isleap(i) ? 366 : 365;
- if (work >= k)
- work -= k;
- else
- break;
- }
- r->tm_year = i - 1900;
- r->tm_yday = work;
-
- r->tm_mday = 1;
- if (__isleap(i) && (work > 58))
- {
- if (work == 59)
- r->tm_mday = 2; /* 29.2. */
- work -= 1;
- }
-
- for (i = 11; i && (__spm[i] > work); --i)
- ;
- r->tm_mon = i;
- r->tm_mday += work - __spm[i];
- return r;
-}
-
-struct tm* localtime_r(const time_t* t, struct tm* r)
-{
- time_t tmp;
- struct timezone tz = {0};
- gettimeofday(0, &tz);
- timezone = tz.tz_minuteswest * 60L;
- tmp = *t + timezone;
- return gmtime_r(&tmp, r);
-}
-
-struct tm* localtime(const time_t* t)
-{
- static struct tm tmp;
- return localtime_r(t, &tmp);
-}
-
-time_t mktime(struct tm * const t)
-{
- register time_t day;
- register time_t i;
- register time_t years = t->tm_year - 70;
-
- if (t->tm_sec > 60)
- {
- t->tm_min += t->tm_sec / 60;
- t->tm_sec %= 60;
- }
- if (t->tm_min > 60)
- {
- t->tm_hour += t->tm_min / 60;
- t->tm_min %= 60;
- }
- if (t->tm_hour > 24)
- {
- t->tm_mday += t->tm_hour / 24;
- t->tm_hour %= 24;
- }
- if (t->tm_mon > 12)
- {
- t->tm_year += t->tm_mon / 12;
- t->tm_mon %= 12;
- }
- while (t->tm_mday > __spm[1 + t->tm_mon])
- {
- if (t->tm_mon == 1 && __isleap(t->tm_year + 1900))
- {
- --t->tm_mday;
- }
- t->tm_mday -= __spm[t->tm_mon];
- ++t->tm_mon;
- if (t->tm_mon > 11)
- {
- t->tm_mon = 0;
- ++t->tm_year;
- }
- }
-
- if (t->tm_year < 70)
- return (time_t) -1;
-
- /* Days since 1970 is 365 * number of years + number of leap years since 1970 */
- day = years * 365 + (years + 1) / 4;
-
- /* After 2100 we have to substract 3 leap years for every 400 years
- This is not intuitive. Most mktime implementations do not support
- dates after 2059, anyway, so we might leave this out for it's
- bloat. */
- if (years >= 131)
- {
- years -= 131;
- years /= 100;
- day -= (years >> 2) * 3 + 1;
- if ((years &= 3) == 3)
- years--;
- day -= years;
- }
-
- day += t->tm_yday = __spm[t->tm_mon] + t->tm_mday - 1 +
- (__isleap(t->tm_year + 1900) & (t->tm_mon > 1));
-
- /* day is now the number of days since 'Jan 1 1970' */
- i = 7;
- t->tm_wday = (day + 4) % i; /* Sunday=0, Monday=1, ..., Saturday=6 */
-
- i = 24;
- day *= i;
- i = 60;
- return ((day + t->tm_hour) * i + t->tm_min) * i + t->tm_sec;
-}
-
-static void num2str(char *c, int i)
-{
- c[0] = i / 10 + '0';
- c[1] = i % 10 + '0';
-}
-
-char *asctime_r(const struct tm *t, char *buf)
-{
- /* "Wed Jun 30 21:49:08 1993\n" */
- *(int*) buf = *(int*) (days + (t->tm_wday << 2));
- *(int*) (buf + 4) = *(int*) (months + (t->tm_mon << 2));
- num2str(buf + 8, t->tm_mday);
- if (buf[8] == '0')
- buf[8] = ' ';
- buf[10] = ' ';
- num2str(buf + 11, t->tm_hour);
- buf[13] = ':';
- num2str(buf + 14, t->tm_min);
- buf[16] = ':';
- num2str(buf + 17, t->tm_sec);
- buf[19] = ' ';
- num2str(buf + 20, (t->tm_year + 1900) / 100);
- num2str(buf + 22, (t->tm_year + 1900) % 100);
- buf[24] = '\n';
- return buf;
-}
-
-char *asctime(const struct tm *timeptr)
-{
- static char buf[25];
- return asctime_r(timeptr, buf);
-}
-
-char *ctime(const time_t *timep)
-{
- return asctime(localtime(timep));
-}
-
-#ifdef RT_USING_DEVICE
-int gettimeofday(struct timeval *tp, void *ignore)
-{
- time_t time;
- rt_device_t device;
-
- device = rt_device_find("rtc");
- if (device != RT_NULL)
- {
- rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &time);
- if (tp != RT_NULL)
- {
- tp->tv_sec = time;
- tp->tv_usec = 0;
- }
-
- return time;
- }
-
- return 0;
-}
-#endif
+#include <time.h> + +/* days per month -- nonleap! */ +const short __spm[13] = + { 0, + (31), + (31+28), + (31+28+31), + (31+28+31+30), + (31+28+31+30+31), + (31+28+31+30+31+30), + (31+28+31+30+31+30+31), + (31+28+31+30+31+30+31+31), + (31+28+31+30+31+30+31+31+30), + (31+28+31+30+31+30+31+31+30+31), + (31+28+31+30+31+30+31+31+30+31+30), + (31+28+31+30+31+30+31+31+30+31+30+31), + }; +static long int timezone; +static const char days[] = "Sun Mon Tue Wed Thu Fri Sat "; +static const char months[] = "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec "; + +/* seconds per day */ +#define SPD 24*60*60 + +int __isleap(int year) +{ + /* every fourth year is a leap year except for century years that are + * not divisible by 400. */ + /* return (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)); */ + return (!(year % 4) && ((year % 100) || !(year % 400))); +} + +struct tm *gmtime_r(const time_t *timep, struct tm *r) +{ + time_t i; + register time_t work = *timep % (SPD); + r->tm_sec = work % 60; + work /= 60; + r->tm_min = work % 60; + r->tm_hour = work / 60; + work = *timep / (SPD); + r->tm_wday = (4 + work) % 7; + for (i = 1970;; ++i) + { + register time_t k = __isleap(i) ? 366 : 365; + if (work >= k) + work -= k; + else + break; + } + r->tm_year = i - 1900; + r->tm_yday = work; + + r->tm_mday = 1; + if (__isleap(i) && (work > 58)) + { + if (work == 59) + r->tm_mday = 2; /* 29.2. */ + work -= 1; + } + + for (i = 11; i && (__spm[i] > work); --i) + ; + r->tm_mon = i; + r->tm_mday += work - __spm[i]; + return r; +} + +struct tm* localtime_r(const time_t* t, struct tm* r) +{ + time_t tmp; + struct timezone tz = {0}; + gettimeofday(0, &tz); + timezone = tz.tz_minuteswest * 60L; + tmp = *t + timezone; + return gmtime_r(&tmp, r); +} + +struct tm* localtime(const time_t* t) +{ + static struct tm tmp; + return localtime_r(t, &tmp); +} + +time_t mktime(struct tm * const t) +{ + register time_t day; + register time_t i; + register time_t years = t->tm_year - 70; + + if (t->tm_sec > 60) + { + t->tm_min += t->tm_sec / 60; + t->tm_sec %= 60; + } + if (t->tm_min > 60) + { + t->tm_hour += t->tm_min / 60; + t->tm_min %= 60; + } + if (t->tm_hour > 24) + { + t->tm_mday += t->tm_hour / 24; + t->tm_hour %= 24; + } + if (t->tm_mon > 12) + { + t->tm_year += t->tm_mon / 12; + t->tm_mon %= 12; + } + while (t->tm_mday > __spm[1 + t->tm_mon]) + { + if (t->tm_mon == 1 && __isleap(t->tm_year + 1900)) + { + --t->tm_mday; + } + t->tm_mday -= __spm[t->tm_mon]; + ++t->tm_mon; + if (t->tm_mon > 11) + { + t->tm_mon = 0; + ++t->tm_year; + } + } + + if (t->tm_year < 70) + return (time_t) -1; + + /* Days since 1970 is 365 * number of years + number of leap years since 1970 */ + day = years * 365 + (years + 1) / 4; + + /* After 2100 we have to substract 3 leap years for every 400 years + This is not intuitive. Most mktime implementations do not support + dates after 2059, anyway, so we might leave this out for it's + bloat. */ + if (years >= 131) + { + years -= 131; + years /= 100; + day -= (years >> 2) * 3 + 1; + if ((years &= 3) == 3) + years--; + day -= years; + } + + day += t->tm_yday = __spm[t->tm_mon] + t->tm_mday - 1 + + (__isleap(t->tm_year + 1900) & (t->tm_mon > 1)); + + /* day is now the number of days since 'Jan 1 1970' */ + i = 7; + t->tm_wday = (day + 4) % i; /* Sunday=0, Monday=1, ..., Saturday=6 */ + + i = 24; + day *= i; + i = 60; + return ((day + t->tm_hour) * i + t->tm_min) * i + t->tm_sec; +} + +static void num2str(char *c, int i) +{ + c[0] = i / 10 + '0'; + c[1] = i % 10 + '0'; +} + +char *asctime_r(const struct tm *t, char *buf) +{ + /* "Wed Jun 30 21:49:08 1993\n" */ + *(int*) buf = *(int*) (days + (t->tm_wday << 2)); + *(int*) (buf + 4) = *(int*) (months + (t->tm_mon << 2)); + num2str(buf + 8, t->tm_mday); + if (buf[8] == '0') + buf[8] = ' '; + buf[10] = ' '; + num2str(buf + 11, t->tm_hour); + buf[13] = ':'; + num2str(buf + 14, t->tm_min); + buf[16] = ':'; + num2str(buf + 17, t->tm_sec); + buf[19] = ' '; + num2str(buf + 20, (t->tm_year + 1900) / 100); + num2str(buf + 22, (t->tm_year + 1900) % 100); + buf[24] = '\n'; + return buf; +} + +char *asctime(const struct tm *timeptr) +{ + static char buf[25]; + return asctime_r(timeptr, buf); +} + +char *ctime(const time_t *timep) +{ + return asctime(localtime(timep)); +} + +#ifdef RT_USING_DEVICE +int gettimeofday(struct timeval *tp, void *ignore) +{ + time_t time; + rt_device_t device; + + device = rt_device_find("rtc"); + if (device != RT_NULL) + { + rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &time); + if (tp != RT_NULL) + { + tp->tv_sec = time; + tp->tv_usec = 0; + } + + return time; + } + + return 0; +} +#endif diff --git a/components/libc/minilibc/time.h b/components/libc/minilibc/time.h index 0b2aabbed1..2f8ad23c71 100644 --- a/components/libc/minilibc/time.h +++ b/components/libc/minilibc/time.h @@ -1,6 +1,6 @@ -#ifndef __TIME_H__
-#define __TIME_H__
-
-#include <sys/time.h>
-
-#endif
+#ifndef __TIME_H__ +#define __TIME_H__ + +#include <sys/time.h> + +#endif diff --git a/components/libc/newlib/libc.h b/components/libc/newlib/libc.h index 35788d9f18..52fddd9492 100644 --- a/components/libc/newlib/libc.h +++ b/components/libc/newlib/libc.h @@ -1,21 +1,21 @@ -#ifndef __RTT_LIBC_H__
-#define __RTT_LIBC_H__
-
-#include <sys/time.h>
-
-#define MILLISECOND_PER_SECOND 1000UL
-#define MICROSECOND_PER_SECOND 1000000UL
-#define NANOSECOND_PER_SECOND 1000000000UL
-
-#define MILLISECOND_PER_TICK (MILLISECOND_PER_SECOND / RT_TICK_PER_SECOND)
-#define MICROSECOND_PER_TICK (MICROSECOND_PER_SECOND / RT_TICK_PER_SECOND)
-#define NANOSECOND_PER_TICK (NANOSECOND_PER_SECOND / RT_TICK_PER_SECOND)
-
-void libc_system_init(const char* tty_name);
-
-/* some time related function */
-int libc_set_time(const struct timespec *time);
-int libc_get_time(struct timespec *time);
-int libc_time_to_tick(const struct timespec *time);
-
-#endif
+#ifndef __RTT_LIBC_H__ +#define __RTT_LIBC_H__ + +#include <sys/time.h> + +#define MILLISECOND_PER_SECOND 1000UL +#define MICROSECOND_PER_SECOND 1000000UL +#define NANOSECOND_PER_SECOND 1000000000UL + +#define MILLISECOND_PER_TICK (MILLISECOND_PER_SECOND / RT_TICK_PER_SECOND) +#define MICROSECOND_PER_TICK (MICROSECOND_PER_SECOND / RT_TICK_PER_SECOND) +#define NANOSECOND_PER_TICK (NANOSECOND_PER_SECOND / RT_TICK_PER_SECOND) + +void libc_system_init(const char* tty_name); + +/* some time related function */ +int libc_set_time(const struct timespec *time); +int libc_get_time(struct timespec *time); +int libc_time_to_tick(const struct timespec *time); + +#endif diff --git a/components/libc/newlib/sys/dirent.h b/components/libc/newlib/sys/dirent.h index 18c5d02e11..2efc683579 100644 --- a/components/libc/newlib/sys/dirent.h +++ b/components/libc/newlib/sys/dirent.h @@ -1,57 +1,57 @@ -#ifndef __RTT_DIRENT_H__
-#define __RTT_DIRENT_H__
-
-#include <rtthread.h>
-
-/*
-* dirent.h - format of directory entries
- * Ref: http://www.opengroup.org/onlinepubs/009695399/basedefs/dirent.h.html
- */
-
-/* File types */
-#define FT_REGULAR 0 /* regular file */
-#define FT_SOCKET 1 /* socket file */
-#define FT_DIRECTORY 2 /* directory */
-#define FT_USER 3 /* user defined */
-
-#define DT_UNKNOWN 0x00
-#define DT_REG 0x01
-#define DT_DIR 0x02
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#ifndef HAVE_DIR_STRUCTURE
-typedef struct
-{
- int fd; /* directory file */
- char buf[512];
- int num;
- int cur;
-} DIR;
-#endif
-
-#ifndef HAVE_DIRENT_STRUCTURE
-struct dirent
-{
- rt_uint8_t d_type; /* The type of the file */
- rt_uint8_t d_namlen; /* The length of the not including the terminating null file name */
- rt_uint16_t d_reclen; /* length of this record */
- char d_name[256]; /* The null-terminated file name */
-};
-#endif
-
-int closedir(DIR *);
-DIR *opendir(const char *);
-struct dirent *readdir(DIR *);
-int readdir_r(DIR *, struct dirent *, struct dirent **);
-void rewinddir(DIR *);
-void seekdir(DIR *, long int);
-long telldir(DIR *);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
+#ifndef __RTT_DIRENT_H__ +#define __RTT_DIRENT_H__ + +#include <rtthread.h> + +/* +* dirent.h - format of directory entries + * Ref: http://www.opengroup.org/onlinepubs/009695399/basedefs/dirent.h.html + */ + +/* File types */ +#define FT_REGULAR 0 /* regular file */ +#define FT_SOCKET 1 /* socket file */ +#define FT_DIRECTORY 2 /* directory */ +#define FT_USER 3 /* user defined */ + +#define DT_UNKNOWN 0x00 +#define DT_REG 0x01 +#define DT_DIR 0x02 + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef HAVE_DIR_STRUCTURE +typedef struct +{ + int fd; /* directory file */ + char buf[512]; + int num; + int cur; +} DIR; +#endif + +#ifndef HAVE_DIRENT_STRUCTURE +struct dirent +{ + rt_uint8_t d_type; /* The type of the file */ + rt_uint8_t d_namlen; /* The length of the not including the terminating null file name */ + rt_uint16_t d_reclen; /* length of this record */ + char d_name[256]; /* The null-terminated file name */ +}; +#endif + +int closedir(DIR *); +DIR *opendir(const char *); +struct dirent *readdir(DIR *); +int readdir_r(DIR *, struct dirent *, struct dirent **); +void rewinddir(DIR *); +void seekdir(DIR *, long int); +long telldir(DIR *); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/components/libc/newlib/sys/statfs.h b/components/libc/newlib/sys/statfs.h index c3bc9be359..95772b5ead 100644 --- a/components/libc/newlib/sys/statfs.h +++ b/components/libc/newlib/sys/statfs.h @@ -1,13 +1,13 @@ -#ifndef __RTT_STATFS_H__
-#define __RTT_STATFS_H__
-
-#include <rtthread.h>
-
-struct statfs
-{
- rt_size_t f_bsize; /* block size */
- rt_size_t f_blocks; /* total data blocks in file system */
- rt_size_t f_bfree; /* free blocks in file system */
-};
-
-#endif
+#ifndef __RTT_STATFS_H__ +#define __RTT_STATFS_H__ + +#include <rtthread.h> + +struct statfs +{ + rt_size_t f_bsize; /* block size */ + rt_size_t f_blocks; /* total data blocks in file system */ + rt_size_t f_bfree; /* free blocks in file system */ +}; + +#endif |
