Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lfmiao0
rt-thread
提交
497e7b45
R
rt-thread
项目概览
lfmiao0
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rt-thread
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
497e7b45
编写于
2月 23, 2021
作者:
mysterywolf
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
remove minilibc
上级
b2d3317c
变更
23
隐藏空白更改
内联
并排
Showing
23 changed file
with
0 addition
and
2054 deletion
+0
-2054
components/libc/compilers/minilibc/SConscript
components/libc/compilers/minilibc/SConscript
+0
-15
components/libc/compilers/minilibc/ctype.c
components/libc/compilers/minilibc/ctype.c
+0
-49
components/libc/compilers/minilibc/ctype.h
components/libc/compilers/minilibc/ctype.h
+0
-18
components/libc/compilers/minilibc/errno.h
components/libc/compilers/minilibc/errno.h
+0
-16
components/libc/compilers/minilibc/inttypes.h
components/libc/compilers/minilibc/inttypes.h
+0
-14
components/libc/compilers/minilibc/math.c
components/libc/compilers/minilibc/math.c
+0
-176
components/libc/compilers/minilibc/math.h
components/libc/compilers/minilibc/math.h
+0
-20
components/libc/compilers/minilibc/qsort.c
components/libc/compilers/minilibc/qsort.c
+0
-52
components/libc/compilers/minilibc/rand.c
components/libc/compilers/minilibc/rand.c
+0
-43
components/libc/compilers/minilibc/signal.h
components/libc/compilers/minilibc/signal.h
+0
-20
components/libc/compilers/minilibc/stddef.h
components/libc/compilers/minilibc/stddef.h
+0
-15
components/libc/compilers/minilibc/stdint.h
components/libc/compilers/minilibc/stdint.h
+0
-266
components/libc/compilers/minilibc/stdio.h
components/libc/compilers/minilibc/stdio.h
+0
-26
components/libc/compilers/minilibc/stdlib.c
components/libc/compilers/minilibc/stdlib.c
+0
-75
components/libc/compilers/minilibc/stdlib.h
components/libc/compilers/minilibc/stdlib.h
+0
-33
components/libc/compilers/minilibc/string.c
components/libc/compilers/minilibc/string.c
+0
-630
components/libc/compilers/minilibc/string.h
components/libc/compilers/minilibc/string.h
+0
-69
components/libc/compilers/minilibc/sys/mman.h
components/libc/compilers/minilibc/sys/mman.h
+0
-58
components/libc/compilers/minilibc/sys/stat.h
components/libc/compilers/minilibc/sys/stat.h
+0
-44
components/libc/compilers/minilibc/sys/time.h
components/libc/compilers/minilibc/sys/time.h
+0
-54
components/libc/compilers/minilibc/sys/types.h
components/libc/compilers/minilibc/sys/types.h
+0
-50
components/libc/compilers/minilibc/time.c
components/libc/compilers/minilibc/time.c
+0
-287
components/libc/compilers/minilibc/time.h
components/libc/compilers/minilibc/time.h
+0
-24
未找到文件。
components/libc/compilers/minilibc/SConscript
已删除
100644 → 0
浏览文件 @
b2d3317c
from
building
import
*
Import
(
'rtconfig'
)
src
=
Glob
(
'*.c'
)
+
Glob
(
'*.cpp'
)
cwd
=
GetCurrentDir
()
group
=
[]
CPPPATH
=
[
cwd
]
CPPDEFINES
=
[
'RT_USING_MINILIBC'
]
if
rtconfig
.
PLATFORM
==
'gcc'
and
rtconfig
.
ARCH
!=
'sim'
and
not
GetDepend
(
'RT_USING_LIBC'
)
and
GetDepend
(
'RT_USING_MINILIBC'
):
group
=
DefineGroup
(
'libc'
,
src
,
depend
=
[
''
],
CPPPATH
=
CPPPATH
,
CPPDEFINES
=
CPPDEFINES
)
Return
(
'group'
)
components/libc/compilers/minilibc/ctype.c
已删除
100644 → 0
浏览文件 @
b2d3317c
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* 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
components/libc/compilers/minilibc/ctype.h
已删除
100644 → 0
浏览文件 @
b2d3317c
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* 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
components/libc/compilers/minilibc/errno.h
已删除
100644 → 0
浏览文件 @
b2d3317c
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
*/
#ifndef __ERRNO_H__
#define __ERRNO_H__
#include "libc/libc_errno.h"
/* Others defined in libc/libc_errno.h */
#define ENSRNOTFOUND 163
/* Domain name not found */
#endif
components/libc/compilers/minilibc/inttypes.h
已删除
100644 → 0
浏览文件 @
b2d3317c
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
*/
#ifndef __INTTYPES_H__
#define __INTTYPES_H__
#include "stdint.h"
#endif
components/libc/compilers/minilibc/math.c
已删除
100644 → 0
浏览文件 @
b2d3317c
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
*/
#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 (timo.kreuzer@reactos.org)
*/
#define PRECISION 9
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
;
}
components/libc/compilers/minilibc/math.h
已删除
100644 → 0
浏览文件 @
b2d3317c
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
*/
#ifndef __MATH_H__
#define __MATH_H__
#define M_PI 3.141592653589793238462643
double
sin
(
double
x
);
double
cos
(
double
x
);
typedef
float
float_t
;
typedef
double
double_t
;
#endif
components/libc/compilers/minilibc/qsort.c
已删除
100644 → 0
浏览文件 @
b2d3317c
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
*/
#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
);
}
components/libc/compilers/minilibc/rand.c
已删除
100644 → 0
浏览文件 @
b2d3317c
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
*/
#include <stdlib.h>
#include <stdint.h>
#include <sys/types.h>
static
unsigned
int
_seed
=
1
;
/* Knuth's TAOCP section 3.6 */
#define M ((1U<<31) -1)
#define A 48271
#define Q 44488 // M/A
#define R 3399 // M%A; R < Q !!!
int
rand_r
(
unsigned
int
*
seed
)
{
int32_t
X
;
X
=
*
seed
;
X
=
A
*
(
X
%
Q
)
-
R
*
(
int32_t
)
(
X
/
Q
);
if
(
X
<
0
)
X
+=
M
;
*
seed
=
X
;
return
X
;
}
int
rand
(
void
)
{
return
rand_r
(
&
_seed
);
}
void
srand
(
unsigned
int
i
)
{
_seed
=
i
;
}
int
random
(
void
)
__attribute__
((
alias
(
"rand"
)));
void
srandom
(
unsigned
int
i
)
__attribute__
((
alias
(
"srand"
)));
components/libc/compilers/minilibc/signal.h
已删除
100644 → 0
浏览文件 @
b2d3317c
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2017-09-12 Bernard The first version
*/
#ifndef SIGNAL_H__
#define SIGNAL_H__
#include <libc/libc_signal.h>
#define SIG_DFL ((_sig_func_ptr)0)
/* Default action */
#define SIG_IGN ((_sig_func_ptr)1)
/* Ignore action */
#define SIG_ERR ((_sig_func_ptr)-1)
/* Error return */
#endif
components/libc/compilers/minilibc/stddef.h
已删除
100644 → 0
浏览文件 @
b2d3317c
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
*/
#ifndef __STDDEF_H__
#define __STDDEF_H__
#include <sys/types.h>
typedef
signed
long
ptrdiff_t
;
#endif
components/libc/compilers/minilibc/stdint.h
已删除
100644 → 0
浏览文件 @
b2d3317c
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
*/
/*
* ISO C Standard: 7.18 Integer types <stdint.h>
*/
#ifndef __STDINT_H__
#define __STDINT_H__
/* 7.8.1.1 Exact-width integer types */
#ifdef __INT8_TYPE__
typedef
__INT8_TYPE__
int8_t
;
#endif
#ifdef __INT16_TYPE__
typedef
__INT16_TYPE__
int16_t
;
#endif
#ifdef __INT32_TYPE__
typedef
__INT32_TYPE__
int32_t
;
#endif
#ifdef __INT64_TYPE__
typedef
__INT64_TYPE__
int64_t
;
#endif
#ifdef __UINT8_TYPE__
typedef
__UINT8_TYPE__
uint8_t
;
#endif
#ifdef __UINT16_TYPE__
typedef
__UINT16_TYPE__
uint16_t
;
#endif
#ifdef __UINT32_TYPE__
typedef
__UINT32_TYPE__
uint32_t
;
#endif
#ifdef __UINT64_TYPE__
typedef
__UINT64_TYPE__
uint64_t
;
#endif
/* 7.8.1.2 Minimum-width integer types */
typedef
__INT_LEAST8_TYPE__
int_least8_t
;
typedef
__INT_LEAST16_TYPE__
int_least16_t
;
typedef
__INT_LEAST32_TYPE__
int_least32_t
;
typedef
__INT_LEAST64_TYPE__
int_least64_t
;
typedef
__UINT_LEAST8_TYPE__
uint_least8_t
;
typedef
__UINT_LEAST16_TYPE__
uint_least16_t
;
typedef
__UINT_LEAST32_TYPE__
uint_least32_t
;
typedef
__UINT_LEAST64_TYPE__
uint_least64_t
;
/* 7.8.1.3 Fastest minimum-width integer types */
typedef
__INT_FAST8_TYPE__
int_fast8_t
;
typedef
__INT_FAST16_TYPE__
int_fast16_t
;
typedef
__INT_FAST32_TYPE__
int_fast32_t
;
typedef
__INT_FAST64_TYPE__
int_fast64_t
;
typedef
__UINT_FAST8_TYPE__
uint_fast8_t
;
typedef
__UINT_FAST16_TYPE__
uint_fast16_t
;
typedef
__UINT_FAST32_TYPE__
uint_fast32_t
;
typedef
__UINT_FAST64_TYPE__
uint_fast64_t
;
/* 7.8.1.4 Integer types capable of holding object pointers */
#ifdef __INTPTR_TYPE__
typedef
__INTPTR_TYPE__
intptr_t
;
#endif
#ifdef __UINTPTR_TYPE__
typedef
__UINTPTR_TYPE__
uintptr_t
;
#endif
/* 7.8.1.5 Greatest-width integer types */
typedef
__INTMAX_TYPE__
intmax_t
;
typedef
__UINTMAX_TYPE__
uintmax_t
;
#if (!defined __cplusplus || __cplusplus >= 201103L \
|| defined __STDC_LIMIT_MACROS)
/*
* 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 */
#ifdef __INT8_MAX__
# undef INT8_MAX
# define INT8_MAX __INT8_MAX__
# undef INT8_MIN
# define INT8_MIN (-INT8_MAX - 1)
#endif
#ifdef __UINT8_MAX__
# undef UINT8_MAX
# define UINT8_MAX __UINT8_MAX__
#endif
#ifdef __INT16_MAX__
# undef INT16_MAX
# define INT16_MAX __INT16_MAX__
# undef INT16_MIN
# define INT16_MIN (-INT16_MAX - 1)
#endif
#ifdef __UINT16_MAX__
# undef UINT16_MAX
# define UINT16_MAX __UINT16_MAX__
#endif
#ifdef __INT32_MAX__
# undef INT32_MAX
# define INT32_MAX __INT32_MAX__
# undef INT32_MIN
# define INT32_MIN (-INT32_MAX - 1)
#endif
#ifdef __UINT32_MAX__
# undef UINT32_MAX
# define UINT32_MAX __UINT32_MAX__
#endif
#ifdef __INT64_MAX__
# undef INT64_MAX
# define INT64_MAX __INT64_MAX__
# undef INT64_MIN
# define INT64_MIN (-INT64_MAX - 1)
#endif
#ifdef __UINT64_MAX__
# undef UINT64_MAX
# define UINT64_MAX __UINT64_MAX__
#endif
#undef INT_LEAST8_MAX
#define INT_LEAST8_MAX __INT_LEAST8_MAX__
#undef INT_LEAST8_MIN
#define INT_LEAST8_MIN (-INT_LEAST8_MAX - 1)
#undef UINT_LEAST8_MAX
#define UINT_LEAST8_MAX __UINT_LEAST8_MAX__
#undef INT_LEAST16_MAX
#define INT_LEAST16_MAX __INT_LEAST16_MAX__
#undef INT_LEAST16_MIN
#define INT_LEAST16_MIN (-INT_LEAST16_MAX - 1)
#undef UINT_LEAST16_MAX
#define UINT_LEAST16_MAX __UINT_LEAST16_MAX__
#undef INT_LEAST32_MAX
#define INT_LEAST32_MAX __INT_LEAST32_MAX__
#undef INT_LEAST32_MIN
#define INT_LEAST32_MIN (-INT_LEAST32_MAX - 1)
#undef UINT_LEAST32_MAX
#define UINT_LEAST32_MAX __UINT_LEAST32_MAX__
#undef INT_LEAST64_MAX
#define INT_LEAST64_MAX __INT_LEAST64_MAX__
#undef INT_LEAST64_MIN
#define INT_LEAST64_MIN (-INT_LEAST64_MAX - 1)
#undef UINT_LEAST64_MAX
#define UINT_LEAST64_MAX __UINT_LEAST64_MAX__
#undef INT_FAST8_MAX
#define INT_FAST8_MAX __INT_FAST8_MAX__
#undef INT_FAST8_MIN
#define INT_FAST8_MIN (-INT_FAST8_MAX - 1)
#undef UINT_FAST8_MAX
#define UINT_FAST8_MAX __UINT_FAST8_MAX__
#undef INT_FAST16_MAX
#define INT_FAST16_MAX __INT_FAST16_MAX__
#undef INT_FAST16_MIN
#define INT_FAST16_MIN (-INT_FAST16_MAX - 1)
#undef UINT_FAST16_MAX
#define UINT_FAST16_MAX __UINT_FAST16_MAX__
#undef INT_FAST32_MAX
#define INT_FAST32_MAX __INT_FAST32_MAX__
#undef INT_FAST32_MIN
#define INT_FAST32_MIN (-INT_FAST32_MAX - 1)
#undef UINT_FAST32_MAX
#define UINT_FAST32_MAX __UINT_FAST32_MAX__
#undef INT_FAST64_MAX
#define INT_FAST64_MAX __INT_FAST64_MAX__
#undef INT_FAST64_MIN
#define INT_FAST64_MIN (-INT_FAST64_MAX - 1)
#undef UINT_FAST64_MAX
#define UINT_FAST64_MAX __UINT_FAST64_MAX__
#ifdef __INTPTR_MAX__
# undef INTPTR_MAX
# define INTPTR_MAX __INTPTR_MAX__
# undef INTPTR_MIN
# define INTPTR_MIN (-INTPTR_MAX - 1)
#endif
#ifdef __UINTPTR_MAX__
# undef UINTPTR_MAX
# define UINTPTR_MAX __UINTPTR_MAX__
#endif
#undef INTMAX_MAX
#define INTMAX_MAX __INTMAX_MAX__
#undef INTMAX_MIN
#define INTMAX_MIN (-INTMAX_MAX - 1)
#undef UINTMAX_MAX
#define UINTMAX_MAX __UINTMAX_MAX__
/* 7.18.3 Limits of other integer types */
#undef PTRDIFF_MAX
#define PTRDIFF_MAX __PTRDIFF_MAX__
#undef PTRDIFF_MIN
#define PTRDIFF_MIN (-PTRDIFF_MAX - 1)
#undef SIG_ATOMIC_MAX
#define SIG_ATOMIC_MAX __SIG_ATOMIC_MAX__
#undef SIG_ATOMIC_MIN
#define SIG_ATOMIC_MIN __SIG_ATOMIC_MIN__
#undef SIZE_MAX
#define SIZE_MAX __SIZE_MAX__
#undef WCHAR_MAX
#define WCHAR_MAX __WCHAR_MAX__
#undef WCHAR_MIN
#define WCHAR_MIN __WCHAR_MIN__
#undef WINT_MAX
#define WINT_MAX __WINT_MAX__
#undef WINT_MIN
#define WINT_MIN __WINT_MIN__
#endif
/* (!defined __cplusplus || __cplusplus >= 201103L
|| defined __STDC_LIMIT_MACROS) */
#if (!defined __cplusplus || __cplusplus >= 201103L \
|| defined __STDC_CONSTANT_MACROS)
#undef INT8_C
#define INT8_C(c) __INT8_C(c)
#undef INT16_C
#define INT16_C(c) __INT16_C(c)
#undef INT32_C
#define INT32_C(c) __INT32_C(c)
#undef INT64_C
#define INT64_C(c) __INT64_C(c)
#undef UINT8_C
#define UINT8_C(c) __UINT8_C(c)
#undef UINT16_C
#define UINT16_C(c) __UINT16_C(c)
#undef UINT32_C
#define UINT32_C(c) __UINT32_C(c)
#undef UINT64_C
#define UINT64_C(c) __UINT64_C(c)
#undef INTMAX_C
#define INTMAX_C(c) __INTMAX_C(c)
#undef UINTMAX_C
#define UINTMAX_C(c) __UINTMAX_C(c)
#endif
/* (!defined __cplusplus || __cplusplus >= 201103L
|| defined __STDC_CONSTANT_MACROS) */
#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
components/libc/compilers/minilibc/stdio.h
已删除
100644 → 0
浏览文件 @
b2d3317c
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
*/
#ifndef __STDIO_H__
#define __STDIO_H__
#define BUFSIZ 128
#define EOF (-1)
#ifndef SEEK_SET
#define SEEK_SET 0
/* set file offset to offset */
#endif
#ifndef SEEK_CUR
#define SEEK_CUR 1
/* set file offset to current plus offset */
#endif
#ifndef SEEK_END
#define SEEK_END 2
/* set file offset to EOF plus offset */
#endif
#endif
components/libc/compilers/minilibc/stdlib.c
已删除
100644 → 0
浏览文件 @
b2d3317c
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* 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
;
}
#ifdef RT_USING_HEAP
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
#endif
components/libc/compilers/minilibc/stdlib.h
已删除
100644 → 0
浏览文件 @
b2d3317c
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* 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
components/libc/compilers/minilibc/string.c
已删除
100644 → 0
浏览文件 @
b2d3317c
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2008-08-14 Bernard the first version
* 2010-02-15 Gary Lee add strlcpy
* 2010-03-17 Bernard add strlcpy implementation to this file.
* fix strlcpy declaration
* 2010-03-24 Bernard add strchr and strtok implementation.
*/
#include <rtthread.h>
#include <stdint.h>
#if !defined (RT_USING_NEWLIB) && defined (RT_USING_MINILIBC)
#include "string.h"
/* there is no strcpy and strcmp implementation in RT-Thread */
char
*
strcpy
(
char
*
dest
,
const
char
*
src
)
{
return
(
char
*
)
rt_strncpy
(
dest
,
src
,
rt_strlen
(
src
)
+
1
);
}
char
*
strncpy
(
char
*
dest
,
const
char
*
src
,
size_t
siz
)
{
return
(
char
*
)
rt_strncpy
(
dest
,
src
,
siz
);
}
size_t
strlcpy
(
char
*
dst
,
const
char
*
src
,
size_t
siz
)
{
register
char
*
d
=
dst
;
register
const
char
*
s
=
src
;
register
size_t
n
=
siz
;
/* Copy as many bytes as will fit */
if
(
n
!=
0
&&
--
n
!=
0
)
{
do
{
if
((
*
d
++
=
*
s
++
)
==
0
)
break
;
}
while
(
--
n
!=
0
);
}
/* Not enough room in dst, add NUL and traverse rest of src */
if
(
n
==
0
)
{
if
(
siz
!=
0
)
*
d
=
'\0'
;
/* NUL-terminate dst */
while
(
*
s
++
)
;
}
return
(
s
-
src
-
1
);
/* count does not include NUL */
}
int
strcmp
(
const
char
*
s1
,
const
char
*
s2
)
{
while
(
*
s1
&&
*
s1
==
*
s2
)
s1
++
,
s2
++
;
return
(
*
s1
-
*
s2
);
}
/**
* strncmp - Compare two length-limited strings
* @cs: One string
* @ct: Another string
* @count: The maximum number of bytes to compare
*/
int
strncmp
(
const
char
*
cs
,
const
char
*
ct
,
size_t
count
)
{
register
signed
char
__res
=
0
;
while
(
count
)
{
if
((
__res
=
*
cs
-
*
ct
++
)
!=
0
||
!*
cs
++
)
break
;
count
--
;
}
return
__res
;
}
char
*
strcat
(
char
*
dest
,
const
char
*
src
)
{
char
*
tmp
=
dest
;
while
(
*
dest
)
dest
++
;
while
((
*
dest
++
=
*
src
++
)
!=
'\0'
)
;
return
tmp
;
}
char
*
strncat
(
char
*
dest
,
const
char
*
src
,
size_t
count
)
{
char
*
tmp
=
dest
;
if
(
count
)
{
while
(
*
dest
)
dest
++
;
while
((
*
dest
++
=
*
src
++
))
{
if
(
--
count
==
0
)
{
*
dest
=
'\0'
;
break
;
}
}
}
return
tmp
;
}
char
*
strrchr
(
const
char
*
t
,
int
c
)
{
register
char
ch
;
register
const
char
*
l
=
0
;
ch
=
c
;
for
(;;)
{
if
(
*
t
==
ch
)
l
=
t
;
if
(
!*
t
)
return
(
char
*
)
l
;
++
t
;
}
return
(
char
*
)
l
;
}
int
strncasecmp
(
const
char
*
s1
,
const
char
*
s2
,
size_t
len
)
{
register
unsigned
int
x2
;
register
unsigned
int
x1
;
register
const
char
*
end
=
s1
+
len
;
while
(
1
)
{
if
((
s1
>=
end
)
)
return
0
;
x2
=
*
s2
-
'A'
;
if
((
x2
<
26u
))
x2
+=
32
;
x1
=
*
s1
-
'A'
;
if
((
x1
<
26u
))
x1
+=
32
;
s1
++
;
s2
++
;
if
(
x2
!=
x1
)
break
;
if
(
x1
==
(
unsigned
int
)
-
'A'
)
break
;
}
return
x1
-
x2
;
}
/* private function */
#define isdigit(c) ((unsigned)((c) - '0') < 10)
rt_inline
int
divide
(
int
*
n
,
int
base
)
{
rt_int32_t
res
;
/* optimized for processor which does not support divide instructions. */
if
(
base
==
10
)
{
res
=
((
int
)
*
n
)
%
10U
;
*
n
=
((
int
)
*
n
)
/
10U
;
}
else
{
res
=
((
int
)
*
n
)
%
16U
;
*
n
=
((
int
)
*
n
)
/
16U
;
}
return
res
;
}
rt_inline
int
skip_atoi
(
const
char
**
s
)
{
register
int
i
=
0
;
while
(
isdigit
(
**
s
))
i
=
i
*
10
+
*
((
*
s
)
++
)
-
'0'
;
return
i
;
}
unsigned
char
_ctype
[]
=
{
_C
,
_C
,
_C
,
_C
,
_C
,
_C
,
_C
,
_C
,
/* 0-7 */
_C
,
_C
|
_S
,
_C
|
_S
,
_C
|
_S
,
_C
|
_S
,
_C
|
_S
,
_C
,
_C
,
/* 8-15 */
_C
,
_C
,
_C
,
_C
,
_C
,
_C
,
_C
,
_C
,
/* 16-23 */
_C
,
_C
,
_C
,
_C
,
_C
,
_C
,
_C
,
_C
,
/* 24-31 */
_S
|
_SP
,
_P
,
_P
,
_P
,
_P
,
_P
,
_P
,
_P
,
/* 32-39 */
_P
,
_P
,
_P
,
_P
,
_P
,
_P
,
_P
,
_P
,
/* 40-47 */
_D
,
_D
,
_D
,
_D
,
_D
,
_D
,
_D
,
_D
,
/* 48-55 */
_D
,
_D
,
_P
,
_P
,
_P
,
_P
,
_P
,
_P
,
/* 56-63 */
_P
,
_U
|
_X
,
_U
|
_X
,
_U
|
_X
,
_U
|
_X
,
_U
|
_X
,
_U
|
_X
,
_U
,
/* 64-71 */
_U
,
_U
,
_U
,
_U
,
_U
,
_U
,
_U
,
_U
,
/* 72-79 */
_U
,
_U
,
_U
,
_U
,
_U
,
_U
,
_U
,
_U
,
/* 80-87 */
_U
,
_U
,
_U
,
_P
,
_P
,
_P
,
_P
,
_P
,
/* 88-95 */
_P
,
_L
|
_X
,
_L
|
_X
,
_L
|
_X
,
_L
|
_X
,
_L
|
_X
,
_L
|
_X
,
_L
,
/* 96-103 */
_L
,
_L
,
_L
,
_L
,
_L
,
_L
,
_L
,
_L
,
/* 104-111 */
_L
,
_L
,
_L
,
_L
,
_L
,
_L
,
_L
,
_L
,
/* 112-119 */
_L
,
_L
,
_L
,
_P
,
_P
,
_P
,
_P
,
_C
,
/* 120-127 */
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
/* 128-143 */
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
/* 144-159 */
_S
|
_SP
,
_P
,
_P
,
_P
,
_P
,
_P
,
_P
,
_P
,
_P
,
_P
,
_P
,
_P
,
_P
,
_P
,
_P
,
_P
,
/* 160-175 */
_P
,
_P
,
_P
,
_P
,
_P
,
_P
,
_P
,
_P
,
_P
,
_P
,
_P
,
_P
,
_P
,
_P
,
_P
,
_P
,
/* 176-191 */
_U
,
_U
,
_U
,
_U
,
_U
,
_U
,
_U
,
_U
,
_U
,
_U
,
_U
,
_U
,
_U
,
_U
,
_U
,
_U
,
/* 192-207 */
_U
,
_U
,
_U
,
_U
,
_U
,
_U
,
_U
,
_P
,
_U
,
_U
,
_U
,
_U
,
_U
,
_U
,
_U
,
_L
,
/* 208-223 */
_L
,
_L
,
_L
,
_L
,
_L
,
_L
,
_L
,
_L
,
_L
,
_L
,
_L
,
_L
,
_L
,
_L
,
_L
,
_L
,
/* 224-239 */
_L
,
_L
,
_L
,
_L
,
_L
,
_L
,
_L
,
_P
,
_L
,
_L
,
_L
,
_L
,
_L
,
_L
,
_L
,
_L
};
/* 240-255 */
#define __ismask(x) (_ctype[(int)(unsigned char)(x)])
#define isalnum(c) ((__ismask(c)&(_U|_L|_D)) != 0)
#define isalpha(c) ((__ismask(c)&(_U|_L)) != 0)
#define iscntrl(c) ((__ismask(c)&(_C)) != 0)
#define isgraph(c) ((__ismask(c)&(_P|_U|_L|_D)) != 0)
#define islower(c) ((__ismask(c)&(_L)) != 0)
#define isprint(c) ((__ismask(c)&(_P|_U|_L|_D|_SP)) != 0)
#define ispunct(c) ((__ismask(c)&(_P)) != 0)
#define isspace(c) ((__ismask(c)&(_S)) != 0)
#define isupper(c) ((__ismask(c)&(_U)) != 0)
#define isxdigit(c) ((__ismask(c)&(_D|_X)) != 0)
#define isascii(c) (((unsigned char)(c))<=0x7f)
#define toascii(c) (((unsigned char)(c))&0x7f)
static
inline
unsigned
char
__tolower
(
unsigned
char
c
)
{
if
(
isupper
(
c
))
c
-=
'A'
-
'a'
;
return
c
;
}
static
inline
unsigned
char
__toupper
(
unsigned
char
c
)
{
if
(
islower
(
c
))
c
-=
'a'
-
'A'
;
return
c
;
}
int
tolower
(
int
c
)
{
return
__tolower
(
c
);
}
int
toupper
(
int
c
)
{
return
__toupper
(
c
);
}
/**
* simple_strtoul - convert a string to an unsigned long
* @cp: The start of the string
* @endp: A pointer to the end of the parsed string will be placed here
* @base: The number base to use
*/
unsigned
long
simple_strtoul
(
const
char
*
cp
,
char
**
endp
,
unsigned
int
base
)
{
unsigned
long
result
=
0
,
value
;
if
(
!
base
)
{
base
=
10
;
if
(
*
cp
==
'0'
)
{
base
=
8
;
cp
++
;
if
((
toupper
(
*
cp
)
==
'X'
)
&&
isxdigit
(
cp
[
1
]))
{
cp
++
;
base
=
16
;
}
}
}
else
if
(
base
==
16
)
{
if
(
cp
[
0
]
==
'0'
&&
toupper
(
cp
[
1
])
==
'X'
)
cp
+=
2
;
}
while
(
isxdigit
(
*
cp
)
&&
(
value
=
isdigit
(
*
cp
)
?
*
cp
-
'0'
:
toupper
(
*
cp
)
-
'A'
+
10
)
<
base
)
{
result
=
result
*
base
+
value
;
cp
++
;
}
if
(
endp
)
*
endp
=
(
char
*
)
cp
;
return
result
;
}
/**
* simple_strtol - convert a string to a signed long
* @cp: The start of the string
* @endp: A pointer to the end of the parsed string will be placed here
* @base: The number base to use
*/
long
simple_strtol
(
const
char
*
cp
,
char
**
endp
,
unsigned
int
base
)
{
if
(
*
cp
==
'-'
)
return
-
simple_strtoul
(
cp
+
1
,
endp
,
base
);
return
simple_strtoul
(
cp
,
endp
,
base
);
}
/**
* simple_strtoull - convert a string to an unsigned long long
* @cp: The start of the string
* @endp: A pointer to the end of the parsed string will be placed here
* @base: The number base to use
*/
unsigned
long
long
simple_strtoull
(
const
char
*
cp
,
char
**
endp
,
unsigned
int
base
)
{
unsigned
long
long
result
=
0
,
value
;
if
(
*
cp
==
'0'
)
{
cp
++
;
if
((
toupper
(
*
cp
)
==
'X'
)
&&
isxdigit
(
cp
[
1
]))
{
base
=
16
;
cp
++
;
}
if
(
!
base
)
{
base
=
8
;
}
}
if
(
!
base
)
{
base
=
10
;
}
while
(
isxdigit
(
*
cp
)
&&
(
value
=
isdigit
(
*
cp
)
?
*
cp
-
'0'
:
(
islower
(
*
cp
)
?
toupper
(
*
cp
)
:
*
cp
)
-
'A'
+
10
)
<
base
)
{
result
=
result
*
base
+
value
;
cp
++
;
}
if
(
endp
)
*
endp
=
(
char
*
)
cp
;
return
result
;
}
/**
* simple_strtoll - convert a string to a signed long long
* @cp: The start of the string
* @endp: A pointer to the end of the parsed string will be placed here
* @base: The number base to use
*/
long
long
simple_strtoll
(
const
char
*
cp
,
char
**
endp
,
unsigned
int
base
)
{
if
(
*
cp
==
'-'
)
return
-
simple_strtoull
(
cp
+
1
,
endp
,
base
);
return
simple_strtoull
(
cp
,
endp
,
base
);
}
/**
* vsscanf - Unformat a buffer into a list of arguments
* @buf: input buffer
* @fmt: format of buffer
* @args: arguments
*/
int
vsscanf
(
const
char
*
buf
,
const
char
*
fmt
,
va_list
args
)
{
const
char
*
str
=
buf
;
char
*
next
;
int
num
=
0
;
int
qualifier
;
int
base
;
int
field_width
=
-
1
;
int
is_sign
=
0
;
while
(
*
fmt
&&
*
str
)
{
/* skip any white space in format */
/* white space in format matchs any amount of
* white space, including none, in the input.
*/
if
(
isspace
(
*
fmt
))
{
while
(
isspace
(
*
fmt
))
++
fmt
;
while
(
isspace
(
*
str
))
++
str
;
}
/* anything that is not a conversion must match exactly */
if
(
*
fmt
!=
'%'
&&
*
fmt
)
{
if
(
*
fmt
++
!=
*
str
++
)
break
;
continue
;
}
if
(
!*
fmt
)
break
;
++
fmt
;
/* skip this conversion.
* advance both strings to next white space
*/
if
(
*
fmt
==
'*'
)
{
while
(
!
isspace
(
*
fmt
)
&&
*
fmt
)
fmt
++
;
while
(
!
isspace
(
*
str
)
&&
*
str
)
str
++
;
continue
;
}
/* get field width */
if
(
isdigit
(
*
fmt
))
field_width
=
skip_atoi
(
&
fmt
);
/* get conversion qualifier */
qualifier
=
-
1
;
if
(
*
fmt
==
'h'
||
*
fmt
==
'l'
||
*
fmt
==
'L'
||
*
fmt
==
'Z'
)
{
qualifier
=
*
fmt
;
fmt
++
;
}
base
=
10
;
is_sign
=
0
;
if
(
!*
fmt
||
!*
str
)
break
;
switch
(
*
fmt
++
)
{
case
'c'
:
{
char
*
s
=
(
char
*
)
va_arg
(
args
,
char
*
);
if
(
field_width
==
-
1
)
field_width
=
1
;
do
{
*
s
++
=
*
str
++
;
}
while
(
field_width
--
>
0
&&
*
str
);
num
++
;
}
continue
;
case
's'
:
{
char
*
s
=
(
char
*
)
va_arg
(
args
,
char
*
);
if
(
field_width
==
-
1
)
field_width
=
INT_MAX
;
/* first, skip leading white space in buffer */
while
(
isspace
(
*
str
))
str
++
;
/* now copy until next white space */
while
(
*
str
&&
!
isspace
(
*
str
)
&&
field_width
--
)
{
*
s
++
=
*
str
++
;
}
*
s
=
'\0'
;
num
++
;
}
continue
;
case
'n'
:
/* return number of characters read so far */
{
int
*
i
=
(
int
*
)
va_arg
(
args
,
int
*
);
*
i
=
str
-
buf
;
}
continue
;
case
'o'
:
base
=
8
;
break
;
case
'x'
:
case
'X'
:
base
=
16
;
break
;
case
'd'
:
case
'i'
:
is_sign
=
1
;
case
'u'
:
break
;
case
'%'
:
/* looking for '%' in str */
if
(
*
str
++
!=
'%'
)
return
num
;
continue
;
default:
/* invalid format; stop here */
return
num
;
}
/* have some sort of integer conversion.
* first, skip white space in buffer.
*/
while
(
isspace
(
*
str
))
str
++
;
if
(
!*
str
||
!
isdigit
(
*
str
))
break
;
switch
(
qualifier
)
{
case
'h'
:
if
(
is_sign
)
{
short
*
s
=
(
short
*
)
va_arg
(
args
,
short
*
);
*
s
=
(
short
)
simple_strtol
(
str
,
&
next
,
base
);
}
else
{
unsigned
short
*
s
=
(
unsigned
short
*
)
va_arg
(
args
,
unsigned
short
*
);
*
s
=
(
unsigned
short
)
simple_strtoul
(
str
,
&
next
,
base
);
}
break
;
case
'l'
:
if
(
is_sign
)
{
long
*
l
=
(
long
*
)
va_arg
(
args
,
long
*
);
*
l
=
simple_strtol
(
str
,
&
next
,
base
);
}
else
{
unsigned
long
*
l
=
(
unsigned
long
*
)
va_arg
(
args
,
unsigned
long
*
);
*
l
=
simple_strtoul
(
str
,
&
next
,
base
);
}
break
;
case
'L'
:
if
(
is_sign
)
{
long
long
*
l
=
(
long
long
*
)
va_arg
(
args
,
long
long
*
);
*
l
=
simple_strtoll
(
str
,
&
next
,
base
);
}
else
{
unsigned
long
long
*
l
=
(
unsigned
long
long
*
)
va_arg
(
args
,
unsigned
long
long
*
);
*
l
=
simple_strtoull
(
str
,
&
next
,
base
);
}
break
;
case
'Z'
:
{
unsigned
long
*
s
=
(
unsigned
long
*
)
va_arg
(
args
,
unsigned
long
*
);
*
s
=
(
unsigned
long
)
simple_strtoul
(
str
,
&
next
,
base
);
}
break
;
default:
if
(
is_sign
)
{
int
*
i
=
(
int
*
)
va_arg
(
args
,
int
*
);
*
i
=
(
int
)
simple_strtol
(
str
,
&
next
,
base
);
}
else
{
unsigned
int
*
i
=
(
unsigned
int
*
)
va_arg
(
args
,
unsigned
int
*
);
*
i
=
(
unsigned
int
)
simple_strtoul
(
str
,
&
next
,
base
);
}
break
;
}
num
++
;
if
(
!
next
)
break
;
str
=
next
;
}
return
num
;
}
/**
* sscanf - Unformat a buffer into a list of arguments
* @buf: input buffer
* @fmt: formatting of buffer
* @...: resulting arguments
*/
int
sscanf
(
const
char
*
buf
,
const
char
*
fmt
,
...)
{
va_list
args
;
int
i
;
va_start
(
args
,
fmt
);
i
=
vsscanf
(
buf
,
fmt
,
args
);
va_end
(
args
);
return
i
;
}
size_t
strspn
(
const
char
*
s
,
const
char
*
accept
)
{
size_t
l
=
0
;
int
a
=
1
,
i
,
al
=
strlen
(
accept
);
while
((
a
)
&&
(
*
s
))
{
for
(
a
=
i
=
0
;(
!
a
)
&&
(
i
<
al
);
i
++
)
if
(
*
s
==
accept
[
i
])
a
=
1
;
if
(
a
)
l
++
;
s
++
;
}
return
l
;
}
size_t
strcspn
(
const
char
*
s
,
const
char
*
reject
)
{
size_t
l
=
0
;
int
a
=
1
,
i
,
al
=
strlen
(
reject
);
while
((
a
)
&&
(
*
s
))
{
for
(
i
=
0
;(
a
)
&&
(
i
<
al
);
i
++
)
if
(
*
s
==
reject
[
i
])
a
=
0
;
if
(
a
)
l
++
;
s
++
;
}
return
l
;
}
char
*
strtok_r
(
char
*
s
,
const
char
*
delim
,
char
**
ptrptr
)
{
char
*
tmp
=
0
;
if
(
s
==
0
)
s
=*
ptrptr
;
s
+=
strspn
(
s
,
delim
);
/* overread leading delimiter */
if
(
*
s
)
{
tmp
=
s
;
s
+=
strcspn
(
s
,
delim
);
if
(
*
s
)
*
s
++=
0
;
/* not the end ? => terminate it */
}
*
ptrptr
=
s
;
return
tmp
;
}
char
*
strtok
(
char
*
s
,
const
char
*
delim
)
{
static
char
*
strtok_pos
;
return
strtok_r
(
s
,
delim
,
&
strtok_pos
);
}
char
*
strchr
(
const
char
*
s1
,
int
i
)
{
const
unsigned
char
*
s
=
(
const
unsigned
char
*
)
s1
;
unsigned
char
c
=
(
unsigned
int
)
i
;
while
(
*
s
&&
*
s
!=
c
)
{
s
++
;
}
if
(
*
s
!=
c
)
{
s
=
NULL
;
}
return
(
char
*
)
s
;
}
long
strtol
(
const
char
*
str
,
char
**
endptr
,
int
base
)
{
return
simple_strtol
(
str
,
endptr
,
base
);
}
long
long
strtoll
(
const
char
*
str
,
char
**
endptr
,
int
base
)
{
return
simple_strtoll
(
str
,
endptr
,
base
);
}
#endif
components/libc/compilers/minilibc/string.h
已删除
100644 → 0
浏览文件 @
b2d3317c
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2008-08-14 Bernard the first version
*/
#ifndef __STRING_H__
#define __STRING_H__
#include <rtthread.h>
#include <sys/types.h>
/* replace for standard string library */
#if !defined (RT_USING_NEWLIB) && defined (RT_USING_MINILIBC)
#define ZEROPAD (1 << 0)
/* pad with zero */
#define SIGN (1 << 1)
/* unsigned/signed long */
#define PLUS (1 << 2)
/* show plus */
#define SPACE (1 << 3)
/* space if plus */
#define LEFT (1 << 4)
/* left justified */
#define SPECIAL (1 << 5)
/* 0x */
#define LARGE (1 << 6)
/* use 'ABCDEF' instead of 'abcdef' */
#define _U 0x01
/* upper */
#define _L 0x02
/* lower */
#define _D 0x04
/* digit */
#define _C 0x08
/* cntrl */
#define _P 0x10
/* punct */
#define _S 0x20
/* white space (space/lf/tab) */
#define _X 0x40
/* hex digit */
#define _SP 0x80
/* hard space (0x20) */
void
*
memset
(
void
*
s
,
int
c
,
size_t
n
);
void
*
memcpy
(
void
*
dest
,
const
void
*
src
,
size_t
n
);
void
*
memmove
(
void
*
dest
,
const
void
*
src
,
size_t
n
);
int
memcmp
(
const
void
*
s1
,
const
void
*
s2
,
size_t
n
);
int
tolower
(
int
c
);
int
toupper
(
int
c
);
int
strcmp
(
const
char
*
s1
,
const
char
*
s2
);
int
strncmp
(
const
char
*
cs
,
const
char
*
ct
,
size_t
count
);
int
strcasecmp
(
const
char
*
a
,
const
char
*
b
);
int
strncasecmp
(
const
char
*
cs
,
const
char
*
ct
,
size_t
count
);
int
sscanf
(
const
char
*
buf
,
const
char
*
fmt
,
...);
size_t
strlen
(
const
char
*
s
);
char
*
strstr
(
const
char
*
s1
,
const
char
*
s2
);
char
*
strcpy
(
char
*
dest
,
const
char
*
src
);
char
*
strncpy
(
char
*
dest
,
const
char
*
src
,
size_t
n
);
size_t
strlcpy
(
char
*
dst
,
const
char
*
src
,
size_t
siz
);
char
*
strncat
(
char
*
dest
,
const
char
*
src
,
size_t
count
);
char
*
strcat
(
char
*
dest
,
const
char
*
src
);
char
*
strchr
(
const
char
*
s1
,
int
i
);
char
*
strrchr
(
const
char
*
t
,
int
c
);
char
*
strdup
(
const
char
*
s
);
char
*
strtok
(
char
*
s
,
const
char
*
delim
);
char
*
strtok_r
(
char
*
s
,
const
char
*
delim
,
char
**
ptrptr
);
size_t
strcspn
(
const
char
*
s
,
const
char
*
reject
);
size_t
strspn
(
const
char
*
s
,
const
char
*
accept
);
long
strtol
(
const
char
*
str
,
char
**
endptr
,
int
base
);
long
long
strtoll
(
const
char
*
str
,
char
**
endptr
,
int
base
);
#endif
#endif
components/libc/compilers/minilibc/sys/mman.h
已删除
100644 → 0
浏览文件 @
b2d3317c
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2017/11/30 Bernard The first version.
*/
#ifndef _SYS_MMAN_H
#define _SYS_MMAN_H
#ifdef __cplusplus
extern
"C"
{
#endif
#define MAP_FAILED ((void *) -1)
#define MAP_SHARED 0x01
#define MAP_PRIVATE 0x02
#define MAP_TYPE 0x0f
#define MAP_FIXED 0x10
#define MAP_ANON 0x20
#define MAP_ANONYMOUS MAP_ANON
#define MAP_NORESERVE 0x4000
#define MAP_GROWSDOWN 0x0100
#define MAP_DENYWRITE 0x0800
#define MAP_EXECUTABLE 0x1000
#define MAP_LOCKED 0x2000
#define MAP_POPULATE 0x8000
#define MAP_NONBLOCK 0x10000
#define MAP_STACK 0x20000
#define MAP_HUGETLB 0x40000
#define MAP_FILE 0
#define PROT_NONE 0
#define PROT_READ 1
#define PROT_WRITE 2
#define PROT_EXEC 4
#define PROT_GROWSDOWN 0x01000000
#define PROT_GROWSUP 0x02000000
#define MS_ASYNC 1
#define MS_INVALIDATE 2
#define MS_SYNC 4
#define MCL_CURRENT 1
#define MCL_FUTURE 2
#define MCL_ONFAULT 4
void
*
mmap
(
void
*
start
,
size_t
len
,
int
prot
,
int
flags
,
int
fd
,
off_t
off
);
int
munmap
(
void
*
start
,
size_t
len
);
#ifdef __cplusplus
}
#endif
#endif
components/libc/compilers/minilibc/sys/stat.h
已删除
100644 → 0
浏览文件 @
b2d3317c
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
*/
#ifndef __STAT_H__
#define __STAT_H__
#include <rtthread.h>
#ifdef RT_USING_DFS
#include <dfs_posix.h>
#else
#define _FREAD 0x0001
/* read enabled */
#define _FWRITE 0x0002
/* write enabled */
#define _FAPPEND 0x0008
/* append (writes guaranteed at the end) */
#define _FMARK 0x0010
/* internal; mark during gc() */
#define _FDEFER 0x0020
/* internal; defer for next gc pass */
#define _FASYNC 0x0040
/* signal pgrp when data ready */
#define _FSHLOCK 0x0080
/* BSD flock() shared lock present */
#define _FEXLOCK 0x0100
/* BSD flock() exclusive lock present */
#define _FCREAT 0x0200
/* open with file create */
#define _FTRUNC 0x0400
/* open with truncation */
#define _FEXCL 0x0800
/* error on open if file exists */
#define _FNBIO 0x1000
/* non blocking I/O (sys5 style) */
#define _FSYNC 0x2000
/* do all writes synchronously */
#define _FNONBLOCK 0x4000
/* non blocking I/O (POSIX style) */
#define _FNDELAY _FNONBLOCK
/* non blocking I/O (4.2 style) */
#define _FNOCTTY 0x8000
/* don't assign a ctty on this open */
#define O_RDONLY 0
/* +1 == FREAD */
#define O_WRONLY 1
/* +1 == FWRITE */
#define O_RDWR 2
/* +1 == FREAD|FWRITE */
#define O_APPEND _FAPPEND
#define O_CREAT _FCREAT
#define O_TRUNC _FTRUNC
#define O_EXCL _FEXCL
#define O_SYNC _FSYNC
#endif
#endif
components/libc/compilers/minilibc/sys/time.h
已删除
100644 → 0
浏览文件 @
b2d3317c
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
*/
#ifndef _SYS_TIME_H_
#define _SYS_TIME_H_
#include <sys/types.h>
typedef
long
time_t
;
/*
* 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. */
};
int
gettimeofday
(
struct
timeval
*
tp
,
void
*
ignore
);
#endif
components/libc/compilers/minilibc/sys/types.h
已删除
100644 → 0
浏览文件 @
b2d3317c
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
*/
#ifndef __TYPES_H__
#define __TYPES_H__
#include <rtconfig.h>
typedef
long
off_t
;
#ifndef ARCH_CPU_64BIT
typedef
unsigned
int
size_t
;
typedef
signed
int
ssize_t
;
/* Used for a count of bytes or an error indication. */
#else
typedef
long
unsigned
int
size_t
;
typedef
long
signed
int
ssize_t
;
/* Used for a count of bytes or an error indication. */
#endif
typedef
unsigned
char
u_char
;
typedef
unsigned
short
u_short
;
typedef
unsigned
int
u_int
;
typedef
unsigned
long
u_long
;
typedef
unsigned
long
clockid_t
;
typedef
int
pid_t
;
typedef
int
gid_t
;
typedef
int
uid_t
;
typedef
int
dev_t
;
typedef
int
ino_t
;
typedef
int
mode_t
;
typedef
int
caddr_t
;
typedef
unsigned
int
wint_t
;
typedef
unsigned
long
useconds_t
;
typedef
unsigned
long
clock_t
;
/* clock() */
#ifndef NULL
#define NULL (0)
#endif
#define __u_char_defined
#endif
components/libc/compilers/minilibc/time.c
已删除
100644 → 0
浏览文件 @
b2d3317c
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
*/
#include <time.h>
#include <rtthread.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"
);
RT_ASSERT
(
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
;
}
#endif
#ifndef _gettimeofday
/* Dummy function when hardware do not have RTC */
int
_gettimeofday
(
struct
timeval
*
tv
,
void
*
ignore
)
{
tv
->
tv_sec
=
0
;
// convert to seconds
tv
->
tv_usec
=
0
;
// get remaining microseconds
return
0
;
// return non-zero for error
}
#endif
/**
* Returns the current time.
*
* @param time_t * t the timestamp pointer, if not used, keep NULL.
*
* @return time_t return timestamp current.
*
*/
/* for IAR 6.2 later Compiler */
#if defined (__IAR_SYSTEMS_ICC__) && (__VER__) >= 6020000
#pragma module_name = "?time"
time_t
(
__time32
)(
time_t
*
t
)
/* Only supports 32-bit timestamp */
#else
time_t
time
(
time_t
*
t
)
#endif
{
time_t
time_now
=
0
;
#ifdef RT_USING_RTC
static
rt_device_t
device
=
RT_NULL
;
/* optimization: find rtc device only first. */
if
(
device
==
RT_NULL
)
{
device
=
rt_device_find
(
"rtc"
);
}
/* read timestamp from RTC device. */
if
(
device
!=
RT_NULL
)
{
if
(
rt_device_open
(
device
,
0
)
==
RT_EOK
)
{
rt_device_control
(
device
,
RT_DEVICE_CTRL_RTC_GET_TIME
,
&
time_now
);
rt_device_close
(
device
);
}
}
#endif
/* RT_USING_RTC */
/* if t is not NULL, write timestamp to *t */
if
(
t
!=
RT_NULL
)
{
*
t
=
time_now
;
}
return
time_now
;
}
RT_WEAK
clock_t
clock
(
void
)
{
return
rt_tick_get
();
}
components/libc/compilers/minilibc/time.h
已删除
100644 → 0
浏览文件 @
b2d3317c
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
*/
#ifndef __TIME_H__
#define __TIME_H__
#include <sys/time.h>
time_t
mktime
(
struct
tm
*
const
t
);
char
*
asctime
(
const
struct
tm
*
timeptr
);
char
*
ctime
(
const
time_t
*
timep
);
struct
tm
*
localtime
(
const
time_t
*
t
);
char
*
asctime_r
(
const
struct
tm
*
t
,
char
*
buf
);
struct
tm
*
gmtime_r
(
const
time_t
*
timep
,
struct
tm
*
r
);
struct
tm
*
localtime_r
(
const
time_t
*
t
,
struct
tm
*
r
);
#endif
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录