[posix][io]整理posix/io文件夹 (#5539)

* [posix][io]整理posix/io文件夹
- 将select.c移入到poll文件夹
- 将libc.c移入到tty文件夹,isatty函数归并到libc.c中, termios并入tty文件夹中
- 整理Sconscript

Signed-off-by: Meco Man <920369182@qq.com>

* [libc][newlib]调整文件夹结构
This commit is contained in:
Man, Jianting (Meco) 2022-01-23 20:16:57 -05:00 committed by GitHub
parent e10173daff
commit 31c3214faf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 64 additions and 133 deletions

View File

@ -1,53 +0,0 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2017/10/15 bernard the first version
*/
#include <rtthread.h>
#include <rtm.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
RTM_EXPORT(strcpy);
RTM_EXPORT(strncpy);
RTM_EXPORT(strlen);
RTM_EXPORT(strcat);
RTM_EXPORT(strstr);
RTM_EXPORT(strchr);
RTM_EXPORT(strcmp);
RTM_EXPORT(strtol);
RTM_EXPORT(strtoul);
RTM_EXPORT(strncmp);
RTM_EXPORT(memcpy);
RTM_EXPORT(memcmp);
RTM_EXPORT(memmove);
RTM_EXPORT(memset);
RTM_EXPORT(memchr);
RTM_EXPORT(putchar);
RTM_EXPORT(puts);
RTM_EXPORT(printf);
RTM_EXPORT(sprintf);
RTM_EXPORT(snprintf);
RTM_EXPORT(fwrite);
#include <setjmp.h>
RTM_EXPORT(longjmp);
RTM_EXPORT(setjmp);
RTM_EXPORT(exit);
RTM_EXPORT(abort);
RTM_EXPORT(rand);
#include <assert.h>
RTM_EXPORT(__assert_func);

View File

@ -0,0 +1,10 @@
This folder contains:
| sub-folders | description |
| ----------- | ------------------------- |
| aio | Asynchronous I/O |
| mman | Memory-Mapped I/O |
| poll | Nonblocking I/O |
| stdio | Standard Input/Output I/O |
| termios | Terminal I/O |

View File

@ -3,24 +3,9 @@
import os
from building import *
src = []
cwd = GetCurrentDir()
CPPPATH = [cwd]
group = []
flag = False
if GetDepend('RT_USING_POSIX_STDIO'):
src += ['libc.c']
flag = True
if GetDepend('RT_USING_POSIX_SELECT'):
src += ['select.c']
flag = True
if flag == True:
group = DefineGroup('POSIX', src, depend = [''], CPPPATH = CPPPATH)
list = os.listdir(cwd)
for d in list:
path = os.path.join(cwd, d)

View File

@ -9,6 +9,9 @@ CPPPATH = [cwd]
if GetDepend('RT_USING_POSIX_POLL'):
src += ['poll.c']
if GetDepend('RT_USING_POSIX_SELECT'):
src += ['select.c']
group = DefineGroup('POSIX', src, depend = [''], CPPPATH = CPPPATH)
Return('group')

View File

@ -0,0 +1,22 @@
# RT-Thread building script for component
import os
from building import *
src = []
cwd = GetCurrentDir()
CPPPATH = [cwd]
group = []
if GetDepend('RT_USING_POSIX_STDIO'):
src += ['libc.c']
group = DefineGroup('POSIX', src, depend = [''], CPPPATH = CPPPATH)
list = os.listdir(cwd)
for d in list:
path = os.path.join(cwd, d)
if os.path.isfile(os.path.join(path, 'SConscript')):
group = group + SConscript(os.path.join(d, 'SConscript'))
Return('group')

View File

@ -15,9 +15,8 @@
#include <unistd.h>
#include <fcntl.h>
#include <sys/time.h>
#include <sys/errno.h>
#include "libc.h"
#include <stdio.h>
#include <stdlib.h>
int libc_system_init(void)
{
@ -108,7 +107,7 @@ int libc_stdio_get_console(void)
return -1;
}
#else
#elif defined(RT_USING_POSIX_STDIO)
#define STDIO_DEVICE_NAME_MAX 32
static int std_fd = -1;
int libc_stdio_set_console(const char* device_name, int mode)
@ -136,3 +135,24 @@ int libc_stdio_get_console(void) {
return std_fd;
}
#endif /* defined(RT_USING_POSIX_STDIO) && defined(RT_USING_NEWLIB) */
int isatty(int fd)
{
#if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
if(fd == STDOUT_FILENO || fd == STDERR_FILENO)
{
return 1;
}
#endif
#ifdef RT_USING_POSIX_STDIO
if(fd == STDIN_FILENO)
{
return 1;
}
#endif
rt_set_errno(ENOTTY);
return 0;
}
RTM_EXPORT(isatty);

View File

@ -11,8 +11,6 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/statfs.h>
#include <sys/errno.h>
#include "termios.h"

View File

@ -1,7 +1,7 @@
from building import *
Import('rtconfig')
src = Glob('*.c') + Glob('*.cpp') + Glob('arch/*.c')
src = Glob('*.c') + Glob('arch/*.c')
cwd = GetCurrentDir()
group = []
CPPPATH = [cwd]

View File

@ -4,5 +4,8 @@ This folder provides functions that are not part of the standard C library but a
## NOTE
1. For consistency of compilation results across the different of platforms(gcc, keil, iar) , you better use ``#include <sys/time.h>`` to instead of ``#include <time.h>``.
1. For consistency of compilation results across the different of platforms(gcc, keil, iar) , use:
- `#include <sys/time.h>` to instead of `#include <time.h>`
- `#include <sys/errno.h>` to instead of `#include <errno.h>`
- `#include <sys/signal.h>` to instead of `#include <signal.h>`

View File

@ -1,16 +0,0 @@
# RT-Thread building script for component
from building import *
src = []
cwd = GetCurrentDir()
CPPPATH = [cwd]
group = []
flag = False
src += ['unistd.c'] #TODO
if flag == True:
group = DefineGroup('POSIX', src, depend = [''], CPPPATH = CPPPATH)
Return('group')

View File

@ -1,41 +0,0 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2020-09-01 Meco Man first Version
* 2021-02-12 Meco Man move all functions located in <pthread_sleep.c> to this file
*/
#include <rtthread.h>
#include <unistd.h>
#ifdef RT_USING_POSIX_TERMIOS
#include "termios.h"
int isatty(int fd)
{
struct termios ts;
return(tcgetattr(fd, &ts) != -1); /*true if no error (is a tty)*/
}
#else
int isatty(int fd)
{
if (fd >=0 && fd < 3)
{
return 1;
}
else
{
return 0;
}
}
#endif
RTM_EXPORT(isatty);
char *ttyname(int fd)
{
return "/dev/tty"; /* TODO: need to add more specific */
}
RTM_EXPORT(ttyname);