mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2025-12-26 09:08:25 +00:00
[libc][posix/io/stdio] rename libc.c as posix/stdio.c
This commit is contained in:
@@ -23,7 +23,7 @@
|
||||
#include <sys/stat.h>
|
||||
#include <compiler_private.h>
|
||||
#ifdef RT_USING_POSIX_STDIO
|
||||
#include "libc.h"
|
||||
#include <posix/stdio.h>
|
||||
#endif /* RT_USING_POSIX_STDIO */
|
||||
|
||||
#define DBG_TAG "armlibc.syscalls"
|
||||
@@ -153,7 +153,7 @@ int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode)
|
||||
if (fh == STDIN)
|
||||
{
|
||||
#ifdef RT_USING_POSIX_STDIO
|
||||
if (libc_stdio_get_console() < 0)
|
||||
if (rt_posix_stdio_get_console() < 0)
|
||||
{
|
||||
LOG_W("Do not invoke standard output before initializing Compiler");
|
||||
return 0; /* error, but keep going */
|
||||
@@ -375,7 +375,7 @@ int fgetc(FILE *f)
|
||||
#ifdef RT_USING_POSIX_STDIO
|
||||
char ch;
|
||||
|
||||
if (libc_stdio_get_console() < 0)
|
||||
if (rt_posix_stdio_get_console() < 0)
|
||||
{
|
||||
LOG_W("Do not invoke standard output before initializing Compiler");
|
||||
return 0;
|
||||
|
||||
@@ -1,87 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2014-05-22 ivanrad implement getline
|
||||
*/
|
||||
|
||||
#include "posix/stdio.h"
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
#include <sys/errno.h>
|
||||
|
||||
#ifdef DFS_USING_POSIX
|
||||
ssize_t getdelim(char **lineptr, size_t *n, int delim, FILE *stream)
|
||||
{
|
||||
char *cur_pos, *new_lineptr;
|
||||
size_t new_lineptr_len;
|
||||
int c;
|
||||
|
||||
if (lineptr == NULL || n == NULL || stream == NULL)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (*lineptr == NULL)
|
||||
{
|
||||
*n = 128; /* init len */
|
||||
if ((*lineptr = (char *)malloc(*n)) == NULL)
|
||||
{
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
cur_pos = *lineptr;
|
||||
for (;;)
|
||||
{
|
||||
c = getc(stream);
|
||||
|
||||
if (ferror(stream) || (c == EOF && cur_pos == *lineptr))
|
||||
return -1;
|
||||
|
||||
if (c == EOF)
|
||||
break;
|
||||
|
||||
if ((*lineptr + *n - cur_pos) < 2)
|
||||
{
|
||||
if (LONG_MAX / 2 < *n)
|
||||
{
|
||||
#ifdef EOVERFLOW
|
||||
errno = EOVERFLOW;
|
||||
#else
|
||||
errno = ERANGE; /* no EOVERFLOW defined */
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
new_lineptr_len = *n * 2;
|
||||
|
||||
if ((new_lineptr = (char *)realloc(*lineptr, new_lineptr_len)) == NULL)
|
||||
{
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
cur_pos = new_lineptr + (cur_pos - *lineptr);
|
||||
*lineptr = new_lineptr;
|
||||
*n = new_lineptr_len;
|
||||
}
|
||||
|
||||
*cur_pos++ = (char)c;
|
||||
|
||||
if (c == delim)
|
||||
break;
|
||||
}
|
||||
|
||||
*cur_pos = '\0';
|
||||
return (ssize_t)(cur_pos - *lineptr);
|
||||
}
|
||||
|
||||
ssize_t getline(char **lineptr, size_t *n, FILE *stream)
|
||||
{
|
||||
return getdelim(lineptr, n, '\n', stream);
|
||||
}
|
||||
#endif /* DFS_USING_POSIX */
|
||||
34
components/libc/compilers/common/cunistd.c
Normal file
34
components/libc/compilers/common/cunistd.c
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2023-08-16 Meco Man first version
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/errno.h>
|
||||
|
||||
int isatty(int fd)
|
||||
{
|
||||
#if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
|
||||
if(fd == STDOUT_FILENO || fd == STDERR_FILENO)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
#endif /* defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE) */
|
||||
|
||||
#ifdef RT_USING_POSIX_STDIO
|
||||
if(fd == STDIN_FILENO)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
#endif /* RT_USING_POSIX_STDIO */
|
||||
|
||||
rt_set_errno(ENOTTY);
|
||||
return 0;
|
||||
}
|
||||
RTM_EXPORT(isatty);
|
||||
@@ -1,30 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2022-06-07 Meco Man first version
|
||||
*/
|
||||
|
||||
#ifndef __POSIX_STDIO_H__
|
||||
#define __POSIX_STDIO_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef DFS_USING_POSIX
|
||||
ssize_t getdelim(char **lineptr, size_t *n, int delim, FILE *stream);
|
||||
ssize_t getline(char **lineptr, size_t *n, FILE *stream);
|
||||
#endif /* DFS_USING_POSIX */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __POSIX_STDIO_H__ */
|
||||
@@ -12,7 +12,7 @@
|
||||
#include <LowLevelIOInterface.h>
|
||||
#include <unistd.h>
|
||||
#ifdef RT_USING_POSIX_STDIO
|
||||
#include "libc.h"
|
||||
#include <posix/stdio.h>
|
||||
#endif /* RT_USING_POSIX_STDIO */
|
||||
#include <compiler_private.h>
|
||||
#define DBG_TAG "dlib.syscall.read"
|
||||
@@ -40,7 +40,7 @@ size_t __read(int handle, unsigned char *buf, size_t len)
|
||||
if (handle == _LLIO_STDIN)
|
||||
{
|
||||
#ifdef RT_USING_POSIX_STDIO
|
||||
if (libc_stdio_get_console() < 0)
|
||||
if (rt_posix_stdio_get_console() < 0)
|
||||
{
|
||||
LOG_W("Do not invoke standard input before initializing Compiler");
|
||||
return 0; /* error, but keep going */
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#include <sys/errno.h>
|
||||
#include <sys/stat.h>
|
||||
#ifdef RT_USING_POSIX_STDIO
|
||||
#include "libc.h"
|
||||
#include <posix/stdio.h>
|
||||
#endif /* RT_USING_POSIX_STDIO */
|
||||
#ifdef RT_USING_MODULE
|
||||
#include <dlmodule.h>
|
||||
@@ -225,7 +225,7 @@ _ssize_t _read_r(struct _reent *ptr, int fd, void *buf, size_t nbytes)
|
||||
if (fd == STDIN_FILENO)
|
||||
{
|
||||
#ifdef RT_USING_POSIX_STDIO
|
||||
if (libc_stdio_get_console() < 0)
|
||||
if (rt_posix_stdio_get_console() < 0)
|
||||
{
|
||||
LOG_W("Do not invoke standard input before initializing Compiler");
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user