Skip to content

Commit ca18a17

Browse files
committed
Merge remote-tracking branch 'china/master'
2 parents 390973a + 2c88533 commit ca18a17

File tree

10 files changed

+204
-72
lines changed

10 files changed

+204
-72
lines changed

components/libc/SConscript

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ if GetDepend('RT_USING_LIBC'):
1111
objs = objs + SConscript('newlib/SConscript')
1212
elif rtconfig.PLATFORM == 'armcc':
1313
objs = objs + SConscript('armlibc/SConscript')
14+
elif rtconfig.PLATFORM == 'iar':
15+
objs = objs + SConscript('dlib/SConscript')
1416
else:
1517
if rtconfig.PLATFORM == 'gcc':
1618
objs = objs + SConscript('minilibc/SConscript')

components/libc/dlib/SConscript

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ CPPDEFINES = ['RT_USING_DLIBC']
1010

1111
if rtconfig.PLATFORM == 'iar':
1212
group = DefineGroup('dlib', src, depend = ['RT_USING_LIBC'],
13-
CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES, LIBS = LIBS)
13+
CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES)
1414

1515
Return('group')

components/libc/dlib/rmtx.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
*/
3131

3232
#if _DLIB_THREAD_SUPPORT
33+
typedef void* _Rmtx;
3334
void _Mtxinit(_Rmtx *m)
3435
{
3536
rt_mutex_t mutex;
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* File : syscall_close.c
3+
* This file is part of RT-Thread RTOS
4+
* COPYRIGHT (C) 2006 - 2015, RT-Thread Development Team
5+
*
6+
* This program is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation; either version 2 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License along
17+
* with this program; if not, write to the Free Software Foundation, Inc.,
18+
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19+
*
20+
* Change Logs:
21+
* Date Author Notes
22+
* 2015-01-28 Bernard first version
23+
*/
24+
#include <rtthread.h>
25+
#ifdef RT_USING_DFS
26+
#include <dfs_posix.h>
27+
#endif
28+
#include <yfuns.h>
29+
30+
#pragma module_name = "?__close"
31+
int __close(int handle)
32+
{
33+
if (handle == _LLIO_STDOUT ||
34+
handle == _LLIO_STDERR ||
35+
handle == _LLIO_STDIN)
36+
return _LLIO_ERROR;
37+
38+
#ifdef RT_USING_DFS
39+
return close(handle);
40+
#else
41+
return 0;
42+
#endif
43+
}
Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* File : syscalls.c
2+
* File : syscall_lseek.c
33
* This file is part of RT-Thread RTOS
44
* COPYRIGHT (C) 2006 - 2015, RT-Thread Development Team
55
*
@@ -23,46 +23,21 @@
2323
*/
2424
#include <rtthread.h>
2525
#ifdef RT_USING_DFS
26-
#include <dfs_file.h>
26+
#include <dfs_posix.h>
2727
#endif
2828
#include <yfuns.h>
2929

30-
#pragma module_name = "?__close"
31-
int __close(int handle)
32-
{
33-
if (handle == _LLIO_STDOUT ||
34-
handle == _LLIO_STDERR ||
35-
handle == _LLIO_STDIN)
36-
return _LLIO_ERROR;
37-
38-
#ifdef RT_USING_DFS
39-
return close(handle);
40-
#else
41-
return 0;
42-
#endif
43-
}
44-
45-
#pragma module_name = "?remove"
46-
int remove(const char *val)
47-
{
48-
#ifdef RT_USING_DFS
49-
dfs_file_unlink(val);
50-
#endif
51-
52-
return 0;
53-
}
54-
5530
#pragma module_name = "?__lseek"
5631
long __lseek(int handle, long offset, int whence)
5732
{
58-
#ifdef RT_USING_DFS
59-
#endif
60-
6133
if (handle == _LLIO_STDOUT ||
6234
handle == _LLIO_STDERR ||
6335
handle == _LLIO_STDIN)
6436
return _LLIO_ERROR;
6537

38+
#ifdef RT_USING_DFS
6639
return lseek(handle, offset, whence);
40+
#else
41+
return _LLIO_ERROR;
42+
#endif
6743
}
68-

components/libc/dlib/syscall_mem.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* File : syscall_mem.c
3+
* This file is part of RT-Thread RTOS
4+
* COPYRIGHT (C) 2006 - 2015, RT-Thread Development Team
5+
*
6+
* This program is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation; either version 2 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License along
17+
* with this program; if not, write to the Free Software Foundation, Inc.,
18+
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19+
*
20+
* Change Logs:
21+
* Date Author Notes
22+
* 2015-01-28 Bernard first version
23+
*/
24+
#include <rtthread.h>
25+
26+
void *malloc(rt_size_t n)
27+
{
28+
return rt_malloc(n);
29+
}
30+
31+
void *realloc(void *rmem, rt_size_t newsize)
32+
{
33+
return rt_realloc(rmem, newsize);
34+
}
35+
36+
void *calloc(rt_size_t nelem, rt_size_t elsize)
37+
{
38+
return rt_calloc(nelem, elsize);
39+
}
40+
41+
void free(void *rmem)
42+
{
43+
rt_free(rmem);
44+
}

components/libc/dlib/syscall_open.c

Lines changed: 60 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
/*
2-
* File : syscall_open.c
3-
* This file is part of RT-Thread RTOS
4-
* COPYRIGHT (C) 2006 - 2015, RT-Thread Development Team
5-
*
6-
* This program is free software; you can redistribute it and/or modify
7-
* it under the terms of the GNU General Public License as published by
8-
* the Free Software Foundation; either version 2 of the License, or
9-
* (at your option) any later version.
10-
*
11-
* This program is distributed in the hope that it will be useful,
12-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14-
* GNU General Public License for more details.
15-
*
16-
* You should have received a copy of the GNU General Public License along
17-
* with this program; if not, write to the Free Software Foundation, Inc.,
18-
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19-
*
20-
* Change Logs:
21-
* Date Author Notes
22-
* 2015-01-28 Bernard first version
23-
*/
2+
* File : syscall_open.c
3+
* This file is part of RT-Thread RTOS
4+
* COPYRIGHT (C) 2006 - 2015, RT-Thread Development Team
5+
*
6+
* This program is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation; either version 2 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License along
17+
* with this program; if not, write to the Free Software Foundation, Inc.,
18+
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19+
*
20+
* Change Logs:
21+
* Date Author Notes
22+
* 2015-01-28 Bernard first version
23+
*/
2424

2525
#include <rtthread.h>
2626
#include <yfuns.h>
@@ -32,33 +32,57 @@
3232

3333
int __open(const char *filename, int mode)
3434
{
35-
if (mode & _LLIO_CREAT)
35+
#ifndef RT_USING_DFS
36+
return -1;
37+
#else
38+
int handle;
39+
int open_mode = O_RDONLY;
40+
41+
if (mode & _LLIO_CREAT)
42+
{
43+
open_mode |= O_CREAT;
44+
45+
/* Check what we should do with it if it exists. */
46+
if (mode & _LLIO_APPEND)
3647
{
48+
/* Append to the existing file. */
49+
open_mode |= O_APPEND;
3750
}
3851

39-
if (mode & _LLIO_TEXT)
52+
if (mode & _LLIO_TRUNC)
4053
{
41-
/* we didn't support text mode */
54+
/* Truncate the existsing file. */
55+
open_mode |= O_TRUNC;
4256
}
43-
44-
switch (mode & _LLIO_RDWRMASK)
45-
{
57+
}
58+
59+
if (mode & _LLIO_TEXT)
60+
{
61+
/* we didn't support text mode */
62+
}
63+
64+
switch (mode & _LLIO_RDWRMASK)
65+
{
4666
case _LLIO_RDONLY:
47-
/* The file should be opened for read only. */
4867
break;
49-
68+
5069
case _LLIO_WRONLY:
51-
/* The file should be opened for write only. */
70+
open_mode |= O_WRONLY;
5271
break;
53-
72+
5473
case _LLIO_RDWR:
5574
/* The file should be opened for both reads and writes. */
75+
open_mode |= O_RDWR;
5676
break;
57-
77+
5878
default:
5979
return -1;
6080
}
61-
62-
return handle;
81+
82+
handle = open(filename, open_mode, 0);
83+
if (handle < 0)
84+
return -1;
85+
86+
return handle + _LLIO_STDERR + 1;
87+
#endif
6388
}
64-

components/libc/dlib/syscall_read.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
*/
2424

2525
#include <rtthread.h>
26+
#ifdef RT_USING_DFS
27+
#include <dfs_posix.h>
28+
#endif
2629
#include <yfuns.h>
2730

2831
#pragma module_name = "?__read"
@@ -44,8 +47,7 @@ size_t __read(int handle, unsigned char *buf, size_t len)
4447
#ifndef RT_USING_DFS
4548
return _LLIO_ERROR;
4649
#else
47-
size = read(handle - STDERR - 1, buf, len);
50+
size = read(handle - _LLIO_STDERR - 1, buf, len);
4851
return size;
4952
#endif
5053
}
51-
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* File : syscall_remove.c
3+
* This file is part of RT-Thread RTOS
4+
* COPYRIGHT (C) 2006 - 2015, RT-Thread Development Team
5+
*
6+
* This program is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation; either version 2 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License along
17+
* with this program; if not, write to the Free Software Foundation, Inc.,
18+
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19+
*
20+
* Change Logs:
21+
* Date Author Notes
22+
* 2015-01-28 Bernard first version
23+
*/
24+
#include <rtthread.h>
25+
#ifdef RT_USING_DFS
26+
#include <dfs_file.h>
27+
#endif
28+
#include <yfuns.h>
29+
30+
#pragma module_name = "?remove"
31+
int remove(const char *val)
32+
{
33+
#ifdef RT_USING_DFS
34+
dfs_file_unlink(val);
35+
#endif
36+
37+
return 0;
38+
}

components/libc/dlib/syscall_write.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
*/
2424

2525
#include <rtthread.h>
26+
#ifdef RT_USING_DFS
27+
#include <dfs_posix.h>
28+
#endif
2629
#include <yfuns.h>
2730

2831
#pragma module_name = "?__write"
@@ -47,12 +50,12 @@ size_t __write(int handle, const unsigned char *buf, size_t len)
4750
#endif
4851
}
4952

50-
if (handle == STDIN) return -1;
53+
if (handle == _LLIO_STDIN) return -1;
5154

5255
#ifndef RT_USING_DFS
5356
return _LLIO_ERROR;
5457
#else
55-
size = write(handle - STDERR - 1, buf, len);
58+
size = write(handle - _LLIO_STDERR - 1, buf, len);
5659
return size;
5760
#endif
5861
}

0 commit comments

Comments
 (0)