import RT-Thread@9217865c without bsp, libcpu and components/net
This commit is contained in:
commit
e2376a3709
1414 changed files with 390370 additions and 0 deletions
15
components/libc/compilers/SConscript
Normal file
15
components/libc/compilers/SConscript
Normal file
|
@ -0,0 +1,15 @@
|
|||
# RT-Thread building script for bridge
|
||||
|
||||
import os
|
||||
from building import *
|
||||
|
||||
cwd = GetCurrentDir()
|
||||
objs = []
|
||||
list = os.listdir(cwd)
|
||||
|
||||
for d in list:
|
||||
path = os.path.join(cwd, d)
|
||||
if os.path.isfile(os.path.join(path, 'SConscript')):
|
||||
objs = objs + SConscript(os.path.join(d, 'SConscript'))
|
||||
|
||||
Return('objs')
|
5
components/libc/compilers/armlibc/README.md
Normal file
5
components/libc/compilers/armlibc/README.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
# ARMLIB (Keil-MDK) porting for RT-Thread
|
||||
|
||||
https://www.keil.com/support/man/docs/armlib/
|
||||
|
||||
https://www.keil.com/support/man/docs/armlib/armlib_chr1358938918041.htm
|
12
components/libc/compilers/armlibc/SConscript
Normal file
12
components/libc/compilers/armlibc/SConscript
Normal file
|
@ -0,0 +1,12 @@
|
|||
from building import *
|
||||
Import('rtconfig')
|
||||
|
||||
src = Glob('*.c')
|
||||
group = []
|
||||
|
||||
if rtconfig.PLATFORM in ['armcc', 'armclang']:
|
||||
CPPDEFINES = ['RT_USING_ARMLIBC', 'RT_USING_LIBC', '__STDC_LIMIT_MACROS']
|
||||
AddDepend(['RT_USING_ARMLIBC', 'RT_USING_LIBC'])
|
||||
group = DefineGroup('Compiler', src, depend = [''], CPPDEFINES = CPPDEFINES)
|
||||
|
||||
Return('group')
|
71
components/libc/compilers/armlibc/syscall_mem.c
Normal file
71
components/libc/compilers/armlibc/syscall_mem.c
Normal file
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2021, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2014-08-03 bernard Add file header
|
||||
* 2021-11-13 Meco Man implement no-heap warning
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#ifndef RT_USING_HEAP
|
||||
#define DBG_TAG "armlibc.syscall.mem"
|
||||
#define DBG_LVL DBG_INFO
|
||||
#include <rtdbg.h>
|
||||
|
||||
#define _NO_HEAP_ERROR() do{LOG_E("Please enable RT_USING_HEAP");\
|
||||
RT_ASSERT(0);\
|
||||
}while(0)
|
||||
#endif /* RT_USING_HEAP */
|
||||
|
||||
#ifdef __CC_ARM
|
||||
/* avoid the heap and heap-using library functions supplied by arm */
|
||||
#pragma import(__use_no_heap)
|
||||
#endif /* __CC_ARM */
|
||||
|
||||
void *malloc(size_t n)
|
||||
{
|
||||
#ifdef RT_USING_HEAP
|
||||
return rt_malloc(n);
|
||||
#else
|
||||
_NO_HEAP_ERROR();
|
||||
return RT_NULL;
|
||||
#endif
|
||||
}
|
||||
RTM_EXPORT(malloc);
|
||||
|
||||
void *realloc(void *rmem, size_t newsize)
|
||||
{
|
||||
#ifdef RT_USING_HEAP
|
||||
return rt_realloc(rmem, newsize);
|
||||
#else
|
||||
_NO_HEAP_ERROR();
|
||||
return RT_NULL;
|
||||
#endif
|
||||
}
|
||||
RTM_EXPORT(realloc);
|
||||
|
||||
void *calloc(size_t nelem, size_t elsize)
|
||||
{
|
||||
#ifdef RT_USING_HEAP
|
||||
return rt_calloc(nelem, elsize);
|
||||
#else
|
||||
_NO_HEAP_ERROR();
|
||||
return RT_NULL;
|
||||
#endif
|
||||
}
|
||||
RTM_EXPORT(calloc);
|
||||
|
||||
void free(void *rmem)
|
||||
{
|
||||
#ifdef RT_USING_HEAP
|
||||
rt_free(rmem);
|
||||
#else
|
||||
_NO_HEAP_ERROR();
|
||||
#endif
|
||||
}
|
||||
RTM_EXPORT(free);
|
391
components/libc/compilers/armlibc/syscalls.c
Normal file
391
components/libc/compilers/armlibc/syscalls.c
Normal file
|
@ -0,0 +1,391 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2012-11-23 Yihui The first version
|
||||
* 2013-11-24 aozima fixed _sys_read()/_sys_write() issues.
|
||||
* 2014-08-03 bernard If using msh, use system() implementation
|
||||
* in msh.
|
||||
* 2020-08-05 Meco Man fixed _sys_flen() compiling-warning when
|
||||
* RT_USING_DFS is not defined
|
||||
* 2020-02-13 Meco Man re-implement exit() and abort()
|
||||
* 2020-02-14 Meco Man implement _sys_tmpnam()
|
||||
*/
|
||||
|
||||
#include <rt_sys.h>
|
||||
#include <rtthread.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include <compiler_private.h>
|
||||
#ifdef RT_USING_POSIX_STDIO
|
||||
#include "libc.h"
|
||||
#endif /* RT_USING_POSIX_STDIO */
|
||||
|
||||
#define DBG_TAG "armlibc.syscalls"
|
||||
#define DBG_LVL DBG_INFO
|
||||
#include <rtdbg.h>
|
||||
|
||||
#ifdef __clang__
|
||||
__asm(".global __use_no_semihosting\n\t");
|
||||
#else
|
||||
#pragma import(__use_no_semihosting_swi)
|
||||
#endif
|
||||
|
||||
/* Standard IO device handles. */
|
||||
#define STDIN 0
|
||||
#define STDOUT 1
|
||||
#define STDERR 2
|
||||
|
||||
/* Standard IO device name defines. */
|
||||
const char __stdin_name[] = "STDIN";
|
||||
const char __stdout_name[] = "STDOUT";
|
||||
const char __stderr_name[] = "STDERR";
|
||||
|
||||
/**
|
||||
* required by fopen() and freopen().
|
||||
*
|
||||
* @param name - file name with path.
|
||||
* @param openmode - a bitmap hose bits mostly correspond directly to
|
||||
* the ISO mode specification.
|
||||
* @return -1 if an error occurs.
|
||||
*/
|
||||
FILEHANDLE _sys_open(const char *name, int openmode)
|
||||
{
|
||||
#ifdef DFS_USING_POSIX
|
||||
int fd;
|
||||
int mode = O_RDONLY;
|
||||
#endif /* DFS_USING_POSIX */
|
||||
|
||||
/* Register standard Input Output devices. */
|
||||
if (strcmp(name, __stdin_name) == 0)
|
||||
return (STDIN);
|
||||
if (strcmp(name, __stdout_name) == 0)
|
||||
return (STDOUT);
|
||||
if (strcmp(name, __stderr_name) == 0)
|
||||
return (STDERR);
|
||||
|
||||
#ifndef DFS_USING_POSIX
|
||||
LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
|
||||
return -1; /* error */
|
||||
#else
|
||||
/* Correct openmode from fopen to open */
|
||||
if (openmode & OPEN_PLUS)
|
||||
{
|
||||
if (openmode & OPEN_W)
|
||||
{
|
||||
mode |= (O_RDWR | O_TRUNC | O_CREAT);
|
||||
}
|
||||
else if (openmode & OPEN_A)
|
||||
{
|
||||
mode |= (O_RDWR | O_APPEND | O_CREAT);
|
||||
}
|
||||
else
|
||||
mode |= O_RDWR;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (openmode & OPEN_W)
|
||||
{
|
||||
mode |= (O_WRONLY | O_TRUNC | O_CREAT);
|
||||
}
|
||||
else if (openmode & OPEN_A)
|
||||
{
|
||||
mode |= (O_WRONLY | O_APPEND | O_CREAT);
|
||||
}
|
||||
}
|
||||
|
||||
fd = open(name, mode, 0);
|
||||
if (fd < 0)
|
||||
return -1; /* error */
|
||||
else
|
||||
return fd;
|
||||
#endif /* DFS_USING_POSIX */
|
||||
}
|
||||
|
||||
int _sys_close(FILEHANDLE fh)
|
||||
{
|
||||
#ifdef DFS_USING_POSIX
|
||||
if (fh <= STDERR)
|
||||
return 0; /* error */
|
||||
|
||||
return close(fh);
|
||||
#else
|
||||
LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
|
||||
return 0; /* error */
|
||||
#endif /* DFS_USING_POSIX */
|
||||
}
|
||||
|
||||
/*
|
||||
* Read from a file. Can return:
|
||||
* - zero if the read was completely successful
|
||||
* - the number of bytes _not_ read, if the read was partially successful
|
||||
* - the number of bytes not read, plus the top bit set (0x80000000), if
|
||||
* the read was partially successful due to end of file
|
||||
* - -1 if some error other than EOF occurred
|
||||
*
|
||||
* It is also legal to signal EOF by returning no data but
|
||||
* signalling no error (i.e. the top-bit-set mechanism need never
|
||||
* be used).
|
||||
*
|
||||
* So if (for example) the user is trying to read 8 bytes at a time
|
||||
* from a file in which only 5 remain, this routine can do three
|
||||
* equally valid things:
|
||||
*
|
||||
* - it can return 0x80000003 (3 bytes not read due to EOF)
|
||||
* - OR it can return 3 (3 bytes not read), and then return
|
||||
* 0x80000008 (8 bytes not read due to EOF) on the next attempt
|
||||
* - OR it can return 3 (3 bytes not read), and then return
|
||||
* 8 (8 bytes not read, meaning 0 read, meaning EOF) on the next
|
||||
* attempt
|
||||
*
|
||||
* `mode' exists for historical reasons and must be ignored.
|
||||
*/
|
||||
int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode)
|
||||
{
|
||||
#ifdef DFS_USING_POSIX
|
||||
int size;
|
||||
|
||||
if (fh == STDIN)
|
||||
{
|
||||
#ifdef RT_USING_POSIX_STDIO
|
||||
if (libc_stdio_get_console() < 0)
|
||||
{
|
||||
LOG_W("Do not invoke standard output before initializing Compiler");
|
||||
return 0; /* error, but keep going */
|
||||
}
|
||||
size = read(STDIN_FILENO, buf, len);
|
||||
return len - size; /* success */
|
||||
#else
|
||||
LOG_W("%s: %s", __func__, _WARNING_WITHOUT_STDIO);
|
||||
return 0; /* error */
|
||||
#endif /* RT_USING_POSIX_STDIO */
|
||||
}
|
||||
else if (fh == STDOUT || fh == STDERR)
|
||||
{
|
||||
return -1; /* 100% error */
|
||||
}
|
||||
else
|
||||
{
|
||||
size = read(fh, buf, len);
|
||||
if (size >= 0)
|
||||
{
|
||||
return len - size; /* success */
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0; /* error */
|
||||
}
|
||||
}
|
||||
#else
|
||||
LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
|
||||
return 0; /* error */
|
||||
#endif /* DFS_USING_POSIX */
|
||||
}
|
||||
|
||||
/*
|
||||
* Write to a file. Returns 0 on success, negative on error, and
|
||||
* the number of characters _not_ written on partial success.
|
||||
* `mode' exists for historical reasons and must be ignored.
|
||||
* The return value is either:
|
||||
* A positive number representing the number of characters not written
|
||||
* (so any nonzero return value denotes a failure of some sort).
|
||||
* A negative number indicating an error.
|
||||
*/
|
||||
int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode)
|
||||
{
|
||||
#ifdef DFS_USING_POSIX
|
||||
int size;
|
||||
#endif /* DFS_USING_POSIX */
|
||||
|
||||
if (fh == STDOUT || fh == STDERR)
|
||||
{
|
||||
#if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
|
||||
rt_device_t console;
|
||||
console = rt_console_get_device();
|
||||
if (console)
|
||||
{
|
||||
rt_device_write(console, -1, buf, len);
|
||||
}
|
||||
return 0; /* success */
|
||||
#else
|
||||
return 0; /* error */
|
||||
#endif /* defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE) */
|
||||
}
|
||||
else if (fh == STDIN)
|
||||
{
|
||||
return -1; /* 100% error */
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef DFS_USING_POSIX
|
||||
size = write(fh, buf, len);
|
||||
if (size >= 0)
|
||||
{
|
||||
/*
|
||||
fflush doesn't have a good solution in Keil-MDK,
|
||||
so it has to sync/flush when for each writen.
|
||||
*/
|
||||
fsync(fh);
|
||||
return len - size; /* success */
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0; /* error */
|
||||
}
|
||||
#else
|
||||
LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
|
||||
return 0; /* error */
|
||||
#endif /* DFS_USING_POSIX */
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Flush any OS buffers associated with fh, ensuring that the file
|
||||
* is up to date on disk. Result is >=0 if OK, negative for an
|
||||
* error.
|
||||
* This function is deprecated. It is never called by any other library function,
|
||||
* and you are not required to re-implement it if you are retargeting standard I/O (stdio).
|
||||
*/
|
||||
int _sys_ensure(FILEHANDLE fh)
|
||||
{
|
||||
#ifdef DFS_USING_POSIX
|
||||
return fsync(fh);
|
||||
#else
|
||||
LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
|
||||
return 0; /* error */
|
||||
#endif /* DFS_USING_POSIX */
|
||||
}
|
||||
|
||||
/*
|
||||
* Move the file position to a given offset from the file start.
|
||||
* Returns >=0 on success, <0 on failure.
|
||||
*/
|
||||
int _sys_seek(FILEHANDLE fh, long pos)
|
||||
{
|
||||
#ifdef DFS_USING_POSIX
|
||||
if (fh < STDERR)
|
||||
return 0; /* error */
|
||||
|
||||
/* position is relative to the start of file fh */
|
||||
return lseek(fh, pos, 0);
|
||||
#else
|
||||
LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
|
||||
return 0; /* error */
|
||||
#endif /* DFS_USING_POSIX */
|
||||
}
|
||||
|
||||
/**
|
||||
* used by tmpnam() or tmpfile()
|
||||
*/
|
||||
#if __ARMCC_VERSION >= 6190000
|
||||
void _sys_tmpnam(char *name, int fileno, unsigned maxlength)
|
||||
{
|
||||
rt_snprintf(name, maxlength, "tem%03d", fileno);
|
||||
}
|
||||
#else
|
||||
int _sys_tmpnam(char *name, int fileno, unsigned maxlength)
|
||||
{
|
||||
rt_snprintf(name, maxlength, "tem%03d", fileno);
|
||||
return 1;
|
||||
}
|
||||
#endif /* __ARMCC_VERSION >= 6190000 */
|
||||
|
||||
char *_sys_command_string(char *cmd, int len)
|
||||
{
|
||||
/* no support */
|
||||
return RT_NULL;
|
||||
}
|
||||
|
||||
/* This function writes a character to the console. */
|
||||
void _ttywrch(int ch)
|
||||
{
|
||||
#ifdef RT_USING_CONSOLE
|
||||
rt_kprintf("%c", (char)ch);
|
||||
#endif /* RT_USING_CONSOLE */
|
||||
}
|
||||
|
||||
/* for exit() and abort() */
|
||||
rt_weak void _sys_exit(int return_code)
|
||||
{
|
||||
extern void __rt_libc_exit(int status);
|
||||
__rt_libc_exit(return_code);
|
||||
while (1);
|
||||
}
|
||||
|
||||
/**
|
||||
* return current length of file.
|
||||
*
|
||||
* @param fh - file handle
|
||||
* @return file length, or -1 on failed
|
||||
*/
|
||||
long _sys_flen(FILEHANDLE fh)
|
||||
{
|
||||
#ifdef DFS_USING_POSIX
|
||||
struct stat stat;
|
||||
|
||||
if (fh < STDERR)
|
||||
return 0; /* error */
|
||||
|
||||
fstat(fh, &stat);
|
||||
return stat.st_size;
|
||||
#else
|
||||
LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
|
||||
return 0;
|
||||
#endif /* DFS_USING_POSIX */
|
||||
}
|
||||
|
||||
int _sys_istty(FILEHANDLE fh)
|
||||
{
|
||||
if ((STDIN <= fh) && (fh <= STDERR))
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
int remove(const char *filename)
|
||||
{
|
||||
#ifdef DFS_USING_POSIX
|
||||
return unlink(filename);
|
||||
#else
|
||||
LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
|
||||
return 0; /* error */
|
||||
#endif /* DFS_USING_POSIX */
|
||||
}
|
||||
|
||||
#ifdef __MICROLIB
|
||||
#include <stdio.h>
|
||||
|
||||
int fputc(int c, FILE *f)
|
||||
{
|
||||
#ifdef RT_USING_CONSOLE
|
||||
rt_kprintf("%c", (char)c);
|
||||
return 1;
|
||||
#else
|
||||
return 0; /* error */
|
||||
#endif /* RT_USING_CONSOLE */
|
||||
}
|
||||
|
||||
int fgetc(FILE *f)
|
||||
{
|
||||
#ifdef RT_USING_POSIX_STDIO
|
||||
char ch;
|
||||
|
||||
if (libc_stdio_get_console() < 0)
|
||||
{
|
||||
LOG_W("Do not invoke standard output before initializing Compiler");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (read(STDIN_FILENO, &ch, 1) == 1)
|
||||
return ch;
|
||||
#endif /* RT_USING_POSIX_STDIO */
|
||||
LOG_W("%s: %s", __func__, _WARNING_WITHOUT_STDIO);
|
||||
return 0; /* error */
|
||||
}
|
||||
|
||||
#endif /* __MICROLIB */
|
24
components/libc/compilers/common/SConscript
Normal file
24
components/libc/compilers/common/SConscript
Normal file
|
@ -0,0 +1,24 @@
|
|||
from building import *
|
||||
Import('rtconfig')
|
||||
|
||||
src = []
|
||||
cwd = GetCurrentDir()
|
||||
group = []
|
||||
CPPPATH = [cwd + '/include']
|
||||
CPPDEFINES = []
|
||||
|
||||
if rtconfig.PLATFORM in ['armcc', 'armclang']:
|
||||
CPPDEFINES += ['__CLK_TCK=RT_TICK_PER_SECOND']
|
||||
elif rtconfig.PLATFORM in ['iccarm']:
|
||||
CPPDEFINES += ['CLOCKS_PER_SEC=RT_TICK_PER_SECOND'] # forcly revert to 1 by IAR
|
||||
|
||||
src += Glob('*.c')
|
||||
|
||||
group = DefineGroup('Compiler', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES)
|
||||
|
||||
list = os.listdir(cwd)
|
||||
for item in list:
|
||||
if os.path.isfile(os.path.join(cwd, item, 'SConscript')):
|
||||
group = group + SConscript(os.path.join(item, 'SConscript'))
|
||||
|
||||
Return('group')
|
27
components/libc/compilers/common/cctype.c
Normal file
27
components/libc/compilers/common/cctype.c
Normal file
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2022-06-07 Meco Man The first version.
|
||||
*/
|
||||
|
||||
#include "posix/ctype.h"
|
||||
|
||||
#if !(defined(__ICCARM__) && (__VER__ > 9000000)) /* IAR9.0 has defined */
|
||||
#ifndef isascii /* some toolchain use macro to define it */
|
||||
int isascii(int c)
|
||||
{
|
||||
return c >= 0x00 && c <= 0x7f;
|
||||
}
|
||||
#endif
|
||||
#endif /* !(defined(__ICCARM__) && (__VER__ > 9000000)) */
|
||||
|
||||
#ifndef toascii
|
||||
int toascii(int c)
|
||||
{
|
||||
return (c)&0177;
|
||||
}
|
||||
#endif
|
87
components/libc/compilers/common/cstdio.c
Normal file
87
components/libc/compilers/common/cstdio.c
Normal file
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
* 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 */
|
149
components/libc/compilers/common/cstdlib.c
Normal file
149
components/libc/compilers/common/cstdlib.c
Normal file
|
@ -0,0 +1,149 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2021-02-15 Meco Man first version
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
|
||||
#define DBG_TAG "stdlib"
|
||||
#define DBG_LVL DBG_INFO
|
||||
#include <rtdbg.h>
|
||||
|
||||
void __rt_libc_exit(int status)
|
||||
{
|
||||
rt_thread_t self = rt_thread_self();
|
||||
|
||||
if (self != RT_NULL)
|
||||
{
|
||||
LOG_W("thread:%s exit:%d!", self->parent.name, status);
|
||||
#ifdef RT_USING_PTHREADS
|
||||
if(self->pthread_data != RT_NULL)
|
||||
{
|
||||
extern void pthread_exit(void *value);
|
||||
pthread_exit((void *)status);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
rt_thread_control(self, RT_THREAD_CTRL_CLOSE, RT_NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef RT_USING_MSH
|
||||
int system(const char *command)
|
||||
{
|
||||
extern int msh_exec(char *cmd, rt_size_t length);
|
||||
|
||||
if (command)
|
||||
{
|
||||
msh_exec((char *)command, rt_strlen(command));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
RTM_EXPORT(system);
|
||||
#endif /* RT_USING_MSH */
|
||||
|
||||
char *ltoa(long value, char *string, int radix)
|
||||
{
|
||||
char tmp[33];
|
||||
char *tp = tmp;
|
||||
long i;
|
||||
unsigned long v;
|
||||
int sign;
|
||||
char *sp;
|
||||
|
||||
if (string == NULL)
|
||||
{
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
if (radix > 36 || radix <= 1)
|
||||
{
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
sign = (radix == 10 && value < 0);
|
||||
if (sign)
|
||||
{
|
||||
v = -value;
|
||||
}
|
||||
else
|
||||
{
|
||||
v = (unsigned long)value;
|
||||
}
|
||||
|
||||
while (v || tp == tmp)
|
||||
{
|
||||
i = v % radix;
|
||||
v = v / radix;
|
||||
if (i < 10)
|
||||
*tp++ = (char)(i+'0');
|
||||
else
|
||||
*tp++ = (char)(i + 'a' - 10);
|
||||
}
|
||||
|
||||
sp = string;
|
||||
|
||||
if (sign)
|
||||
*sp++ = '-';
|
||||
while (tp > tmp)
|
||||
*sp++ = *--tp;
|
||||
*sp = 0;
|
||||
|
||||
return string;
|
||||
}
|
||||
|
||||
char *itoa(int value, char *string, int radix)
|
||||
{
|
||||
return ltoa(value, string, radix) ;
|
||||
}
|
||||
|
||||
|
||||
char *ultoa(unsigned long value, char *string, int radix)
|
||||
{
|
||||
char tmp[33];
|
||||
char *tp = tmp;
|
||||
long i;
|
||||
unsigned long v = value;
|
||||
char *sp;
|
||||
|
||||
if (string == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (radix > 36 || radix <= 1)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
while (v || tp == tmp)
|
||||
{
|
||||
i = v % radix;
|
||||
v = v / radix;
|
||||
if (i < 10)
|
||||
*tp++ = (char)(i+'0');
|
||||
else
|
||||
*tp++ = (char)(i + 'a' - 10);
|
||||
}
|
||||
|
||||
sp = string;
|
||||
|
||||
while (tp > tmp)
|
||||
*sp++ = *--tp;
|
||||
*sp = 0;
|
||||
|
||||
return string;
|
||||
}
|
||||
|
||||
char *utoa(unsigned value, char *string, int radix)
|
||||
{
|
||||
return ultoa(value, string, radix) ;
|
||||
}
|
225
components/libc/compilers/common/cstring.c
Normal file
225
components/libc/compilers/common/cstring.c
Normal file
|
@ -0,0 +1,225 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2022-01-12 Meco Man The first version.
|
||||
*/
|
||||
|
||||
#include "posix/string.h"
|
||||
#include <ctype.h>
|
||||
#include <rtthread.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/**
|
||||
* @brief erases the data in the n bytes of the memory starting at the
|
||||
* location pointed to by s, by writing zeros (bytes containing '\0') to that area.
|
||||
*
|
||||
* @note The bzero() function is deprecated (marked as LEGACY in POSIX. 1-2001).
|
||||
*/
|
||||
#ifndef RT_USING_PICOLIBC
|
||||
void bzero(void* s, size_t n)
|
||||
{
|
||||
rt_memset(s, 0, n);
|
||||
}
|
||||
#endif
|
||||
|
||||
void bcopy(const void* src, void* dest, size_t n)
|
||||
{
|
||||
rt_memcpy(dest, src, n);
|
||||
}
|
||||
|
||||
int bcmp(const void* s1, const void* s2, size_t n)
|
||||
{
|
||||
return rt_memcmp(s1, s2, n);
|
||||
}
|
||||
|
||||
void explicit_bzero(void* s, size_t n)
|
||||
{
|
||||
volatile char* vs = (volatile char*)s;
|
||||
while (n)
|
||||
{
|
||||
*vs++ = 0;
|
||||
n--;
|
||||
}
|
||||
}
|
||||
|
||||
char* index(const char* s, int c)
|
||||
{
|
||||
return strchr(s, c);
|
||||
}
|
||||
|
||||
char* rindex(const char* s, int c)
|
||||
{
|
||||
return strrchr(s, c);
|
||||
}
|
||||
|
||||
int ffs(int i)
|
||||
{
|
||||
int bit;
|
||||
|
||||
if (0 == i)
|
||||
return 0;
|
||||
|
||||
for (bit = 1; !(i & 1); ++bit)
|
||||
i >>= 1;
|
||||
return bit;
|
||||
}
|
||||
|
||||
int ffsl(long i)
|
||||
{
|
||||
int bit;
|
||||
|
||||
if (0 == i)
|
||||
return 0;
|
||||
|
||||
for (bit = 1; !(i & 1); ++bit)
|
||||
i >>= 1;
|
||||
return bit;
|
||||
}
|
||||
|
||||
int ffsll(long long i)
|
||||
{
|
||||
int bit;
|
||||
|
||||
if (0 == i)
|
||||
return 0;
|
||||
|
||||
for (bit = 1; !(i & 1); ++bit)
|
||||
i >>= 1;
|
||||
return bit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief The memchr() function scans the initial n bytes of the memory area pointed to
|
||||
* by s for the first instance of c. Both c and the bytes of the memory area
|
||||
* pointed to by s are interpreted as unsigned char.
|
||||
*
|
||||
* @note This function is GNU extension, available since glibc 2.1.91.
|
||||
*/
|
||||
void* memrchr(const void* ptr, int ch, size_t pos)
|
||||
{
|
||||
char* end = (char*)ptr + pos - 1;
|
||||
while (end != ptr)
|
||||
{
|
||||
if (*end == ch)
|
||||
return end;
|
||||
end--;
|
||||
}
|
||||
return (*end == ch) ? (end) : (NULL);
|
||||
}
|
||||
|
||||
size_t strnlen(const char *s, size_t maxlen)
|
||||
{
|
||||
const char *sc;
|
||||
for (sc = s; maxlen != 0 && *sc != '\0'; maxlen--, ++sc);
|
||||
return sc - s;
|
||||
}
|
||||
|
||||
char* strchrnul(const char* s, int c)
|
||||
{
|
||||
while (*s != '\0' && *s != c)
|
||||
s++;
|
||||
return (char*)s;
|
||||
}
|
||||
|
||||
int strcasecmp(const char* s1, const char* s2)
|
||||
{
|
||||
const unsigned char* u1 = (const unsigned char*)s1;
|
||||
const unsigned char* u2 = (const unsigned char*)s2;
|
||||
int result;
|
||||
|
||||
while ((result = tolower(*u1) - tolower(*u2)) == 0 && *u1 != 0)
|
||||
{
|
||||
u1++;
|
||||
u2++;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int strncasecmp(const char* s1, const char* s2, size_t n)
|
||||
{
|
||||
const unsigned char* u1 = (const unsigned char*)s1;
|
||||
const unsigned char* u2 = (const unsigned char*)s2;
|
||||
int result;
|
||||
|
||||
for (; n != 0; n--)
|
||||
{
|
||||
result = tolower(*u1) - tolower(*u2);
|
||||
if (result)
|
||||
return result;
|
||||
if (*u1 == 0)
|
||||
return 0;
|
||||
u1++;
|
||||
u2++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *strdup(const char *s)
|
||||
{
|
||||
char *news = (char *)malloc(strlen(s) + 1);
|
||||
|
||||
if (news)
|
||||
{
|
||||
strcpy(news, s);
|
||||
}
|
||||
|
||||
return news;
|
||||
}
|
||||
|
||||
char *strndup(const char *s, size_t size)
|
||||
{
|
||||
size_t nsize = strnlen(s, size);
|
||||
char *news = (char *)malloc(nsize + 1);
|
||||
if (news)
|
||||
{
|
||||
rt_memcpy(news, s, nsize);
|
||||
news[nsize] = '\0';
|
||||
}
|
||||
|
||||
return news;
|
||||
}
|
||||
|
||||
rt_weak char *strtok_r(char *str, const char *delim, char **saveptr)
|
||||
{
|
||||
char *pbegin;
|
||||
char *pend = NULL;
|
||||
|
||||
if (str)
|
||||
{
|
||||
pbegin = str;
|
||||
}
|
||||
else if (saveptr && *saveptr)
|
||||
{
|
||||
pbegin = *saveptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (;*pbegin && strchr(delim, *pbegin) != NULL; pbegin++);
|
||||
|
||||
if (!*pbegin)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (pend = pbegin + 1; *pend && strchr(delim, *pend) == NULL; pend++);
|
||||
|
||||
if (*pend)
|
||||
{
|
||||
*pend++ = '\0';
|
||||
}
|
||||
|
||||
if (saveptr)
|
||||
{
|
||||
*saveptr = pend;
|
||||
}
|
||||
|
||||
return pbegin;
|
||||
}
|
1381
components/libc/compilers/common/ctime.c
Normal file
1381
components/libc/compilers/common/ctime.c
Normal file
File diff suppressed because it is too large
Load diff
140
components/libc/compilers/common/cwchar.c
Normal file
140
components/libc/compilers/common/cwchar.c
Normal file
|
@ -0,0 +1,140 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2014-01-01 mattn implement wcwidth
|
||||
*/
|
||||
|
||||
#include "posix/wchar.h"
|
||||
#include <string.h>
|
||||
|
||||
struct interval
|
||||
{
|
||||
long first;
|
||||
long last;
|
||||
};
|
||||
|
||||
static int bisearch(wchar_t ucs, const struct interval *table, int max)
|
||||
{
|
||||
int min = 0;
|
||||
int mid;
|
||||
|
||||
if (ucs < table[0].first || ucs > table[max].last)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
while (max >= min)
|
||||
{
|
||||
mid = (min + max) / 2;
|
||||
if (ucs > table[mid].last)
|
||||
{
|
||||
min = mid + 1;
|
||||
}
|
||||
else if (ucs < table[mid].first)
|
||||
{
|
||||
max = mid - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int wcwidth(wchar_t ucs)
|
||||
{
|
||||
/* sorted list of non-overlapping intervals of non-spacing characters */
|
||||
static const struct interval combining[] = {
|
||||
{ 0x0300, 0x034E }, { 0x0360, 0x0362 }, { 0x0483, 0x0486 },
|
||||
{ 0x0488, 0x0489 }, { 0x0591, 0x05A1 }, { 0x05A3, 0x05B9 },
|
||||
{ 0x05BB, 0x05BD }, { 0x05BF, 0x05BF }, { 0x05C1, 0x05C2 },
|
||||
{ 0x05C4, 0x05C4 }, { 0x064B, 0x0655 }, { 0x0670, 0x0670 },
|
||||
{ 0x06D6, 0x06E4 }, { 0x06E7, 0x06E8 }, { 0x06EA, 0x06ED },
|
||||
{ 0x070F, 0x070F }, { 0x0711, 0x0711 }, { 0x0730, 0x074A },
|
||||
{ 0x07A6, 0x07B0 }, { 0x0901, 0x0902 }, { 0x093C, 0x093C },
|
||||
{ 0x0941, 0x0948 }, { 0x094D, 0x094D }, { 0x0951, 0x0954 },
|
||||
{ 0x0962, 0x0963 }, { 0x0981, 0x0981 }, { 0x09BC, 0x09BC },
|
||||
{ 0x09C1, 0x09C4 }, { 0x09CD, 0x09CD }, { 0x09E2, 0x09E3 },
|
||||
{ 0x0A02, 0x0A02 }, { 0x0A3C, 0x0A3C }, { 0x0A41, 0x0A42 },
|
||||
{ 0x0A47, 0x0A48 }, { 0x0A4B, 0x0A4D }, { 0x0A70, 0x0A71 },
|
||||
{ 0x0A81, 0x0A82 }, { 0x0ABC, 0x0ABC }, { 0x0AC1, 0x0AC5 },
|
||||
{ 0x0AC7, 0x0AC8 }, { 0x0ACD, 0x0ACD }, { 0x0B01, 0x0B01 },
|
||||
{ 0x0B3C, 0x0B3C }, { 0x0B3F, 0x0B3F }, { 0x0B41, 0x0B43 },
|
||||
{ 0x0B4D, 0x0B4D }, { 0x0B56, 0x0B56 }, { 0x0B82, 0x0B82 },
|
||||
{ 0x0BC0, 0x0BC0 }, { 0x0BCD, 0x0BCD }, { 0x0C3E, 0x0C40 },
|
||||
{ 0x0C46, 0x0C48 }, { 0x0C4A, 0x0C4D }, { 0x0C55, 0x0C56 },
|
||||
{ 0x0CBF, 0x0CBF }, { 0x0CC6, 0x0CC6 }, { 0x0CCC, 0x0CCD },
|
||||
{ 0x0D41, 0x0D43 }, { 0x0D4D, 0x0D4D }, { 0x0DCA, 0x0DCA },
|
||||
{ 0x0DD2, 0x0DD4 }, { 0x0DD6, 0x0DD6 }, { 0x0E31, 0x0E31 },
|
||||
{ 0x0E34, 0x0E3A }, { 0x0E47, 0x0E4E }, { 0x0EB1, 0x0EB1 },
|
||||
{ 0x0EB4, 0x0EB9 }, { 0x0EBB, 0x0EBC }, { 0x0EC8, 0x0ECD },
|
||||
{ 0x0F18, 0x0F19 }, { 0x0F35, 0x0F35 }, { 0x0F37, 0x0F37 },
|
||||
{ 0x0F39, 0x0F39 }, { 0x0F71, 0x0F7E }, { 0x0F80, 0x0F84 },
|
||||
{ 0x0F86, 0x0F87 }, { 0x0F90, 0x0F97 }, { 0x0F99, 0x0FBC },
|
||||
{ 0x0FC6, 0x0FC6 }, { 0x102D, 0x1030 }, { 0x1032, 0x1032 },
|
||||
{ 0x1036, 0x1037 }, { 0x1039, 0x1039 }, { 0x1058, 0x1059 },
|
||||
{ 0x1160, 0x11FF }, { 0x17B7, 0x17BD }, { 0x17C6, 0x17C6 },
|
||||
{ 0x17C9, 0x17D3 }, { 0x180B, 0x180E }, { 0x18A9, 0x18A9 },
|
||||
{ 0x200B, 0x200F }, { 0x202A, 0x202E }, { 0x206A, 0x206F },
|
||||
{ 0x20D0, 0x20E3 }, { 0x302A, 0x302F }, { 0x3099, 0x309A },
|
||||
{ 0xFB1E, 0xFB1E }, { 0xFE20, 0xFE23 }, { 0xFEFF, 0xFEFF },
|
||||
{ 0xFFF9, 0xFFFB }
|
||||
};
|
||||
|
||||
/* test for 8-bit control characters */
|
||||
if (ucs == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (ucs < 32 || (ucs >= 0x7f && ucs < 0xa0))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* binary search in table of non-spacing characters */
|
||||
if (bisearch(ucs, combining, sizeof(combining) / sizeof(struct interval) - 1))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1 +
|
||||
(ucs >= 0x1100 &&
|
||||
(ucs <= 0x115f || /* Hangul Jamo init. consonants */
|
||||
(ucs >= 0x2e80 && ucs <= 0xa4cf && (ucs & ~0x0011) != 0x300a &&
|
||||
ucs != 0x303f) || /* CJK ... Yi */
|
||||
(ucs >= 0xac00 && ucs <= 0xd7a3) || /* Hangul Syllables */
|
||||
(ucs >= 0xf900 && ucs <= 0xfaff) || /* CJK Compatibility Ideographs */
|
||||
(ucs >= 0xfe30 && ucs <= 0xfe6f) || /* CJK Compatibility Forms */
|
||||
(ucs >= 0xff00 && ucs <= 0xff5f) || /* Fullwidth Forms */
|
||||
(ucs >= 0xffe0 && ucs <= 0xffe6) // ||
|
||||
//#ifndef _WIN32
|
||||
// (ucs >= 0x20000 && ucs <= 0x2ffff)
|
||||
//#else
|
||||
// 0
|
||||
//#endif
|
||||
));
|
||||
}
|
||||
|
||||
int wcswidth(const wchar_t *pwcs, size_t n)
|
||||
{
|
||||
int w, width = 0;
|
||||
|
||||
for (;*pwcs && n-- > 0; pwcs++)
|
||||
{
|
||||
if ((w = wcwidth(*pwcs)) < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
width += w;
|
||||
}
|
||||
}
|
||||
return width;
|
||||
}
|
21
components/libc/compilers/common/extension/SConscript
Normal file
21
components/libc/compilers/common/extension/SConscript
Normal file
|
@ -0,0 +1,21 @@
|
|||
import os
|
||||
from building import *
|
||||
Import('rtconfig')
|
||||
|
||||
src = []
|
||||
cwd = GetCurrentDir()
|
||||
CPPPATH = [cwd]
|
||||
group = []
|
||||
|
||||
src += Glob('*.c')
|
||||
|
||||
if rtconfig.PLATFORM not in ['gcc', 'llvm-arm']:
|
||||
group = DefineGroup('Compiler', 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')
|
|
@ -0,0 +1,4 @@
|
|||
Because of the history issue, flags in fcntl.h, such as O_CREAT, have difference types of value. Some OS use hex flags and others use octal flags.
|
||||
|
||||
In terms of RT-Thread, Keil, IAR and MSVC use octal flags, which is located in the `tcntl/octal` folder; newlib uses hex flags; musl uses octal flags.
|
||||
|
15
components/libc/compilers/common/extension/fcntl/SConscript
Normal file
15
components/libc/compilers/common/extension/fcntl/SConscript
Normal file
|
@ -0,0 +1,15 @@
|
|||
# RT-Thread building script for bridge
|
||||
|
||||
import os
|
||||
from building import *
|
||||
|
||||
cwd = GetCurrentDir()
|
||||
objs = []
|
||||
list = os.listdir(cwd)
|
||||
|
||||
for d in list:
|
||||
path = os.path.join(cwd, d)
|
||||
if os.path.isfile(os.path.join(path, 'SConscript')):
|
||||
objs = objs + SConscript(os.path.join(d, 'SConscript'))
|
||||
|
||||
Return('objs')
|
|
@ -0,0 +1,11 @@
|
|||
from building import *
|
||||
Import('rtconfig')
|
||||
|
||||
src = []
|
||||
cwd = GetCurrentDir()
|
||||
CPPPATH = [cwd]
|
||||
group = []
|
||||
|
||||
if rtconfig.CROSS_TOOL == 'msvc':
|
||||
group = DefineGroup('Compiler', src, depend = [''], CPPPATH = CPPPATH)
|
||||
Return('group')
|
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2022-09-02 Meco Man First version
|
||||
*/
|
||||
|
||||
#ifndef __FCNTL_H__
|
||||
#define __FCNTL_H__
|
||||
|
||||
#include "sys/types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* VS fcntl.h interent */
|
||||
#define O_RDONLY 0x0000 /* open for reading only */
|
||||
#define O_WRONLY 0x0001 /* open for writing only */
|
||||
#define O_RDWR 0x0002 /* open for reading and writing */
|
||||
#define O_APPEND 0x0008 /* writes done at eof */
|
||||
|
||||
#define O_CREAT 0x0100 /* create and open file */
|
||||
#define O_TRUNC 0x0200 /* open and truncate */
|
||||
#define O_EXCL 0x0400 /* open only if file doesn't already exist */
|
||||
|
||||
// O_TEXT files have <cr><lf> sequences translated to <lf> on read()'s and <lf>
|
||||
// sequences translated to <cr><lf> on write()'s
|
||||
#define O_TEXT 0x4000 /* file mode is text (translated) */
|
||||
|
||||
#define O_BINARY 0x8000 /* file mode is binary (untranslated) */
|
||||
#define O_RAW O_BINARY
|
||||
#define O_TEMPORARY 0x0040 /* temporary file bit (file is deleted when last handle is closed) */
|
||||
#define O_NOINHERIT 0x0080 /* child process doesn't inherit file */
|
||||
#define O_SEQUENTIAL 0x0020 /* file access is primarily sequential */
|
||||
#define O_RANDOM 0x0010 /* file access is primarily random */
|
||||
|
||||
/* extension */
|
||||
#define O_ACCMODE 0x0003 /* mask for above modes, from 4.4BSD https://minnie.tuhs.org/cgi-bin/utree.pl?file=4.4BSD/usr/include/sys/fcntl.h */
|
||||
#define O_NONBLOCK 0x0004 /* non blocking I/O, from BSD apple https://opensource.apple.com/source/xnu/xnu-1228.0.2/bsd/sys/fcntl.h */
|
||||
#define O_DIRECTORY 0x200000 /* from Newlib */
|
||||
|
||||
#define F_DUPFD 0
|
||||
#define F_GETFD 1
|
||||
#define F_SETFD 2
|
||||
#define F_GETFL 3
|
||||
#define F_SETFL 4
|
||||
|
||||
#define F_SETOWN 8
|
||||
#define F_GETOWN 9
|
||||
#define F_SETSIG 10
|
||||
#define F_GETSIG 11
|
||||
|
||||
#define F_GETLK 12
|
||||
#define F_SETLK 13
|
||||
#define F_SETLKW 14
|
||||
|
||||
#define F_SETOWN_EX 15
|
||||
#define F_GETOWN_EX 16
|
||||
|
||||
#define F_GETOWNER_UIDS 17
|
||||
|
||||
int open(const char *file, int flags, ...);
|
||||
int fcntl(int fildes, int cmd, ...);
|
||||
int creat(const char *path, mode_t mode);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,11 @@
|
|||
from building import *
|
||||
Import('rtconfig')
|
||||
|
||||
src = []
|
||||
cwd = GetCurrentDir()
|
||||
CPPPATH = [cwd]
|
||||
group = []
|
||||
|
||||
if rtconfig.PLATFORM in ['armcc', 'armclang', 'iccarm']:
|
||||
group = DefineGroup('Compiler', src, depend = [''], CPPPATH = CPPPATH)
|
||||
Return('group')
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2021-09-02 Meco Man First version
|
||||
*/
|
||||
|
||||
#ifndef __FCNTL_H__
|
||||
#define __FCNTL_H__
|
||||
|
||||
#include "sys/types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define O_RDONLY 00
|
||||
#define O_WRONLY 01
|
||||
#define O_RDWR 02
|
||||
|
||||
#define O_CREAT 0100
|
||||
#define O_EXCL 0200
|
||||
#define O_NOCTTY 0400
|
||||
#define O_TRUNC 01000
|
||||
#define O_APPEND 02000
|
||||
#define O_NONBLOCK 04000
|
||||
#define O_DSYNC 010000
|
||||
#define O_SYNC 04010000
|
||||
#define O_RSYNC 04010000
|
||||
#define O_BINARY 0100000
|
||||
#define O_DIRECTORY 0200000
|
||||
#define O_NOFOLLOW 0400000
|
||||
#define O_CLOEXEC 02000000
|
||||
|
||||
#define O_ASYNC 020000
|
||||
#define O_DIRECT 040000
|
||||
#define O_LARGEFILE 0100000
|
||||
#define O_NOATIME 01000000
|
||||
#define O_PATH 010000000
|
||||
#define O_TMPFILE 020200000
|
||||
#define O_NDELAY O_NONBLOCK
|
||||
|
||||
#define O_SEARCH O_PATH
|
||||
#define O_EXEC O_PATH
|
||||
|
||||
#define O_ACCMODE (03|O_SEARCH)
|
||||
|
||||
#define F_DUPFD 0
|
||||
#define F_GETFD 1
|
||||
#define F_SETFD 2
|
||||
#define F_GETFL 3
|
||||
#define F_SETFL 4
|
||||
|
||||
#define F_SETOWN 8
|
||||
#define F_GETOWN 9
|
||||
#define F_SETSIG 10
|
||||
#define F_GETSIG 11
|
||||
|
||||
#define F_GETLK 12
|
||||
#define F_SETLK 13
|
||||
#define F_SETLKW 14
|
||||
|
||||
#define F_SETOWN_EX 15
|
||||
#define F_GETOWN_EX 16
|
||||
|
||||
#define F_GETOWNER_UIDS 17
|
||||
|
||||
int open(const char *file, int flags, ...);
|
||||
int fcntl(int fildes, int cmd, ...);
|
||||
int creat(const char *path, mode_t mode);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
4
components/libc/compilers/common/extension/readme.md
Normal file
4
components/libc/compilers/common/extension/readme.md
Normal file
|
@ -0,0 +1,4 @@
|
|||
## Attentions
|
||||
|
||||
This folder is "common" for toolchains, which only support ISO C, as an extension part, such as Keil-MDK and IAR.
|
||||
|
585
components/libc/compilers/common/extension/sys/errno.h
Normal file
585
components/libc/compilers/common/extension/sys/errno.h
Normal file
|
@ -0,0 +1,585 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2021-05-22 Meco Man The first version.
|
||||
*/
|
||||
|
||||
#ifndef __SYS_ERRNO_H__
|
||||
#define __SYS_ERRNO_H__
|
||||
|
||||
#if defined(__ARMCC_VERSION)
|
||||
/*
|
||||
defined in armcc/errno.h
|
||||
|
||||
#define EDOM 1
|
||||
#define ERANGE 2
|
||||
#define EILSEQ 4
|
||||
#define ESIGNUM 3
|
||||
#define EINVAL 5
|
||||
#define ENOMEM 6
|
||||
*/
|
||||
|
||||
#define ERROR_BASE_NO 7
|
||||
|
||||
#elif defined(__IAR_SYSTEMS_ICC__)
|
||||
/* defined in iar/errno.h
|
||||
#define EDOM 33
|
||||
#define ERANGE 34
|
||||
#define EFPOS 35
|
||||
#define EILSEQ 36
|
||||
*/
|
||||
#define ERROR_BASE_NO 36
|
||||
|
||||
#else
|
||||
#define ERROR_BASE_NO 0
|
||||
#endif
|
||||
|
||||
#if defined(__ARMCC_VERSION) || defined(__IAR_SYSTEMS_ICC__)
|
||||
#include <errno.h>
|
||||
|
||||
#ifndef EPERM
|
||||
#define EPERM (ERROR_BASE_NO + 1)
|
||||
#endif
|
||||
|
||||
#ifndef ENOENT
|
||||
#define ENOENT (ERROR_BASE_NO + 2)
|
||||
#endif
|
||||
|
||||
#ifndef ESRCH
|
||||
#define ESRCH (ERROR_BASE_NO + 3)
|
||||
#endif
|
||||
|
||||
#ifndef EINTR
|
||||
#define EINTR (ERROR_BASE_NO + 4)
|
||||
#endif
|
||||
|
||||
#ifndef EIO
|
||||
#define EIO (ERROR_BASE_NO + 5)
|
||||
#endif
|
||||
|
||||
#ifndef ENXIO
|
||||
#define ENXIO (ERROR_BASE_NO + 6)
|
||||
#endif
|
||||
|
||||
#ifndef E2BIG
|
||||
#define E2BIG (ERROR_BASE_NO + 7)
|
||||
#endif
|
||||
|
||||
#ifndef ENOEXEC
|
||||
#define ENOEXEC (ERROR_BASE_NO + 8)
|
||||
#endif
|
||||
|
||||
#ifndef EBADF
|
||||
#define EBADF (ERROR_BASE_NO + 9)
|
||||
#endif
|
||||
|
||||
#ifndef ECHILD
|
||||
#define ECHILD (ERROR_BASE_NO + 10)
|
||||
#endif
|
||||
|
||||
#ifndef EAGAIN
|
||||
#define EAGAIN (ERROR_BASE_NO + 11)
|
||||
#endif
|
||||
|
||||
#ifndef ENOMEM
|
||||
#define ENOMEM (ERROR_BASE_NO + 12)
|
||||
#endif
|
||||
|
||||
#ifndef EACCES
|
||||
#define EACCES (ERROR_BASE_NO + 13)
|
||||
#endif
|
||||
|
||||
#ifndef EFAULT
|
||||
#define EFAULT (ERROR_BASE_NO + 14)
|
||||
#endif
|
||||
|
||||
#ifndef ENOTBLK
|
||||
#define ENOTBLK (ERROR_BASE_NO + 15)
|
||||
#endif
|
||||
|
||||
#ifndef EBUSY
|
||||
#define EBUSY (ERROR_BASE_NO + 16)
|
||||
#endif
|
||||
|
||||
#ifndef EEXIST
|
||||
#define EEXIST (ERROR_BASE_NO + 17)
|
||||
#endif
|
||||
|
||||
#ifndef EXDEV
|
||||
#define EXDEV (ERROR_BASE_NO + 18)
|
||||
#endif
|
||||
|
||||
#ifndef ENODEV
|
||||
#define ENODEV (ERROR_BASE_NO + 19)
|
||||
#endif
|
||||
|
||||
#ifndef ENOTDIR
|
||||
#define ENOTDIR (ERROR_BASE_NO + 20)
|
||||
#endif
|
||||
|
||||
#ifndef EISDIR
|
||||
#define EISDIR (ERROR_BASE_NO + 21)
|
||||
#endif
|
||||
|
||||
#ifndef EINVAL
|
||||
#define EINVAL (ERROR_BASE_NO + 22)
|
||||
#endif
|
||||
|
||||
#ifndef ENFILE
|
||||
#define ENFILE (ERROR_BASE_NO + 23)
|
||||
#endif
|
||||
|
||||
#ifndef EMFILE
|
||||
#define EMFILE (ERROR_BASE_NO + 24)
|
||||
#endif
|
||||
|
||||
#ifndef ENOTTY
|
||||
#define ENOTTY (ERROR_BASE_NO + 25)
|
||||
#endif
|
||||
|
||||
#ifndef ETXTBSY
|
||||
#define ETXTBSY (ERROR_BASE_NO + 26)
|
||||
#endif
|
||||
|
||||
#ifndef EFBIG
|
||||
#define EFBIG (ERROR_BASE_NO + 27)
|
||||
#endif
|
||||
|
||||
#ifndef ENOSPC
|
||||
#define ENOSPC (ERROR_BASE_NO + 28)
|
||||
#endif
|
||||
|
||||
#ifndef ESPIPE
|
||||
#define ESPIPE (ERROR_BASE_NO + 29)
|
||||
#endif
|
||||
|
||||
#ifndef EROFS
|
||||
#define EROFS (ERROR_BASE_NO + 30)
|
||||
#endif
|
||||
|
||||
#ifndef EMLINK
|
||||
#define EMLINK (ERROR_BASE_NO + 31)
|
||||
#endif
|
||||
|
||||
#ifndef EPIPE
|
||||
#define EPIPE (ERROR_BASE_NO + 32)
|
||||
#endif
|
||||
|
||||
#ifndef EDOM
|
||||
#define EDOM (ERROR_BASE_NO + 33)
|
||||
#endif
|
||||
|
||||
#ifndef ERANGE
|
||||
#define ERANGE (ERROR_BASE_NO + 34)
|
||||
#endif
|
||||
|
||||
#ifndef EDEADLK
|
||||
#define EDEADLK (ERROR_BASE_NO + 35)
|
||||
#endif
|
||||
|
||||
#ifndef ENAMETOOLONG
|
||||
#define ENAMETOOLONG (ERROR_BASE_NO + 36)
|
||||
#endif
|
||||
|
||||
#ifndef ENOLCK
|
||||
#define ENOLCK (ERROR_BASE_NO + 37)
|
||||
#endif
|
||||
|
||||
#ifndef ENOSYS
|
||||
#define ENOSYS (ERROR_BASE_NO + 38)
|
||||
#endif
|
||||
|
||||
#ifndef ENOTEMPTY
|
||||
#define ENOTEMPTY (ERROR_BASE_NO + 39)
|
||||
#endif
|
||||
|
||||
#ifndef ELOOP
|
||||
#define ELOOP (ERROR_BASE_NO + 40)
|
||||
#endif
|
||||
|
||||
#ifndef EWOULDBLOCK
|
||||
#define EWOULDBLOCK EAGAIN
|
||||
#endif
|
||||
|
||||
#ifndef ENOMSG
|
||||
#define ENOMSG (ERROR_BASE_NO + 42)
|
||||
#endif
|
||||
|
||||
#ifndef EIDRM
|
||||
#define EIDRM (ERROR_BASE_NO + 43)
|
||||
#endif
|
||||
|
||||
#ifndef ECHRNG
|
||||
#define ECHRNG (ERROR_BASE_NO + 44)
|
||||
#endif
|
||||
|
||||
#ifndef EL2NSYNC
|
||||
#define EL2NSYNC (ERROR_BASE_NO + 45)
|
||||
#endif
|
||||
|
||||
#ifndef EL3HLT
|
||||
#define EL3HLT (ERROR_BASE_NO + 46)
|
||||
#endif
|
||||
|
||||
#ifndef EL3RST
|
||||
#define EL3RST (ERROR_BASE_NO + 47)
|
||||
#endif
|
||||
|
||||
#ifndef ELNRNG
|
||||
#define ELNRNG (ERROR_BASE_NO + 48)
|
||||
#endif
|
||||
|
||||
#ifndef EUNATCH
|
||||
#define EUNATCH (ERROR_BASE_NO + 49)
|
||||
#endif
|
||||
|
||||
#ifndef ENOCSI
|
||||
#define ENOCSI (ERROR_BASE_NO + 50)
|
||||
#endif
|
||||
|
||||
#ifndef EL2HLT
|
||||
#define EL2HLT (ERROR_BASE_NO + 51)
|
||||
#endif
|
||||
|
||||
#ifndef EBADE
|
||||
#define EBADE (ERROR_BASE_NO + 52)
|
||||
#endif
|
||||
|
||||
#ifndef EBADR
|
||||
#define EBADR (ERROR_BASE_NO + 53)
|
||||
#endif
|
||||
|
||||
#ifndef EXFULL
|
||||
#define EXFULL (ERROR_BASE_NO + 54)
|
||||
#endif
|
||||
|
||||
#ifndef ENOANO
|
||||
#define ENOANO (ERROR_BASE_NO + 55)
|
||||
#endif
|
||||
|
||||
#ifndef EBADRQC
|
||||
#define EBADRQC (ERROR_BASE_NO + 56)
|
||||
#endif
|
||||
|
||||
#ifndef EBADSLT
|
||||
#define EBADSLT (ERROR_BASE_NO + 57)
|
||||
#endif
|
||||
|
||||
#ifndef EDEADLOCK
|
||||
#define EDEADLOCK EDEADLK
|
||||
#endif
|
||||
|
||||
#ifndef EBFONT
|
||||
#define EBFONT (ERROR_BASE_NO + 59)
|
||||
#endif
|
||||
|
||||
#ifndef ENOSTR
|
||||
#define ENOSTR (ERROR_BASE_NO + 60)
|
||||
#endif
|
||||
|
||||
#ifndef ENODATA
|
||||
#define ENODATA (ERROR_BASE_NO + 61)
|
||||
#endif
|
||||
|
||||
#ifndef ETIME
|
||||
#define ETIME (ERROR_BASE_NO + 62)
|
||||
#endif
|
||||
|
||||
#ifndef ENOSR
|
||||
#define ENOSR (ERROR_BASE_NO + 63)
|
||||
#endif
|
||||
|
||||
#ifndef ENONET
|
||||
#define ENONET (ERROR_BASE_NO + 64)
|
||||
#endif
|
||||
|
||||
#ifndef ENOPKG
|
||||
#define ENOPKG (ERROR_BASE_NO + 65)
|
||||
#endif
|
||||
|
||||
#ifndef EREMOTE
|
||||
#define EREMOTE (ERROR_BASE_NO + 66)
|
||||
#endif
|
||||
|
||||
#ifndef ENOLINK
|
||||
#define ENOLINK (ERROR_BASE_NO + 67)
|
||||
#endif
|
||||
|
||||
#ifndef EADV
|
||||
#define EADV (ERROR_BASE_NO + 68)
|
||||
#endif
|
||||
|
||||
#ifndef ESRMNT
|
||||
#define ESRMNT (ERROR_BASE_NO + 69)
|
||||
#endif
|
||||
|
||||
#ifndef ECOMM
|
||||
#define ECOMM (ERROR_BASE_NO + 70)
|
||||
#endif
|
||||
|
||||
#ifndef EPROTO
|
||||
#define EPROTO (ERROR_BASE_NO + 71)
|
||||
#endif
|
||||
|
||||
#ifndef EMULTIHOP
|
||||
#define EMULTIHOP (ERROR_BASE_NO + 72)
|
||||
#endif
|
||||
|
||||
#ifndef EDOTDOT
|
||||
#define EDOTDOT (ERROR_BASE_NO + 73)
|
||||
#endif
|
||||
|
||||
#ifndef EBADMSG
|
||||
#define EBADMSG (ERROR_BASE_NO + 74)
|
||||
#endif
|
||||
|
||||
#ifndef EOVERFLOW
|
||||
#define EOVERFLOW (ERROR_BASE_NO + 75)
|
||||
#endif
|
||||
|
||||
#ifndef ENOTUNIQ
|
||||
#define ENOTUNIQ (ERROR_BASE_NO + 76)
|
||||
#endif
|
||||
|
||||
#ifndef EBADFD
|
||||
#define EBADFD (ERROR_BASE_NO + 77)
|
||||
#endif
|
||||
|
||||
#ifndef EREMCHG
|
||||
#define EREMCHG (ERROR_BASE_NO + 78)
|
||||
#endif
|
||||
|
||||
#ifndef ELIBACC
|
||||
#define ELIBACC (ERROR_BASE_NO + 79)
|
||||
#endif
|
||||
|
||||
#ifndef ELIBBAD
|
||||
#define ELIBBAD (ERROR_BASE_NO + 80)
|
||||
#endif
|
||||
|
||||
#ifndef ELIBSCN
|
||||
#define ELIBSCN (ERROR_BASE_NO + 81)
|
||||
#endif
|
||||
|
||||
#ifndef ELIBMAX
|
||||
#define ELIBMAX (ERROR_BASE_NO + 82)
|
||||
#endif
|
||||
|
||||
#ifndef ELIBEXEC
|
||||
#define ELIBEXEC (ERROR_BASE_NO + 83)
|
||||
#endif
|
||||
|
||||
#ifndef EILSEQ
|
||||
#define EILSEQ (ERROR_BASE_NO + 84)
|
||||
#endif
|
||||
|
||||
#ifndef ERESTART
|
||||
#define ERESTART (ERROR_BASE_NO + 85)
|
||||
#endif
|
||||
|
||||
#ifndef ESTRPIPE
|
||||
#define ESTRPIPE (ERROR_BASE_NO + 86)
|
||||
#endif
|
||||
|
||||
#ifndef EUSERS
|
||||
#define EUSERS (ERROR_BASE_NO + 87)
|
||||
#endif
|
||||
|
||||
#ifndef ENOTSOCK
|
||||
#define ENOTSOCK (ERROR_BASE_NO + 88)
|
||||
#endif
|
||||
|
||||
#ifndef EDESTADDRREQ
|
||||
#define EDESTADDRREQ (ERROR_BASE_NO + 89)
|
||||
#endif
|
||||
|
||||
#ifndef EMSGSIZE
|
||||
#define EMSGSIZE (ERROR_BASE_NO + 90)
|
||||
#endif
|
||||
|
||||
#ifndef EPROTOTYPE
|
||||
#define EPROTOTYPE (ERROR_BASE_NO + 91)
|
||||
#endif
|
||||
|
||||
#ifndef ENOPROTOOPT
|
||||
#define ENOPROTOOPT (ERROR_BASE_NO + 92)
|
||||
#endif
|
||||
|
||||
#ifndef EPROTONOSUPPORT
|
||||
#define EPROTONOSUPPORT (ERROR_BASE_NO + 93)
|
||||
#endif
|
||||
|
||||
#ifndef ESOCKTNOSUPPORT
|
||||
#define ESOCKTNOSUPPORT (ERROR_BASE_NO + 94)
|
||||
#endif
|
||||
|
||||
#ifndef EOPNOTSUPP
|
||||
#define EOPNOTSUPP (ERROR_BASE_NO + 95)
|
||||
#endif
|
||||
|
||||
#ifndef ENOTSUP
|
||||
#define ENOTSUP EOPNOTSUPP
|
||||
#endif
|
||||
|
||||
#ifndef EPFNOSUPPORT
|
||||
#define EPFNOSUPPORT (ERROR_BASE_NO + 96)
|
||||
#endif
|
||||
|
||||
#ifndef EAFNOSUPPORT
|
||||
#define EAFNOSUPPORT (ERROR_BASE_NO + 97)
|
||||
#endif
|
||||
|
||||
#ifndef EADDRINUSE
|
||||
#define EADDRINUSE (ERROR_BASE_NO + 98)
|
||||
#endif
|
||||
|
||||
#ifndef EADDRNOTAVAIL
|
||||
#define EADDRNOTAVAIL (ERROR_BASE_NO + 99)
|
||||
#endif
|
||||
|
||||
#ifndef ENETDOWN
|
||||
#define ENETDOWN (ERROR_BASE_NO + 100)
|
||||
#endif
|
||||
|
||||
#ifndef ENETUNREACH
|
||||
#define ENETUNREACH (ERROR_BASE_NO + 101)
|
||||
#endif
|
||||
|
||||
#ifndef ENETRESET
|
||||
#define ENETRESET (ERROR_BASE_NO + 102)
|
||||
#endif
|
||||
|
||||
#ifndef ECONNABORTED
|
||||
#define ECONNABORTED (ERROR_BASE_NO + 103)
|
||||
#endif
|
||||
|
||||
#ifndef ECONNRESET
|
||||
#define ECONNRESET (ERROR_BASE_NO + 104)
|
||||
#endif
|
||||
|
||||
#ifndef ENOBUFS
|
||||
#define ENOBUFS (ERROR_BASE_NO + 105)
|
||||
#endif
|
||||
|
||||
#ifndef EISCONN
|
||||
#define EISCONN (ERROR_BASE_NO + 106)
|
||||
#endif
|
||||
|
||||
#ifndef ENOTCONN
|
||||
#define ENOTCONN (ERROR_BASE_NO + 107)
|
||||
#endif
|
||||
|
||||
#ifndef ESHUTDOWN
|
||||
#define ESHUTDOWN (ERROR_BASE_NO + 108)
|
||||
#endif
|
||||
|
||||
#ifndef ETOOMANYREFS
|
||||
#define ETOOMANYREFS (ERROR_BASE_NO + 109)
|
||||
#endif
|
||||
|
||||
#ifndef ETIMEDOUT
|
||||
#define ETIMEDOUT (ERROR_BASE_NO + 110)
|
||||
#endif
|
||||
|
||||
#ifndef ECONNREFUSED
|
||||
#define ECONNREFUSED (ERROR_BASE_NO + 111)
|
||||
#endif
|
||||
|
||||
#ifndef EHOSTDOWN
|
||||
#define EHOSTDOWN (ERROR_BASE_NO + 112)
|
||||
#endif
|
||||
|
||||
#ifndef EHOSTUNREACH
|
||||
#define EHOSTUNREACH (ERROR_BASE_NO + 113)
|
||||
#endif
|
||||
|
||||
#ifndef EALREADY
|
||||
#define EALREADY (ERROR_BASE_NO + 114)
|
||||
#endif
|
||||
|
||||
#ifndef EINPROGRESS
|
||||
#define EINPROGRESS (ERROR_BASE_NO + 115)
|
||||
#endif
|
||||
|
||||
#ifndef ESTALE
|
||||
#define ESTALE (ERROR_BASE_NO + 116)
|
||||
#endif
|
||||
|
||||
#ifndef EUCLEAN
|
||||
#define EUCLEAN (ERROR_BASE_NO + 117)
|
||||
#endif
|
||||
|
||||
#ifndef ENOTNAM
|
||||
#define ENOTNAM (ERROR_BASE_NO + 118)
|
||||
#endif
|
||||
|
||||
#ifndef ENAVAIL
|
||||
#define ENAVAIL (ERROR_BASE_NO + 119)
|
||||
#endif
|
||||
|
||||
#ifndef EISNAM
|
||||
#define EISNAM (ERROR_BASE_NO + 120)
|
||||
#endif
|
||||
|
||||
#ifndef EREMOTEIO
|
||||
#define EREMOTEIO (ERROR_BASE_NO + 121)
|
||||
#endif
|
||||
|
||||
#ifndef EDQUOT
|
||||
#define EDQUOT (ERROR_BASE_NO + 122)
|
||||
#endif
|
||||
|
||||
#ifndef ENOMEDIUM
|
||||
#define ENOMEDIUM (ERROR_BASE_NO + 123)
|
||||
#endif
|
||||
|
||||
#ifndef EMEDIUMTYPE
|
||||
#define EMEDIUMTYPE (ERROR_BASE_NO + 124)
|
||||
#endif
|
||||
|
||||
#ifndef ECANCELED
|
||||
#define ECANCELED (ERROR_BASE_NO + 125)
|
||||
#endif
|
||||
|
||||
#ifndef ENOKEY
|
||||
#define ENOKEY (ERROR_BASE_NO + 126)
|
||||
#endif
|
||||
|
||||
#ifndef EKEYEXPIRED
|
||||
#define EKEYEXPIRED (ERROR_BASE_NO + 127)
|
||||
#endif
|
||||
|
||||
#ifndef EKEYREVOKED
|
||||
#define EKEYREVOKED (ERROR_BASE_NO + 128)
|
||||
#endif
|
||||
|
||||
#ifndef EKEYREJECTED
|
||||
#define EKEYREJECTED (ERROR_BASE_NO + 129)
|
||||
#endif
|
||||
|
||||
#ifndef EOWNERDEAD
|
||||
#define EOWNERDEAD (ERROR_BASE_NO + 130)
|
||||
#endif
|
||||
|
||||
#ifndef ENOTRECOVERABLE
|
||||
#define ENOTRECOVERABLE (ERROR_BASE_NO + 131)
|
||||
#endif
|
||||
|
||||
#ifndef ERFKILL
|
||||
#define ERFKILL (ERROR_BASE_NO + 132)
|
||||
#endif
|
||||
|
||||
#ifndef EHWPOISON
|
||||
#define EHWPOISON (ERROR_BASE_NO + 133)
|
||||
#endif
|
||||
|
||||
#elif defined(_WIN32)
|
||||
#include <errno.h>
|
||||
|
||||
#endif /* defined(__ARMCC_VERSION) || defined(__IAR_SYSTEMS_ICC__) */
|
||||
|
||||
#endif /* __SYS_ERRNO_H__ */
|
91
components/libc/compilers/common/extension/sys/stat.h
Normal file
91
components/libc/compilers/common/extension/sys/stat.h
Normal file
|
@ -0,0 +1,91 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2021-09-02 Meco Man First version
|
||||
*/
|
||||
|
||||
#ifndef __SYS_STAT_H__
|
||||
#define __SYS_STAT_H__
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define S_IFMT 00170000
|
||||
#define S_IFSOCK 0140000
|
||||
#define S_IFLNK 0120000
|
||||
#define S_IFREG 0100000
|
||||
#define S_IFBLK 0060000
|
||||
#define S_IFDIR 0040000
|
||||
#define S_IFCHR 0020000
|
||||
#define S_IFIFO 0010000
|
||||
#define S_ISUID 0004000
|
||||
#define S_ISGID 0002000
|
||||
#define S_ISVTX 0001000
|
||||
|
||||
#define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
|
||||
#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
|
||||
#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
|
||||
#define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
|
||||
#define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
|
||||
#define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
|
||||
#define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
|
||||
|
||||
#define S_IRWXU 00700
|
||||
#define S_IRUSR 00400
|
||||
#define S_IWUSR 00200
|
||||
#define S_IXUSR 00100
|
||||
|
||||
#define S_IRWXG 00070
|
||||
#define S_IRGRP 00040
|
||||
#define S_IWGRP 00020
|
||||
#define S_IXGRP 00010
|
||||
|
||||
#define S_IRWXO 00007
|
||||
#define S_IROTH 00004
|
||||
#define S_IWOTH 00002
|
||||
#define S_IXOTH 00001
|
||||
|
||||
struct stat
|
||||
{
|
||||
struct rt_device *st_dev;
|
||||
uint16_t st_ino;
|
||||
uint16_t st_mode;
|
||||
uint16_t st_nlink;
|
||||
uint16_t st_uid;
|
||||
uint16_t st_gid;
|
||||
struct rt_device *st_rdev;
|
||||
uint32_t st_size;
|
||||
time_t st_atime;
|
||||
long st_spare1;
|
||||
time_t st_mtime;
|
||||
long st_spare2;
|
||||
time_t st_ctime;
|
||||
long st_spare3;
|
||||
uint32_t st_blksize;
|
||||
uint32_t st_blocks;
|
||||
long st_spare4[2];
|
||||
};
|
||||
|
||||
int chmod(const char *, mode_t);
|
||||
int fchmod(int, mode_t);
|
||||
int fstat(int, struct stat *);
|
||||
int lstat(const char *, struct stat *);
|
||||
int mkdir(const char *, mode_t);
|
||||
int mkfifo(const char *, mode_t);
|
||||
int mknod(const char *, mode_t, dev_t);
|
||||
int stat(const char *, struct stat *);
|
||||
mode_t umask(mode_t);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
46
components/libc/compilers/common/extension/sys/types.h
Normal file
46
components/libc/compilers/common/extension/sys/types.h
Normal file
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2020-09-05 Meco Man fix bugs
|
||||
* 2020-12-16 Meco Man add useconds_t
|
||||
*/
|
||||
|
||||
#ifndef __SYS_TYPES_H__
|
||||
#define __SYS_TYPES_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <time.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef int32_t clockid_t;
|
||||
typedef int32_t key_t; /* Used for interprocess communication. */
|
||||
typedef int pid_t; /* Used for process IDs and process group IDs. */
|
||||
typedef unsigned short uid_t;
|
||||
typedef unsigned short gid_t;
|
||||
typedef signed long off_t;
|
||||
typedef int mode_t;
|
||||
typedef signed long ssize_t; /* Used for a count of bytes or an error indication. */
|
||||
typedef unsigned long __timer_t;
|
||||
typedef __timer_t timer_t;
|
||||
typedef long suseconds_t; /* microseconds. */
|
||||
typedef unsigned long useconds_t; /* microseconds (unsigned) */
|
||||
|
||||
typedef unsigned long dev_t;
|
||||
|
||||
typedef unsigned int u_int;
|
||||
typedef unsigned char u_char;
|
||||
typedef unsigned long u_long;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
17
components/libc/compilers/common/include/compiler_private.h
Normal file
17
components/libc/compilers/common/include/compiler_private.h
Normal file
|
@ -0,0 +1,17 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2021-12-26 Meco Man First Version
|
||||
*/
|
||||
|
||||
#ifndef __COMPILER_PRIVATE_H__
|
||||
#define __COMPILER_PRIVATE_H__
|
||||
|
||||
#define _WARNING_WITHOUT_FS "Please enable RT_USING_POSIX_FS"
|
||||
#define _WARNING_WITHOUT_STDIO "Please enable RT_USING_POSIX_FS and RT_USING_POSIX_STDIO"
|
||||
|
||||
#endif /* __COMPILER_PRIVATE_H__ */
|
71
components/libc/compilers/common/include/dirent.h
Normal file
71
components/libc/compilers/common/include/dirent.h
Normal file
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
*/
|
||||
|
||||
#ifndef __DIRENT_H__
|
||||
#define __DIRENT_H__
|
||||
|
||||
#include <rtdef.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* 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
|
||||
|
||||
#ifndef HAVE_DIR_STRUCTURE
|
||||
#define HAVE_DIR_STRUCTURE
|
||||
typedef struct
|
||||
{
|
||||
int fd; /* directory file */
|
||||
char buf[512];
|
||||
int num;
|
||||
int cur;
|
||||
}DIR;
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_DIRENT_STRUCTURE
|
||||
#define HAVE_DIRENT_STRUCTURE
|
||||
|
||||
#define DIRENT_NAME_MAX 256
|
||||
|
||||
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[DIRENT_NAME_MAX]; /* 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
|
34
components/libc/compilers/common/include/posix/ctype.h
Normal file
34
components/libc/compilers/common/include/posix/ctype.h
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
|
||||
* 2022-06-07 Meco Man The first version.
|
||||
*/
|
||||
|
||||
#ifndef __POSIX_CTYPE_H__
|
||||
#define __POSIX_CTYPE_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
#if !(defined(__ICCARM__) && (__VER__ > 9000000)) /* IAR9.0 has defined */
|
||||
#ifndef isascii /* some toolchain use macro to define it */
|
||||
int isascii(int c);
|
||||
#endif
|
||||
#endif /* !(defined(__ICCARM__) && (__VER__ > 9000000)) */
|
||||
|
||||
#ifndef toascii
|
||||
int toascii(int c);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __POSIX_CTYPE_H__ */
|
30
components/libc/compilers/common/include/posix/stdio.h
Normal file
30
components/libc/compilers/common/include/posix/stdio.h
Normal file
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* 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__ */
|
32
components/libc/compilers/common/include/posix/stdlib.h
Normal file
32
components/libc/compilers/common/include/posix/stdlib.h
Normal file
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2022-06-07 Meco Man The first version.
|
||||
*/
|
||||
|
||||
#ifndef __POSIX_STDLIB_H__
|
||||
#define __POSIX_STDLIB_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
char *itoa(int n, char *buffer, int radix);
|
||||
char *lltoa(int64_t ll, char *buffer, int radix);
|
||||
char *ltoa(long l, char *buffer, int radix);
|
||||
char *ulltoa(uint64_t ll, char *buffer, int radix);
|
||||
char *ultoa(unsigned long l, char *buffer, int radix);
|
||||
char *utoa(unsigned int n, char *buffer, int radix);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __POSIX_STDLIB_H__ */
|
43
components/libc/compilers/common/include/posix/string.h
Normal file
43
components/libc/compilers/common/include/posix/string.h
Normal file
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2022-01-12 Meco Man The first version.
|
||||
*/
|
||||
|
||||
#ifndef __POSIX_STRING_H__
|
||||
#define __POSIX_STRING_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
void bzero(void * s, size_t n);
|
||||
void bcopy(const void * src, void * dest, size_t n);
|
||||
int bcmp(const void * s1, const void * s2, size_t n);
|
||||
void explicit_bzero(void * s, size_t n);
|
||||
char *index(const char * s, int c);
|
||||
char *rindex(const char * s, int c);
|
||||
int ffs(int i);
|
||||
int ffsl(long i);
|
||||
int ffsll(long long i);
|
||||
void *memrchr(const void* ptr, int ch, size_t pos);
|
||||
size_t strnlen(const char *s, size_t maxlen);
|
||||
char* strchrnul(const char *s, int c);
|
||||
int strcasecmp(const char * s1, const char * s2);
|
||||
int strncasecmp(const char * s1, const char * s2, size_t n);
|
||||
char *strdup(const char *s);
|
||||
char *strndup(const char *s, size_t size);
|
||||
char *strtok_r(char *str, const char *delim, char **saveptr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __POSIX_STRING_H__ */
|
27
components/libc/compilers/common/include/posix/wchar.h
Normal file
27
components/libc/compilers/common/include/posix/wchar.h
Normal file
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2022-06-07 Meco Man The first version
|
||||
*/
|
||||
|
||||
#ifndef __POSIX_WCHAR_H__
|
||||
#define __POSIX_WCHAR_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <wchar.h>
|
||||
|
||||
int wcwidth(wchar_t);
|
||||
int wcswidth(const wchar_t*, size_t);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __POSIX_WCHAR_H__ */
|
283
components/libc/compilers/common/include/sys/ioctl.h
Normal file
283
components/libc/compilers/common/include/sys/ioctl.h
Normal file
|
@ -0,0 +1,283 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2020-09-01 Meco Man First Version
|
||||
*/
|
||||
|
||||
#ifndef __SYS_IOCTL_H__
|
||||
#define __SYS_IOCTL_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct winsize
|
||||
{
|
||||
unsigned short ws_row;
|
||||
unsigned short ws_col;
|
||||
unsigned short ws_xpixel;
|
||||
unsigned short ws_ypixel;
|
||||
};
|
||||
|
||||
#ifdef RT_USING_MUSLLIBC
|
||||
#include <bits/ioctl.h>
|
||||
#else
|
||||
/*
|
||||
* Direction bits, which any architecture can choose to override
|
||||
* before including this file.
|
||||
*/
|
||||
|
||||
#ifndef _IOC_NONE
|
||||
#define _IOC_NONE 0U
|
||||
#endif
|
||||
|
||||
#ifndef _IOC_WRITE
|
||||
#define _IOC_WRITE 1U
|
||||
#endif
|
||||
|
||||
#ifndef _IOC_READ
|
||||
#define _IOC_READ 2U
|
||||
#endif
|
||||
|
||||
#ifndef _IOC
|
||||
#define _IOC(a,b,c,d) (((a)<<30) | ((b)<<8) | (c) | ((d)<<16))
|
||||
#endif
|
||||
|
||||
#ifndef _IO
|
||||
#define _IO(a,b) _IOC(_IOC_NONE, (a), (b), 0)
|
||||
#endif
|
||||
|
||||
#ifndef _IOW
|
||||
#define _IOW(a,b,c) _IOC(_IOC_WRITE, (a), (b), sizeof(c))
|
||||
#endif
|
||||
|
||||
#ifndef _IOR
|
||||
#define _IOR(a,b,c) _IOC(_IOC_READ, (a), (b), sizeof(c))
|
||||
#endif
|
||||
|
||||
#ifndef _IOWR
|
||||
#define _IOWR(a,b,c) _IOC(_IOC_READ|_IOC_WRITE, (a), (b), sizeof(c))
|
||||
#endif
|
||||
|
||||
#ifndef FIONREAD
|
||||
#define FIONREAD _IOR('f', 127, int) /* get # bytes to read */
|
||||
#endif
|
||||
|
||||
#ifndef FIONBIO
|
||||
#define FIONBIO _IOW('f', 126, int) /* set/clear non-blocking i/o */
|
||||
#endif
|
||||
|
||||
#ifndef FIOASYNC
|
||||
#define FIOASYNC _IOW('f', 125, int) /* set/clear async i/o */
|
||||
#endif
|
||||
|
||||
/* Socket I/O Controls */
|
||||
#ifndef SIOCSHIWAT
|
||||
#define SIOCSHIWAT _IOW('s', 0, int) /* set high watermark */
|
||||
#define SIOCGHIWAT _IOR('s', 1, int) /* get high watermark */
|
||||
#define SIOCSLOWAT _IOW('s', 2, int) /* set low watermark */
|
||||
#define SIOCGLOWAT _IOR('s', 3, int) /* get low watermark */
|
||||
#define SIOCATMARK _IOR('s', 7, int) /* at oob mark? */
|
||||
#endif
|
||||
|
||||
#define TCGETS 0x5401
|
||||
#define TCSETS 0x5402
|
||||
#define TCSETSW 0x5403
|
||||
#define TCSETSF 0x5404
|
||||
#define TCGETA 0x5405
|
||||
#define TCSETA 0x5406
|
||||
#define TCSETAW 0x5407
|
||||
#define TCSETAF 0x5408
|
||||
#define TCSBRK 0x5409
|
||||
#define TCXONC 0x540A
|
||||
#define TCFLSH 0x540B
|
||||
#define TIOCEXCL 0x540C
|
||||
#define TIOCNXCL 0x540D
|
||||
#define TIOCSCTTY 0x540E
|
||||
#define TIOCGPGRP 0x540F
|
||||
#define TIOCSPGRP 0x5410
|
||||
#define TIOCOUTQ 0x5411
|
||||
#define TIOCSTI 0x5412
|
||||
#define TIOCGWINSZ 0x5413
|
||||
#define TIOCSWINSZ 0x5414
|
||||
#define TIOCMGET 0x5415
|
||||
#define TIOCMBIS 0x5416
|
||||
#define TIOCMBIC 0x5417
|
||||
#define TIOCMSET 0x5418
|
||||
#define TIOCGSOFTCAR 0x5419
|
||||
#define TIOCSSOFTCAR 0x541A
|
||||
#define TIOCINQ FIONREAD
|
||||
#define TIOCLINUX 0x541C
|
||||
#define TIOCCONS 0x541D
|
||||
#define TIOCGSERIAL 0x541E
|
||||
#define TIOCSSERIAL 0x541F
|
||||
#define TIOCPKT 0x5420
|
||||
#define TIOCNOTTY 0x5422
|
||||
#define TIOCSETD 0x5423
|
||||
#define TIOCGETD 0x5424
|
||||
#define TCSBRKP 0x5425
|
||||
#define TIOCSBRK 0x5427
|
||||
#define TIOCCBRK 0x5428
|
||||
#define TIOCGSID 0x5429
|
||||
#define TIOCGRS485 0x542E
|
||||
#define TIOCSRS485 0x542F
|
||||
#define TIOCGPTN 0x80045430
|
||||
#define TIOCSPTLCK 0x40045431
|
||||
#define TIOCGDEV 0x80045432
|
||||
#define TCGETX 0x5432
|
||||
#define TCSETX 0x5433
|
||||
#define TCSETXF 0x5434
|
||||
#define TCSETXW 0x5435
|
||||
#define TIOCSIG 0x40045436
|
||||
#define TIOCVHANGUP 0x5437
|
||||
#define TIOCGPKT 0x80045438
|
||||
#define TIOCGPTLCK 0x80045439
|
||||
#define TIOCGEXCL 0x80045440
|
||||
|
||||
#define FIONCLEX 0x5450
|
||||
#define FIOCLEX 0x5451
|
||||
|
||||
#define TIOCSERCONFIG 0x5453
|
||||
#define TIOCSERGWILD 0x5454
|
||||
#define TIOCSERSWILD 0x5455
|
||||
#define TIOCGLCKTRMIOS 0x5456
|
||||
#define TIOCSLCKTRMIOS 0x5457
|
||||
#define TIOCSERGSTRUCT 0x5458
|
||||
#define TIOCSERGETLSR 0x5459
|
||||
#define TIOCSERGETMULTI 0x545A
|
||||
#define TIOCSERSETMULTI 0x545B
|
||||
|
||||
#define TIOCMIWAIT 0x545C
|
||||
#define TIOCGICOUNT 0x545D
|
||||
#define FIOQSIZE 0x5460
|
||||
|
||||
#define TIOCPKT_DATA 0
|
||||
#define TIOCPKT_FLUSHREAD 1
|
||||
#define TIOCPKT_FLUSHWRITE 2
|
||||
#define TIOCPKT_STOP 4
|
||||
#define TIOCPKT_START 8
|
||||
#define TIOCPKT_NOSTOP 16
|
||||
#define TIOCPKT_DOSTOP 32
|
||||
#define TIOCPKT_IOCTL 64
|
||||
|
||||
#define TIOCSER_TEMT 0x01
|
||||
|
||||
#define TIOCM_LE 0x001
|
||||
#define TIOCM_DTR 0x002
|
||||
#define TIOCM_RTS 0x004
|
||||
#define TIOCM_ST 0x008
|
||||
#define TIOCM_SR 0x010
|
||||
#define TIOCM_CTS 0x020
|
||||
#define TIOCM_CAR 0x040
|
||||
#define TIOCM_RNG 0x080
|
||||
#define TIOCM_DSR 0x100
|
||||
#define TIOCM_CD TIOCM_CAR
|
||||
#define TIOCM_RI TIOCM_RNG
|
||||
#define TIOCM_OUT1 0x2000
|
||||
#define TIOCM_OUT2 0x4000
|
||||
#define TIOCM_LOOP 0x8000
|
||||
|
||||
#define N_TTY 0
|
||||
#define N_SLIP 1
|
||||
#define N_MOUSE 2
|
||||
#define N_PPP 3
|
||||
#define N_STRIP 4
|
||||
#define N_AX25 5
|
||||
#define N_X25 6
|
||||
#define N_6PACK 7
|
||||
#define N_MASC 8
|
||||
#define N_R3964 9
|
||||
#define N_PROFIBUS_FDL 10
|
||||
#define N_IRDA 11
|
||||
#define N_SMSBLOCK 12
|
||||
#define N_HDLC 13
|
||||
#define N_SYNC_PPP 14
|
||||
#define N_HCI 15
|
||||
|
||||
#define FIOSETOWN 0x8901
|
||||
#define SIOCSPGRP 0x8902
|
||||
#define FIOGETOWN 0x8903
|
||||
#define SIOCGPGRP 0x8904
|
||||
#define SIOCGSTAMP 0x8906
|
||||
#define SIOCGSTAMPNS 0x8907
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef FIONWRITE
|
||||
#define FIONWRITE _IOR('f', 121, int) /* get # bytes outstanding in send queue */
|
||||
#endif
|
||||
|
||||
#define SIOCADDRT 0x890B
|
||||
#define SIOCDELRT 0x890C
|
||||
#define SIOCRTMSG 0x890D
|
||||
|
||||
#define SIOCGIFNAME 0x8910
|
||||
#define SIOCSIFLINK 0x8911
|
||||
#define SIOCGIFCONF 0x8912
|
||||
#define SIOCGIFFLAGS 0x8913
|
||||
#define SIOCSIFFLAGS 0x8914
|
||||
#define SIOCGIFADDR 0x8915
|
||||
#define SIOCSIFADDR 0x8916
|
||||
#define SIOCGIFDSTADDR 0x8917
|
||||
#define SIOCSIFDSTADDR 0x8918
|
||||
#define SIOCGIFBRDADDR 0x8919
|
||||
#define SIOCSIFBRDADDR 0x891a
|
||||
#define SIOCGIFNETMASK 0x891b
|
||||
#define SIOCSIFNETMASK 0x891c
|
||||
#define SIOCGIFMETRIC 0x891d
|
||||
#define SIOCSIFMETRIC 0x891e
|
||||
#define SIOCGIFMEM 0x891f
|
||||
#define SIOCSIFMEM 0x8920
|
||||
#define SIOCGIFMTU 0x8921
|
||||
#define SIOCSIFMTU 0x8922
|
||||
#define SIOCSIFNAME 0x8923
|
||||
#define SIOCSIFHWADDR 0x8924
|
||||
#define SIOCGIFENCAP 0x8925
|
||||
#define SIOCSIFENCAP 0x8926
|
||||
#define SIOCGIFHWADDR 0x8927
|
||||
#define SIOCGIFSLAVE 0x8929
|
||||
#define SIOCSIFSLAVE 0x8930
|
||||
#define SIOCADDMULTI 0x8931
|
||||
#define SIOCDELMULTI 0x8932
|
||||
#define SIOCGIFINDEX 0x8933
|
||||
#define SIOGIFINDEX SIOCGIFINDEX
|
||||
#define SIOCSIFPFLAGS 0x8934
|
||||
#define SIOCGIFPFLAGS 0x8935
|
||||
#define SIOCDIFADDR 0x8936
|
||||
#define SIOCSIFHWBROADCAST 0x8937
|
||||
#define SIOCGIFCOUNT 0x8938
|
||||
|
||||
#define SIOCGIFBR 0x8940
|
||||
#define SIOCSIFBR 0x8941
|
||||
|
||||
#define SIOCGIFTXQLEN 0x8942
|
||||
#define SIOCSIFTXQLEN 0x8943
|
||||
|
||||
#define SIOCDARP 0x8953
|
||||
#define SIOCGARP 0x8954
|
||||
#define SIOCSARP 0x8955
|
||||
|
||||
#define SIOCDRARP 0x8960
|
||||
#define SIOCGRARP 0x8961
|
||||
#define SIOCSRARP 0x8962
|
||||
|
||||
#define SIOCGIFMAP 0x8970
|
||||
#define SIOCSIFMAP 0x8971
|
||||
|
||||
#define SIOCADDDLCI 0x8980
|
||||
#define SIOCDELDLCI 0x8981
|
||||
|
||||
#define SIOCDEVPRIVATE 0x89F0
|
||||
#define SIOCPROTOPRIVATE 0x89E0
|
||||
|
||||
int ioctl(int fildes, int cmd, ...);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
60
components/libc/compilers/common/include/sys/select.h
Normal file
60
components/libc/compilers/common/include/sys/select.h
Normal file
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2021-07-21 Meco Man The first version
|
||||
* 2021-12-25 Meco Man Handle newlib 2.2.0 or lower version
|
||||
*/
|
||||
|
||||
#ifndef __SYS_SELECT_H__
|
||||
#define __SYS_SELECT_H__
|
||||
|
||||
#include <rtconfig.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef FD_SETSIZE
|
||||
#define FD_SETSIZE 32
|
||||
#endif
|
||||
|
||||
#ifdef SAL_USING_POSIX
|
||||
#ifdef FD_SETSIZE
|
||||
#undef FD_SETSIZE
|
||||
#endif
|
||||
#define FD_SETSIZE DFS_FD_MAX
|
||||
#endif /* SAL_USING_POSIX */
|
||||
|
||||
typedef long fd_mask;
|
||||
|
||||
#ifndef _SYS_TYPES_FD_SET /* Newlib 2.2.0 or lower version */
|
||||
#define NBBY 8 /* number of bits in a byte */
|
||||
#define NFDBITS (sizeof (fd_mask) * NBBY) /* bits per mask */
|
||||
#ifndef howmany
|
||||
#define howmany(x,y) (((x)+((y)-1))/(y))
|
||||
#endif /* howmany */
|
||||
|
||||
typedef struct _types_fd_set {
|
||||
fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)];
|
||||
} _types_fd_set;
|
||||
#define fd_set _types_fd_set
|
||||
|
||||
#define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1L << ((n) % NFDBITS)))
|
||||
#define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1L << ((n) % NFDBITS)))
|
||||
#define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1L << ((n) % NFDBITS)))
|
||||
#define FD_ZERO(p) rt_memset((void*)(p), 0, sizeof(*(p)))
|
||||
#endif /* _SYS_TYPES_FD_SET */
|
||||
|
||||
int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __SYS_SELECT_H__ */
|
251
components/libc/compilers/common/include/sys/signal.h
Normal file
251
components/libc/compilers/common/include/sys/signal.h
Normal file
|
@ -0,0 +1,251 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2017-09-12 Bernard The first version
|
||||
* 2021-07-21 Meco Man move to libc/common
|
||||
*/
|
||||
|
||||
#ifndef __SYS_SIGNAL_H__
|
||||
#define __SYS_SIGNAL_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#ifdef RT_USING_MUSLLIBC
|
||||
/* this is required for musl <signal.h> */
|
||||
#ifndef _POSIX_SOURCE
|
||||
#define _POSIX_SOURCE
|
||||
#include <signal.h>
|
||||
/* limiting influence of _POSIX_SOURCE */
|
||||
#undef _POSIX_SOURCE
|
||||
|
||||
#else /* ndef _POSIX_SOURCE */
|
||||
#include <signal.h>
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
/* sigev_notify values
|
||||
NOTE: P1003.1c/D10, p. 34 adds SIGEV_THREAD. */
|
||||
|
||||
#define SIGEV_NONE 1 /* No asynchronous notification shall be delivered */
|
||||
/* when the event of interest occurs. */
|
||||
#define SIGEV_SIGNAL 0 /* A queued signal, with an application defined */
|
||||
/* value, shall be delivered when the event of */
|
||||
/* interest occurs. */
|
||||
#define SIGEV_THREAD 2 /* A notification function shall be called to */
|
||||
/* perform notification. */
|
||||
|
||||
/* Signal Generation and Delivery, P1003.1b-1993, p. 63
|
||||
NOTE: P1003.1c/D10, p. 34 adds sigev_notify_function and
|
||||
sigev_notify_attributes to the sigevent structure. */
|
||||
union sigval
|
||||
{
|
||||
int sival_int; /* Integer signal value */
|
||||
void *sival_ptr; /* Pointer signal value */
|
||||
};
|
||||
|
||||
struct sigevent
|
||||
{
|
||||
union sigval sigev_value;
|
||||
int sigev_signo; /* Signal number */
|
||||
int sigev_notify; /* Notification type */
|
||||
void (*sigev_notify_function)( union sigval );
|
||||
/* Notification function */
|
||||
void *sigev_notify_attributes; /* Notification Attributes, really pthread_attr_t */
|
||||
};
|
||||
|
||||
struct siginfo
|
||||
{
|
||||
uint16_t si_signo;
|
||||
uint16_t si_code;
|
||||
union sigval si_value;
|
||||
};
|
||||
typedef struct siginfo siginfo_t;
|
||||
|
||||
#define SI_USER 0x01 /* Signal sent by kill(). */
|
||||
#define SI_QUEUE 0x02 /* Signal sent by sigqueue(). */
|
||||
#define SI_TIMER 0x03 /* Signal generated by expiration of a timer set by timer_settime(). */
|
||||
#define SI_ASYNCIO 0x04 /* Signal generated by completion of an asynchronous I/O request. */
|
||||
#define SI_MESGQ 0x05 /* Signal generated by arrival of a message on an empty message queue. */
|
||||
|
||||
typedef void (*_sig_func_ptr)(int);
|
||||
typedef unsigned long sigset_t;
|
||||
|
||||
struct sigaction
|
||||
{
|
||||
_sig_func_ptr sa_handler;
|
||||
sigset_t sa_mask;
|
||||
int sa_flags;
|
||||
};
|
||||
|
||||
/*
|
||||
* Structure used in sigaltstack call.
|
||||
*/
|
||||
typedef struct sigaltstack
|
||||
{
|
||||
void *ss_sp; /* Stack base or pointer. */
|
||||
int ss_flags; /* Flags. */
|
||||
size_t ss_size; /* Stack size. */
|
||||
} stack_t;
|
||||
|
||||
#define SIG_SETMASK 0 /* set mask with sigprocmask() */
|
||||
#define SIG_BLOCK 1 /* set of signals to block */
|
||||
#define SIG_UNBLOCK 2 /* set of signals to, well, unblock */
|
||||
|
||||
#define sigaddset(what,sig) (*(what) |= (1<<(sig)), 0)
|
||||
#define sigdelset(what,sig) (*(what) &= ~(1<<(sig)), 0)
|
||||
#define sigemptyset(what) (*(what) = 0, 0)
|
||||
#define sigfillset(what) (*(what) = ~(0), 0)
|
||||
#define sigismember(what,sig) (((*(what)) & (1<<(sig))) != 0)
|
||||
|
||||
int sigprocmask (int how, const sigset_t *set, sigset_t *oset);
|
||||
int sigpending (sigset_t *set);
|
||||
int sigsuspend (const sigset_t *set);
|
||||
|
||||
#include "time.h"
|
||||
int sigtimedwait(const sigset_t *set, siginfo_t *info, const struct timespec *timeout);
|
||||
int sigwait(const sigset_t *set, int *sig);
|
||||
int sigwaitinfo(const sigset_t *set, siginfo_t *info);
|
||||
int raise(int sig);
|
||||
int sigqueue(pid_t pid, int signo, const union sigval value);
|
||||
int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact);
|
||||
|
||||
#ifdef __ARMCC_VERSION
|
||||
#define SIGHUP 1
|
||||
/* #define SIGINT 2 */
|
||||
#define SIGQUIT 3
|
||||
/* #define SIGILL 4 */
|
||||
#define SIGTRAP 5
|
||||
/* #define SIGABRT 6 */
|
||||
#define SIGEMT 7
|
||||
/* #define SIGFPE 8 */
|
||||
#define SIGKILL 9
|
||||
#define SIGBUS 10
|
||||
/* #define SIGSEGV 11 */
|
||||
#define SIGSYS 12
|
||||
#define SIGPIPE 13
|
||||
#define SIGALRM 14
|
||||
/* #define SIGTERM 15 */
|
||||
#define SIGURG 16
|
||||
#define SIGSTOP 17
|
||||
#define SIGTSTP 18
|
||||
#define SIGCONT 19
|
||||
#define SIGCHLD 20
|
||||
#define SIGTTIN 21
|
||||
#define SIGTTOU 22
|
||||
#define SIGPOLL 23
|
||||
#define SIGWINCH 24
|
||||
#define SIGXCPU 24 /* exceeded CPU time limit */
|
||||
#define SIGXFSZ 25 /* exceeded file size limit */
|
||||
#define SIGVTALRM 26 /* virtual time alarm */
|
||||
/* #define SIGUSR1 25 */
|
||||
/* #define SIGUSR2 26 */
|
||||
#define SIGRTMIN 27
|
||||
#define SIGRTMAX 31
|
||||
#define NSIG 32
|
||||
|
||||
#elif defined(__IAR_SYSTEMS_ICC__)
|
||||
#define SIGHUP 1
|
||||
#define SIGINT 2
|
||||
#define SIGQUIT 3
|
||||
#define SIGILL 4
|
||||
#define SIGTRAP 5
|
||||
/* #define SIGABRT 6 */
|
||||
#define SIGEMT 7
|
||||
#define SIGFPE 8
|
||||
#define SIGKILL 9
|
||||
#define SIGBUS 10
|
||||
#define SIGSEGV 11
|
||||
#define SIGSYS 12
|
||||
#define SIGPIPE 13
|
||||
#define SIGALRM 14
|
||||
#define SIGTERM 15
|
||||
#define SIGURG 16
|
||||
#define SIGSTOP 17
|
||||
#define SIGTSTP 18
|
||||
#define SIGCONT 19
|
||||
#define SIGCHLD 20
|
||||
#define SIGTTIN 21
|
||||
#define SIGTTOU 22
|
||||
#define SIGPOLL 23
|
||||
#define SIGWINCH 24
|
||||
#define SIGXCPU 24 /* exceeded CPU time limit */
|
||||
#define SIGXFSZ 25 /* exceeded file size limit */
|
||||
#define SIGVTALRM 26 /* virtual time alarm */
|
||||
#define SIGUSR1 25
|
||||
#define SIGUSR2 26
|
||||
#define SIGRTMIN 27
|
||||
#define SIGRTMAX 31
|
||||
#define NSIG 32
|
||||
|
||||
#elif defined(__GNUC__)
|
||||
#define SIGHUP 1 /* hangup */
|
||||
#define SIGINT 2 /* interrupt */
|
||||
#define SIGQUIT 3 /* quit */
|
||||
#define SIGILL 4 /* illegal instruction (not reset when caught) */
|
||||
#define SIGTRAP 5 /* trace trap (not reset when caught) */
|
||||
#define SIGIOT 6 /* IOT instruction */
|
||||
#define SIGABRT 6 /* used by abort, replace SIGIOT in the future */
|
||||
#define SIGEMT 7 /* EMT instruction */
|
||||
#define SIGFPE 8 /* floating point exception */
|
||||
#define SIGKILL 9 /* kill (cannot be caught or ignored) */
|
||||
#define SIGBUS 10 /* bus error */
|
||||
#define SIGSEGV 11 /* segmentation violation */
|
||||
#define SIGSYS 12 /* bad argument to system call */
|
||||
#define SIGPIPE 13 /* write on a pipe with no one to read it */
|
||||
#define SIGALRM 14 /* alarm clock */
|
||||
#define SIGTERM 15 /* software termination signal from kill */
|
||||
#define SIGURG 16 /* urgent condition on IO channel */
|
||||
#define SIGSTOP 17 /* sendable stop signal not from tty */
|
||||
#define SIGTSTP 18 /* stop signal from tty */
|
||||
#define SIGCONT 19 /* continue a stopped process */
|
||||
#define SIGCHLD 20 /* to parent on child stop or exit */
|
||||
#define SIGCLD 20 /* System V name for SIGCHLD */
|
||||
#define SIGTTIN 21 /* to readers pgrp upon background tty read */
|
||||
#define SIGTTOU 22 /* like TTIN for output if (tp->t_local<OSTOP) */
|
||||
#define SIGIO 23 /* input/output possible signal */
|
||||
#define SIGPOLL SIGIO /* System V name for SIGIO */
|
||||
#define SIGXCPU 24 /* exceeded CPU time limit */
|
||||
#define SIGXFSZ 25 /* exceeded file size limit */
|
||||
#define SIGVTALRM 26 /* virtual time alarm */
|
||||
#define SIGPROF 27 /* profiling time alarm */
|
||||
#define SIGWINCH 28 /* window changed */
|
||||
#define SIGLOST 29 /* resource lost (eg, record-lock lost) */
|
||||
#define SIGUSR1 30 /* user defined signal 1 */
|
||||
#define SIGUSR2 31 /* user defined signal 2 */
|
||||
#define NSIG 32 /* signal 0 implied */
|
||||
#endif /* __ARMCC_VERSION */
|
||||
|
||||
/* Some applications take advantage of the fact that <sys/signal.h>
|
||||
* and <signal.h> are equivalent in glibc. Allow for that here. */
|
||||
#include <signal.h>
|
||||
|
||||
#ifndef SIG_ERR
|
||||
#define SIG_ERR ((void (*)(int))-1)
|
||||
#endif
|
||||
|
||||
#ifndef SIG_DFL
|
||||
#define SIG_DFL ((void (*)(int)) 0)
|
||||
#endif
|
||||
|
||||
#ifndef SIG_IGN
|
||||
#define SIG_IGN ((void (*)(int)) 1)
|
||||
#endif
|
||||
|
||||
#endif /* RT_USING_MUSLLIBC */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* __SYS_SIGNAL_H__ */
|
||||
|
49
components/libc/compilers/common/include/sys/statfs.h
Normal file
49
components/libc/compilers/common/include/sys/statfs.h
Normal file
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2023-03-27 xqyjlj adapt musl
|
||||
*/
|
||||
|
||||
#ifndef __SYS_STATFS_H__
|
||||
#define __SYS_STATFS_H__
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef RT_USING_MUSLLIBC
|
||||
/* this is required for musl <sys/statfs.h> */
|
||||
#ifndef _POSIX_SOURCE
|
||||
#define _POSIX_SOURCE
|
||||
#include_next <sys/statfs.h>
|
||||
/* limiting influence of _POSIX_SOURCE */
|
||||
#undef _POSIX_SOURCE
|
||||
|
||||
#else /* def _POSIX_SOURCE */
|
||||
#include_next <sys/statfs.h>
|
||||
#endif
|
||||
#else
|
||||
struct statfs
|
||||
{
|
||||
size_t f_bsize; /* block size */
|
||||
size_t f_blocks; /* total data blocks in file system */
|
||||
size_t f_bfree; /* free blocks in file system */
|
||||
size_t f_bavail; /* free blocks available to unprivileged user*/
|
||||
};
|
||||
|
||||
int statfs(const char *path, struct statfs *buf);
|
||||
int fstatfs(int fd, struct statfs *buf);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
166
components/libc/compilers/common/include/sys/time.h
Normal file
166
components/libc/compilers/common/include/sys/time.h
Normal file
|
@ -0,0 +1,166 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2020-09-07 Meco Man combine gcc armcc iccarm
|
||||
* 2021-02-12 Meco Man move all definitions located in <clock_time.h> to this file
|
||||
*/
|
||||
|
||||
#ifndef __SYS_TIME_H__
|
||||
#define __SYS_TIME_H__
|
||||
|
||||
#include <rtconfig.h>
|
||||
#include <sys/types.h>
|
||||
#include <stdint.h>
|
||||
#include <time.h>
|
||||
#ifdef _WIN32
|
||||
typedef __time64_t time_t;
|
||||
#endif /* _WIN32 */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#undef CLOCKS_PER_SEC
|
||||
#define CLOCKS_PER_SEC RT_TICK_PER_SECOND
|
||||
|
||||
/* timezone */
|
||||
#define DST_NONE 0 /* not on dst */
|
||||
#define DST_USA 1 /* USA style dst */
|
||||
#define DST_AUST 2 /* Australian style dst */
|
||||
#define DST_WET 3 /* Western European dst */
|
||||
#define DST_MET 4 /* Middle European dst */
|
||||
#define DST_EET 5 /* Eastern European dst */
|
||||
#define DST_CAN 6 /* Canada */
|
||||
#define DST_GB 7 /* Great Britain and Eire */
|
||||
#define DST_RUM 8 /* Rumania */
|
||||
#define DST_TUR 9 /* Turkey */
|
||||
#define DST_AUSTALT 10 /* Australian style with shift in 1986 */
|
||||
|
||||
struct itimerspec;
|
||||
|
||||
struct timezone
|
||||
{
|
||||
int tz_minuteswest; /* minutes west of Greenwich */
|
||||
int tz_dsttime; /* type of dst correction */
|
||||
};
|
||||
|
||||
#ifndef _TIMEVAL_DEFINED
|
||||
#define _TIMEVAL_DEFINED
|
||||
struct timeval
|
||||
{
|
||||
time_t tv_sec; /* seconds */
|
||||
suseconds_t tv_usec; /* and microseconds */
|
||||
};
|
||||
#endif /* _TIMEVAL_DEFINED */
|
||||
|
||||
#if defined(__ARMCC_VERSION) || defined(_WIN32) || (defined(__ICCARM__) && (__VER__ < 8010001))
|
||||
struct timespec
|
||||
{
|
||||
time_t tv_sec; /* seconds */
|
||||
long tv_nsec; /* and nanoseconds */
|
||||
};
|
||||
#endif /* defined(__ARMCC_VERSION) || defined(_WIN32) || (defined(__ICCARM__) && (__VER__ < 8010001)) */
|
||||
|
||||
#if !(defined(__GNUC__) && !defined(__ARMCC_VERSION)/*GCC*/)
|
||||
/*
|
||||
* Structure defined by POSIX.1b to be like a itimerval, but with
|
||||
* timespecs. Used in the timer_*() system calls.
|
||||
*/
|
||||
struct itimerspec
|
||||
{
|
||||
struct timespec it_interval;
|
||||
struct timespec it_value;
|
||||
};
|
||||
#endif /* !(defined(__GNUC__) && !defined(__ARMCC_VERSION)) */
|
||||
|
||||
int stime(const time_t *t);
|
||||
time_t timegm(struct tm * const t);
|
||||
int gettimeofday(struct timeval *tv, struct timezone *tz);
|
||||
int settimeofday(const struct timeval *tv, const struct timezone *tz);
|
||||
|
||||
#if defined(__ARMCC_VERSION) || defined (__ICCARM__) || defined(_WIN32)
|
||||
struct tm *gmtime_r(const time_t *timep, struct tm *r);
|
||||
char* asctime_r(const struct tm *t, char *buf);
|
||||
char *ctime_r(const time_t * tim_p, char * result);
|
||||
struct tm* localtime_r(const time_t* t, struct tm* r);
|
||||
#endif /* defined(__ARMCC_VERSION) || defined (__ICCARM__) || defined(_WIN32) */
|
||||
|
||||
#ifdef _WIN32
|
||||
struct tm* gmtime(const time_t* t);
|
||||
struct tm* localtime(const time_t* t);
|
||||
time_t mktime(struct tm* const t);
|
||||
char* ctime(const time_t* tim_p);
|
||||
time_t time(time_t* t);
|
||||
#endif /* _WIN32 */
|
||||
|
||||
#ifdef RT_USING_POSIX_DELAY
|
||||
int nanosleep(const struct timespec *rqtp, struct timespec *rmtp);
|
||||
#endif /* RT_USING_POSIX_DELAY */
|
||||
|
||||
#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)
|
||||
|
||||
#if defined(RT_USING_POSIX_CLOCK) || defined (RT_USING_POSIX_TIMER)
|
||||
/* POSIX clock and timer */
|
||||
|
||||
#ifndef CLOCK_REALTIME
|
||||
#define CLOCK_REALTIME 1
|
||||
#endif /* CLOCK_REALTIME */
|
||||
|
||||
#define CLOCK_CPUTIME_ID 2
|
||||
|
||||
#ifndef CLOCK_PROCESS_CPUTIME_ID
|
||||
#define CLOCK_PROCESS_CPUTIME_ID CLOCK_CPUTIME_ID
|
||||
#endif /* CLOCK_PROCESS_CPUTIME_ID */
|
||||
|
||||
#ifndef CLOCK_THREAD_CPUTIME_ID
|
||||
#define CLOCK_THREAD_CPUTIME_ID CLOCK_CPUTIME_ID
|
||||
#endif /* CLOCK_THREAD_CPUTIME_ID */
|
||||
|
||||
#ifndef CLOCK_MONOTONIC
|
||||
#define CLOCK_MONOTONIC 4
|
||||
#endif /* CLOCK_MONOTONIC */
|
||||
|
||||
#ifdef CLOCK_TAI
|
||||
#define CLOCK_ID_MAX CLOCK_TAI
|
||||
#else
|
||||
#define CLOCK_ID_MAX CLOCK_MONOTONIC
|
||||
#endif
|
||||
#endif /* defined(RT_USING_POSIX_CLOCK) || defined (RT_USING_POSIX_TIMER) */
|
||||
|
||||
#ifdef RT_USING_POSIX_CLOCK
|
||||
int clock_getres (clockid_t clockid, struct timespec *res);
|
||||
int clock_gettime (clockid_t clockid, struct timespec *tp);
|
||||
int clock_settime (clockid_t clockid, const struct timespec *tp);
|
||||
int clock_nanosleep(clockid_t clockid, int flags, const struct timespec *rqtp, struct timespec *rmtp);
|
||||
int rt_timespec_to_tick(const struct timespec *time);
|
||||
#endif /* RT_USING_POSIX_CLOCK */
|
||||
|
||||
#ifdef RT_USING_POSIX_TIMER
|
||||
#include <sys/signal.h>
|
||||
int timer_create(clockid_t clockid, struct sigevent *evp, timer_t *timerid);
|
||||
int timer_delete(timer_t timerid);
|
||||
int timer_getoverrun(timer_t timerid);
|
||||
int timer_gettime(timer_t timerid, struct itimerspec *its);
|
||||
int timer_settime(timer_t timerid, int flags, const struct itimerspec *value, struct itimerspec *ovalue);
|
||||
#endif /* RT_USING_POSIX_TIMER */
|
||||
|
||||
/* timezone */
|
||||
void tz_set(int8_t tz);
|
||||
int8_t tz_get(void);
|
||||
int8_t tz_is_dst(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _SYS_TIME_H_ */
|
62
components/libc/compilers/common/include/sys/unistd.h
Normal file
62
components/libc/compilers/common/include/sys/unistd.h
Normal file
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2020-12-16 Meco Man add usleep
|
||||
* 2021-09-11 Meco Man move functions from dfs_posix.h to unistd.h
|
||||
*/
|
||||
|
||||
#ifndef __SYS_UNISTD_H__
|
||||
#define __SYS_UNISTD_H__
|
||||
|
||||
#include <stddef.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define STDIN_FILENO 0 /* standard input file descriptor */
|
||||
#define STDOUT_FILENO 1 /* standard output file descriptor */
|
||||
#define STDERR_FILENO 2 /* standard error file descriptor */
|
||||
|
||||
#define F_OK 0
|
||||
#define X_OK 1
|
||||
#define W_OK 2
|
||||
#define R_OK 4
|
||||
|
||||
unsigned alarm(unsigned __secs);
|
||||
ssize_t read(int fd, void *buf, size_t len);
|
||||
ssize_t write(int fd, const void *buf, size_t len);
|
||||
off_t lseek(int fd, off_t offset, int whence);
|
||||
int pause(void);
|
||||
int fsync(int fildes);
|
||||
long sysconf(int __name);
|
||||
int unlink(const char *pathname);
|
||||
int close(int d);
|
||||
int ftruncate(int fd, off_t length);
|
||||
int rmdir(const char *path);
|
||||
int chdir(const char *path);
|
||||
char *getcwd(char *buf, size_t size);
|
||||
int access(const char *path, int amode);
|
||||
int pipe(int fildes[2]);
|
||||
int isatty(int fd);
|
||||
char *ttyname(int desc);
|
||||
unsigned int sleep(unsigned int seconds);
|
||||
int usleep(useconds_t usec);
|
||||
pid_t gettid(void);
|
||||
pid_t getpid(void);
|
||||
pid_t getppid(void);
|
||||
uid_t getuid(void);
|
||||
uid_t geteuid(void);
|
||||
gid_t getgid(void);
|
||||
gid_t getegid(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _SYS_UNISTD_H */
|
49
components/libc/compilers/common/include/sys/utsname.h
Normal file
49
components/libc/compilers/common/include/sys/utsname.h
Normal file
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2023, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2023-03-27 xqyjlj add uname
|
||||
*/
|
||||
|
||||
#ifndef __SYS_UTSNAME_H__
|
||||
#define __SYS_UTSNAME_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef RT_USING_MUSLLIBC
|
||||
/* this is required for musl <sys/utsname.h> */
|
||||
#ifndef _POSIX_SOURCE
|
||||
#define _POSIX_SOURCE
|
||||
#include_next <sys/utsname.h>
|
||||
/* limiting influence of _POSIX_SOURCE */
|
||||
#undef _POSIX_SOURCE
|
||||
|
||||
#else /* def _POSIX_SOURCE */
|
||||
#include_next <sys/utsname.h>
|
||||
#endif
|
||||
#else
|
||||
|
||||
struct utsname
|
||||
{
|
||||
char sysname[65];
|
||||
char nodename[65];
|
||||
char release[65];
|
||||
char version[65];
|
||||
char machine[65];
|
||||
char domainname[65];
|
||||
};
|
||||
|
||||
int uname(struct utsname *);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
16
components/libc/compilers/common/include/sys/vfs.h
Normal file
16
components/libc/compilers/common/include/sys/vfs.h
Normal file
|
@ -0,0 +1,16 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2021-09-11 Meco Man First version
|
||||
*/
|
||||
|
||||
#ifndef __SYS_VFS_H__
|
||||
#define __SYS_VFS_H__
|
||||
|
||||
#include "statfs.h" /* <sys/statfs.h> */
|
||||
|
||||
#endif
|
10
components/libc/compilers/common/include/unistd.h
Normal file
10
components/libc/compilers/common/include/unistd.h
Normal file
|
@ -0,0 +1,10 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
*/
|
||||
|
||||
#include "sys/unistd.h"
|
1
components/libc/compilers/common/readme.md
Normal file
1
components/libc/compilers/common/readme.md
Normal file
|
@ -0,0 +1 @@
|
|||
This folder is "common" for all toolchains.
|
3
components/libc/compilers/dlib/README.md
Normal file
3
components/libc/compilers/dlib/README.md
Normal file
|
@ -0,0 +1,3 @@
|
|||
# DLIB (IAR) porting for RT-Thread
|
||||
|
||||
http://www.iarsys.co.jp/download/LMS2/arm/7502/ewarm7502doc/arm/doc/EWARM_DevelopmentGuide.ENU.pdf P.130
|
21
components/libc/compilers/dlib/SConscript
Normal file
21
components/libc/compilers/dlib/SConscript
Normal file
|
@ -0,0 +1,21 @@
|
|||
from building import *
|
||||
Import('rtconfig')
|
||||
|
||||
src = Glob('*.c')
|
||||
group = []
|
||||
|
||||
if rtconfig.PLATFORM in ['iccarm']:
|
||||
CPPDEFINES = ['RT_USING_DLIBC', 'RT_USING_LIBC', '_DLIB_ADD_EXTRA_SYMBOLS=0']
|
||||
AddDepend(['RT_USING_DLIBC', 'RT_USING_LIBC'])
|
||||
|
||||
if GetDepend('DFS_USING_POSIX'):
|
||||
from distutils.version import LooseVersion
|
||||
from iar import IARVersion
|
||||
|
||||
CPPDEFINES = CPPDEFINES + ['_DLIB_FILE_DESCRIPTOR']
|
||||
if LooseVersion(IARVersion()) < LooseVersion("8.20.1"):
|
||||
CPPDEFINES = CPPDEFINES + ['_DLIB_THREAD_SUPPORT']
|
||||
|
||||
group = DefineGroup('Compiler', src, depend = [''], CPPDEFINES = CPPDEFINES)
|
||||
|
||||
Return('group')
|
12
components/libc/compilers/dlib/environ.c
Normal file
12
components/libc/compilers/dlib/environ.c
Normal file
|
@ -0,0 +1,12 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2021, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2015-01-28 Bernard first version
|
||||
*/
|
||||
|
||||
const char *__environ = "OS=RT-Thread";
|
||||
|
38
components/libc/compilers/dlib/syscall_close.c
Normal file
38
components/libc/compilers/dlib/syscall_close.c
Normal file
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2021, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2015-01-28 Bernard first version
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <LowLevelIOInterface.h>
|
||||
#include <unistd.h>
|
||||
#include <compiler_private.h>
|
||||
#define DBG_TAG "dlib.syscall.close"
|
||||
#define DBG_LVL DBG_INFO
|
||||
#include <rtdbg.h>
|
||||
|
||||
/*
|
||||
* The "__close" function should close the file corresponding to
|
||||
* "handle". It should return 0 on success and nonzero on failure.
|
||||
*/
|
||||
|
||||
#pragma module_name = "?__close"
|
||||
|
||||
int __close(int handle)
|
||||
{
|
||||
if (handle == _LLIO_STDOUT ||
|
||||
handle == _LLIO_STDERR ||
|
||||
handle == _LLIO_STDIN)
|
||||
return _LLIO_ERROR;
|
||||
#ifdef DFS_USING_POSIX
|
||||
return close(handle);
|
||||
#else
|
||||
LOG_W(_WARNING_WITHOUT_FS);
|
||||
return _LLIO_ERROR;
|
||||
#endif /* DFS_USING_POSIX */
|
||||
}
|
47
components/libc/compilers/dlib/syscall_lseek.c
Normal file
47
components/libc/compilers/dlib/syscall_lseek.c
Normal file
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2021, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2015-01-28 Bernard first version
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <LowLevelIOInterface.h>
|
||||
#include <unistd.h>
|
||||
#include <compiler_private.h>
|
||||
#define DBG_TAG "dlib.syscall.lseek"
|
||||
#define DBG_LVL DBG_INFO
|
||||
#include <rtdbg.h>
|
||||
|
||||
/*
|
||||
* The "__lseek" function makes the next file operation (__read or
|
||||
* __write) act on a new location. The parameter "whence" specifies
|
||||
* how the "offset" parameter should be interpreted according to the
|
||||
* following table:
|
||||
*
|
||||
* 0 (=SEEK_SET) - Goto location "offset".
|
||||
* 1 (=SEEK_CUR) - Go "offset" bytes from the current location.
|
||||
* 2 (=SEEK_END) - Go to "offset" bytes from the end.
|
||||
*
|
||||
* This function should return the current file position, or -1 on
|
||||
* failure.
|
||||
*/
|
||||
|
||||
#pragma module_name = "?__lseek"
|
||||
|
||||
long __lseek(int handle, long offset, int whence)
|
||||
{
|
||||
if (handle == _LLIO_STDOUT ||
|
||||
handle == _LLIO_STDERR ||
|
||||
handle == _LLIO_STDIN)
|
||||
return _LLIO_ERROR;
|
||||
#ifdef DFS_USING_POSIX
|
||||
return lseek(handle, offset, whence);
|
||||
#else
|
||||
LOG_W(_WARNING_WITHOUT_FS);
|
||||
return _LLIO_ERROR;
|
||||
#endif /* DFS_USING_POSIX */
|
||||
}
|
61
components/libc/compilers/dlib/syscall_mem.c
Normal file
61
components/libc/compilers/dlib/syscall_mem.c
Normal file
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2021, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2015-01-28 Bernard first version
|
||||
* 2021-11-13 Meco Man implement no-heap warning
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#ifndef RT_USING_HEAP
|
||||
#define DBG_TAG "dlib.syscall.mem"
|
||||
#define DBG_LVL DBG_INFO
|
||||
#include <rtdbg.h>
|
||||
#define _NO_HEAP_ERROR() do{LOG_E("Please enable RT_USING_HEAP");\
|
||||
RT_ASSERT(0);\
|
||||
}while(0)
|
||||
#endif /* RT_USING_HEAP */
|
||||
|
||||
void *malloc(size_t n)
|
||||
{
|
||||
#ifdef RT_USING_HEAP
|
||||
return rt_malloc(n);
|
||||
#else
|
||||
_NO_HEAP_ERROR();
|
||||
return RT_NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
void *realloc(void *rmem, size_t newsize)
|
||||
{
|
||||
#ifdef RT_USING_HEAP
|
||||
return rt_realloc(rmem, newsize);
|
||||
#else
|
||||
_NO_HEAP_ERROR();
|
||||
return RT_NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
void *calloc(size_t nelem, size_t elsize)
|
||||
{
|
||||
#ifdef RT_USING_HEAP
|
||||
return rt_calloc(nelem, elsize);
|
||||
#else
|
||||
_NO_HEAP_ERROR();
|
||||
return RT_NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
void free(void *rmem)
|
||||
{
|
||||
#ifdef RT_USING_HEAP
|
||||
rt_free(rmem);
|
||||
#else
|
||||
_NO_HEAP_ERROR();
|
||||
#endif
|
||||
}
|
83
components/libc/compilers/dlib/syscall_open.c
Normal file
83
components/libc/compilers/dlib/syscall_open.c
Normal file
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2021, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2015-01-28 Bernard first version
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <LowLevelIOInterface.h>
|
||||
#include <fcntl.h>
|
||||
#include <compiler_private.h>
|
||||
#define DBG_TAG "dlib.syscall.open"
|
||||
#define DBG_LVL DBG_INFO
|
||||
#include <rtdbg.h>
|
||||
|
||||
/*
|
||||
* The "__open" function opens the file named "filename" as specified
|
||||
* by "mode".
|
||||
*/
|
||||
|
||||
#pragma module_name = "?__open"
|
||||
|
||||
int __open(const char *filename, int mode)
|
||||
{
|
||||
#ifdef DFS_USING_POSIX
|
||||
int handle;
|
||||
int open_mode = O_RDONLY;
|
||||
|
||||
if (mode & _LLIO_CREAT)
|
||||
{
|
||||
open_mode |= O_CREAT;
|
||||
|
||||
/* Check what we should do with it if it exists. */
|
||||
if (mode & _LLIO_APPEND)
|
||||
{
|
||||
/* Append to the existing file. */
|
||||
open_mode |= O_APPEND;
|
||||
}
|
||||
|
||||
if (mode & _LLIO_TRUNC)
|
||||
{
|
||||
/* Truncate the existsing file. */
|
||||
open_mode |= O_TRUNC;
|
||||
}
|
||||
}
|
||||
|
||||
if (mode & _LLIO_TEXT)
|
||||
{
|
||||
/* we didn't support text mode */
|
||||
}
|
||||
|
||||
switch (mode & _LLIO_RDWRMASK)
|
||||
{
|
||||
case _LLIO_RDONLY:
|
||||
break;
|
||||
|
||||
case _LLIO_WRONLY:
|
||||
open_mode |= O_WRONLY;
|
||||
break;
|
||||
|
||||
case _LLIO_RDWR:
|
||||
/* The file should be opened for both reads and writes. */
|
||||
open_mode |= O_RDWR;
|
||||
break;
|
||||
|
||||
default:
|
||||
return _LLIO_ERROR;
|
||||
}
|
||||
|
||||
handle = open(filename, open_mode, 0);
|
||||
if (handle < 0)
|
||||
{
|
||||
return _LLIO_ERROR;
|
||||
}
|
||||
return handle;
|
||||
#else
|
||||
LOG_W(_WARNING_WITHOUT_FS);
|
||||
return _LLIO_ERROR;
|
||||
#endif /* DFS_USING_POSIX */
|
||||
}
|
65
components/libc/compilers/dlib/syscall_read.c
Normal file
65
components/libc/compilers/dlib/syscall_read.c
Normal file
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2021, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2015-01-28 Bernard first version
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <LowLevelIOInterface.h>
|
||||
#include <unistd.h>
|
||||
#ifdef RT_USING_POSIX_STDIO
|
||||
#include "libc.h"
|
||||
#endif /* RT_USING_POSIX_STDIO */
|
||||
#include <compiler_private.h>
|
||||
#define DBG_TAG "dlib.syscall.read"
|
||||
#define DBG_LVL DBG_INFO
|
||||
#include <rtdbg.h>
|
||||
|
||||
/*
|
||||
* The "__read" function reads a number of bytes, at most "size" into
|
||||
* the memory area pointed to by "buffer". It returns the number of
|
||||
* bytes read, 0 at the end of the file, or _LLIO_ERROR if failure
|
||||
* occurs.
|
||||
*
|
||||
* The template implementation below assumes that the application
|
||||
* provides the function "MyLowLevelGetchar". It should return a
|
||||
* character value, or -1 on failure.
|
||||
*/
|
||||
|
||||
#pragma module_name = "?__read"
|
||||
|
||||
size_t __read(int handle, unsigned char *buf, size_t len)
|
||||
{
|
||||
#ifdef DFS_USING_POSIX
|
||||
int size;
|
||||
|
||||
if (handle == _LLIO_STDIN)
|
||||
{
|
||||
#ifdef RT_USING_POSIX_STDIO
|
||||
if (libc_stdio_get_console() < 0)
|
||||
{
|
||||
LOG_W("Do not invoke standard input before initializing Compiler");
|
||||
return 0; /* error, but keep going */
|
||||
}
|
||||
return read(STDIN_FILENO, buf, len); /* return the length of the data read */
|
||||
#else
|
||||
LOG_W(_WARNING_WITHOUT_STDIO);
|
||||
return _LLIO_ERROR;
|
||||
#endif /* RT_USING_POSIX_STDIO */
|
||||
}
|
||||
else if ((handle == _LLIO_STDOUT) || (handle == _LLIO_STDERR))
|
||||
{
|
||||
return _LLIO_ERROR;
|
||||
}
|
||||
|
||||
size = read(handle, buf, len);
|
||||
return size; /* return the length of the data read */
|
||||
#else
|
||||
LOG_W(_WARNING_WITHOUT_FS);
|
||||
return _LLIO_ERROR;
|
||||
#endif /* DFS_USING_POSIX */
|
||||
}
|
34
components/libc/compilers/dlib/syscall_remove.c
Normal file
34
components/libc/compilers/dlib/syscall_remove.c
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2021, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2015-01-28 Bernard first version
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <LowLevelIOInterface.h>
|
||||
#include <unistd.h>
|
||||
#include <compiler_private.h>
|
||||
#define DBG_TAG "dlib.syscall.remove"
|
||||
#define DBG_LVL DBG_INFO
|
||||
#include <rtdbg.h>
|
||||
|
||||
/*
|
||||
* The "remove" function should remove the file named "filename". It
|
||||
* should return 0 on success and nonzero on failure.
|
||||
*/
|
||||
|
||||
#pragma module_name = "?remove"
|
||||
|
||||
int remove(const char *filename)
|
||||
{
|
||||
#ifdef DFS_USING_POSIX
|
||||
return unlink(filename);
|
||||
#else
|
||||
LOG_W(_WARNING_WITHOUT_FS);
|
||||
return _LLIO_ERROR;
|
||||
#endif /* DFS_USING_POSIX */
|
||||
}
|
71
components/libc/compilers/dlib/syscall_write.c
Normal file
71
components/libc/compilers/dlib/syscall_write.c
Normal file
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2021, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2015-01-28 Bernard first version
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <LowLevelIOInterface.h>
|
||||
#include <unistd.h>
|
||||
#include <compiler_private.h>
|
||||
#define DBG_TAG "dlib.syscall.write"
|
||||
#define DBG_LVL DBG_INFO
|
||||
#include <rtdbg.h>
|
||||
|
||||
/*
|
||||
* The "__write" function should output "size" number of bytes from
|
||||
* "buffer" in some application-specific way. It should return the
|
||||
* number of characters written, or _LLIO_ERROR on failure.
|
||||
*
|
||||
* If "buffer" is zero then __write should perform flushing of
|
||||
* internal buffers, if any. In this case "handle" can be -1 to
|
||||
* indicate that all handles should be flushed.
|
||||
*
|
||||
* The template implementation below assumes that the application
|
||||
* provides the function "MyLowLevelPutchar". It should return the
|
||||
* character written, or -1 on failure.
|
||||
*/
|
||||
|
||||
#pragma module_name = "?__write"
|
||||
|
||||
size_t __write(int handle, const unsigned char *buf, size_t len)
|
||||
{
|
||||
#ifdef DFS_USING_POSIX
|
||||
int size;
|
||||
#endif /* DFS_USING_POSIX */
|
||||
|
||||
if ((handle == _LLIO_STDOUT) || (handle == _LLIO_STDERR))
|
||||
{
|
||||
#if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
|
||||
rt_device_t console_device;
|
||||
|
||||
console_device = rt_console_get_device();
|
||||
if (console_device)
|
||||
{
|
||||
rt_device_write(console_device, 0, buf, len);
|
||||
}
|
||||
|
||||
return len; /* return the length of the data written */
|
||||
#else
|
||||
return _LLIO_ERROR;
|
||||
#endif /* defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE) */
|
||||
}
|
||||
else if (handle == _LLIO_STDIN)
|
||||
{
|
||||
return _LLIO_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef DFS_USING_POSIX
|
||||
size = write(handle, buf, len);
|
||||
return size; /* return the length of the data written */
|
||||
#else
|
||||
LOG_W(_WARNING_WITHOUT_FS);
|
||||
return _LLIO_ERROR;
|
||||
#endif /* DFS_USING_POSIX */
|
||||
}
|
||||
}
|
19
components/libc/compilers/dlib/syscalls.c
Normal file
19
components/libc/compilers/dlib/syscalls.c
Normal file
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2021, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2021-02-13 Meco Man implement exit() and abort()
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
|
||||
/* for exit() and abort() */
|
||||
void __exit (int status)
|
||||
{
|
||||
extern void __rt_libc_exit(int status);
|
||||
__rt_libc_exit(status);
|
||||
while(1);
|
||||
}
|
30
components/libc/compilers/musl/SConscript
Normal file
30
components/libc/compilers/musl/SConscript
Normal file
|
@ -0,0 +1,30 @@
|
|||
import os
|
||||
from building import *
|
||||
from gcc import *
|
||||
Import('rtconfig')
|
||||
|
||||
group = []
|
||||
|
||||
musllibc_version = GetMuslVersion(rtconfig)
|
||||
|
||||
if musllibc_version:
|
||||
print('Musl version: ' + musllibc_version)
|
||||
|
||||
cwd = GetCurrentDir()
|
||||
src = Glob('*.c')
|
||||
|
||||
CPPPATH = [cwd]
|
||||
CPPDEFINES = ['RT_USING_MUSLLIBC', 'RT_USING_LIBC']
|
||||
LIBS = ['c', 'gcc']
|
||||
LINKFLAGS = ' --specs=kernel.specs'
|
||||
AddDepend(['RT_USING_MUSLLIBC', 'RT_USING_LIBC'])
|
||||
|
||||
group = group + DefineGroup('Compiler', src, depend = [''], CPPPATH = CPPPATH, LINKFLAGS = LINKFLAGS, CPPDEFINES = CPPDEFINES, LIBS = LIBS)
|
||||
|
||||
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')
|
24
components/libc/compilers/musl/fcntl.h
Normal file
24
components/libc/compilers/musl/fcntl.h
Normal file
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2021, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2021-09-02 Meco Man First version
|
||||
*/
|
||||
|
||||
#ifndef __FCNTL_H__
|
||||
#define __FCNTL_H__
|
||||
|
||||
#include_next <fcntl.h>
|
||||
|
||||
#ifndef O_DIRECTORY
|
||||
#define O_DIRECTORY 0x200000
|
||||
#endif
|
||||
|
||||
#ifndef O_BINARY
|
||||
#define O_BINARY 0x10000
|
||||
#endif
|
||||
|
||||
#endif
|
20
components/libc/compilers/musl/syscalls.c
Normal file
20
components/libc/compilers/musl/syscalls.c
Normal file
|
@ -0,0 +1,20 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2021, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2022-11-18 Meco Man first version
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
|
||||
int *__errno_location(void)
|
||||
{
|
||||
return _rt_errno();
|
||||
}
|
||||
int *___errno_location(void)
|
||||
{
|
||||
return _rt_errno();
|
||||
}
|
4
components/libc/compilers/newlib/README.md
Normal file
4
components/libc/compilers/newlib/README.md
Normal file
|
@ -0,0 +1,4 @@
|
|||
# NEWLIB (GCC) porting for RT-Thread
|
||||
|
||||
https://sourceware.org/newlib/libc.html#Reentrancy
|
||||
|
29
components/libc/compilers/newlib/SConscript
Normal file
29
components/libc/compilers/newlib/SConscript
Normal file
|
@ -0,0 +1,29 @@
|
|||
import os
|
||||
from building import *
|
||||
from gcc import *
|
||||
Import('rtconfig')
|
||||
|
||||
group = []
|
||||
|
||||
newlib_version = GetNewLibVersion(rtconfig)
|
||||
|
||||
if newlib_version and not GetDepend('RT_USING_EXTERNAL_LIBC'):
|
||||
print('Newlib version: ' + newlib_version)
|
||||
|
||||
cwd = GetCurrentDir()
|
||||
src = Glob('*.c')
|
||||
|
||||
CPPPATH = [cwd]
|
||||
CPPDEFINES = ['RT_USING_NEWLIBC', 'RT_USING_LIBC', '_POSIX_C_SOURCE=1'] # identify this is Newlib, and only enable POSIX.1-1990
|
||||
LIBS = ['c', 'm'] # link libc and libm
|
||||
AddDepend(['RT_USING_NEWLIBC', 'RT_USING_LIBC'])
|
||||
|
||||
group = group + DefineGroup('Compiler', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES, LIBS = LIBS)
|
||||
|
||||
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')
|
24
components/libc/compilers/newlib/fcntl.h
Normal file
24
components/libc/compilers/newlib/fcntl.h
Normal file
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2021, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2021-09-02 Meco Man First version
|
||||
*/
|
||||
|
||||
#ifndef __FCNTL_H__
|
||||
#define __FCNTL_H__
|
||||
|
||||
#include <sys/_default_fcntl.h>
|
||||
|
||||
#ifndef O_DIRECTORY
|
||||
#define O_DIRECTORY 0x200000
|
||||
#endif
|
||||
|
||||
#ifndef O_BINARY
|
||||
#define O_BINARY 0x10000
|
||||
#endif
|
||||
|
||||
#endif
|
17
components/libc/compilers/newlib/machine/time.h
Normal file
17
components/libc/compilers/newlib/machine/time.h
Normal file
|
@ -0,0 +1,17 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2021, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2021-02-16 Meco Man The first version
|
||||
*/
|
||||
|
||||
#ifndef _MACHTIME_H_
|
||||
#define _MACHTIME_H_
|
||||
|
||||
#include <rtconfig.h>
|
||||
#define _CLOCKS_PER_SEC_ RT_TICK_PER_SECOND
|
||||
|
||||
#endif /* _MACHTIME_H_ */
|
338
components/libc/compilers/newlib/syscalls.c
Normal file
338
components/libc/compilers/newlib/syscalls.c
Normal file
|
@ -0,0 +1,338 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2021, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2021-02-11 Meco Man remove _gettimeofday_r() and _times_r()
|
||||
* 2021-02-13 Meco Man re-implement exit() and abort()
|
||||
* 2021-02-21 Meco Man improve and beautify syscalls
|
||||
* 2021-02-24 Meco Man fix bug of _isatty_r()
|
||||
*/
|
||||
|
||||
#include <reent.h>
|
||||
#include <rtthread.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stddef.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/errno.h>
|
||||
#include <sys/stat.h>
|
||||
#ifdef RT_USING_POSIX_STDIO
|
||||
#include "libc.h"
|
||||
#endif /* RT_USING_POSIX_STDIO */
|
||||
#ifdef RT_USING_MODULE
|
||||
#include <dlmodule.h>
|
||||
#endif /* RT_USING_MODULE */
|
||||
#include <compiler_private.h>
|
||||
#define DBG_TAG "newlib.syscalls"
|
||||
#define DBG_LVL DBG_INFO
|
||||
#include <rtdbg.h>
|
||||
|
||||
#ifdef RT_USING_HEAP /* Memory routine */
|
||||
void *_malloc_r(struct _reent *ptr, size_t size)
|
||||
{
|
||||
void* result;
|
||||
|
||||
result = (void*)rt_malloc(size);
|
||||
if (result == RT_NULL)
|
||||
{
|
||||
ptr->_errno = ENOMEM;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void *_realloc_r(struct _reent *ptr, void *old, size_t newlen)
|
||||
{
|
||||
void* result;
|
||||
|
||||
result = (void*)rt_realloc(old, newlen);
|
||||
if (result == RT_NULL)
|
||||
{
|
||||
ptr->_errno = ENOMEM;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void *_calloc_r(struct _reent *ptr, size_t size, size_t len)
|
||||
{
|
||||
void* result;
|
||||
|
||||
result = (void*)rt_calloc(size, len);
|
||||
if (result == RT_NULL)
|
||||
{
|
||||
ptr->_errno = ENOMEM;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void _free_r(struct _reent *ptr, void *addr)
|
||||
{
|
||||
rt_free(addr);
|
||||
}
|
||||
|
||||
#else
|
||||
void *_sbrk_r(struct _reent *ptr, ptrdiff_t incr)
|
||||
{
|
||||
LOG_E("Please enable RT_USING_HEAP");
|
||||
RT_ASSERT(0);
|
||||
return RT_NULL;
|
||||
}
|
||||
#endif /*RT_USING_HEAP*/
|
||||
|
||||
void __libc_init_array(void)
|
||||
{
|
||||
/* we not use __libc init_aray to initialize C++ objects */
|
||||
/* __libc_init_array is ARM code, not Thumb; it will cause a hardfault. */
|
||||
}
|
||||
|
||||
/* Reentrant versions of system calls. */
|
||||
#ifndef _REENT_ONLY
|
||||
int *__errno(void)
|
||||
{
|
||||
return _rt_errno();
|
||||
}
|
||||
#endif
|
||||
|
||||
int _getpid_r(struct _reent *ptr)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _close_r(struct _reent *ptr, int fd)
|
||||
{
|
||||
#ifdef DFS_USING_POSIX
|
||||
return close(fd);
|
||||
#else
|
||||
LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
|
||||
ptr->_errno = ENOTSUP;
|
||||
return -1;
|
||||
#endif /* DFS_USING_POSIX */
|
||||
}
|
||||
|
||||
int _execve_r(struct _reent *ptr, const char * name, char *const *argv, char *const *env)
|
||||
{
|
||||
ptr->_errno = ENOTSUP;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int _fcntl_r(struct _reent *ptr, int fd, int cmd, int arg)
|
||||
{
|
||||
ptr->_errno = ENOTSUP;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int _fork_r(struct _reent *ptr)
|
||||
{
|
||||
ptr->_errno = ENOTSUP;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int _fstat_r(struct _reent *ptr, int fd, struct stat *pstat)
|
||||
{
|
||||
ptr->_errno = ENOTSUP;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int _isatty_r(struct _reent *ptr, int fd)
|
||||
{
|
||||
if (fd >=0 && fd < 3)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int _kill_r(struct _reent *ptr, int pid, int sig)
|
||||
{
|
||||
ptr->_errno = ENOTSUP;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int _link_r(struct _reent *ptr, const char *old, const char *new)
|
||||
{
|
||||
ptr->_errno = ENOTSUP;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int _wait_r(struct _reent *ptr, int *status)
|
||||
{
|
||||
ptr->_errno = ENOTSUP;
|
||||
return -1;
|
||||
}
|
||||
|
||||
mode_t umask(mode_t mask)
|
||||
{
|
||||
return 022;
|
||||
}
|
||||
|
||||
int flock(int fd, int operation)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
_off_t _lseek_r(struct _reent *ptr, int fd, _off_t pos, int whence)
|
||||
{
|
||||
#ifdef DFS_USING_POSIX
|
||||
_off_t rc;
|
||||
rc = lseek(fd, pos, whence);
|
||||
return rc;
|
||||
#else
|
||||
LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
|
||||
ptr->_errno = ENOTSUP;
|
||||
return -1;
|
||||
#endif /* DFS_USING_POSIX */
|
||||
}
|
||||
|
||||
int _mkdir_r(struct _reent *ptr, const char *name, int mode)
|
||||
{
|
||||
#ifdef DFS_USING_POSIX
|
||||
int rc;
|
||||
rc = mkdir(name, mode);
|
||||
return rc;
|
||||
#else
|
||||
LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
|
||||
ptr->_errno = ENOTSUP;
|
||||
return -1;
|
||||
#endif /* DFS_USING_POSIX */
|
||||
}
|
||||
|
||||
int _open_r(struct _reent *ptr, const char *file, int flags, int mode)
|
||||
{
|
||||
#ifdef DFS_USING_POSIX
|
||||
int rc;
|
||||
rc = open(file, flags, mode);
|
||||
return rc;
|
||||
#else
|
||||
LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
|
||||
ptr->_errno = ENOTSUP;
|
||||
return -1;
|
||||
#endif /* DFS_USING_POSIX */
|
||||
}
|
||||
|
||||
_ssize_t _read_r(struct _reent *ptr, int fd, void *buf, size_t nbytes)
|
||||
{
|
||||
#ifdef DFS_USING_POSIX
|
||||
_ssize_t rc;
|
||||
if (fd == STDIN_FILENO)
|
||||
{
|
||||
#ifdef RT_USING_POSIX_STDIO
|
||||
if (libc_stdio_get_console() < 0)
|
||||
{
|
||||
LOG_W("Do not invoke standard input before initializing Compiler");
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
LOG_W("%s: %s", __func__, _WARNING_WITHOUT_STDIO);
|
||||
ptr->_errno = ENOTSUP;
|
||||
return -1;
|
||||
#endif /* RT_USING_POSIX_STDIO */
|
||||
}
|
||||
else if (fd == STDOUT_FILENO || fd == STDERR_FILENO)
|
||||
{
|
||||
ptr->_errno = ENOTSUP;
|
||||
return -1;
|
||||
}
|
||||
|
||||
rc = read(fd, buf, nbytes);
|
||||
return rc;
|
||||
#else
|
||||
LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
|
||||
ptr->_errno = ENOTSUP;
|
||||
return -1;
|
||||
#endif /* DFS_USING_POSIX */
|
||||
}
|
||||
|
||||
int _rename_r(struct _reent *ptr, const char *old, const char *new)
|
||||
{
|
||||
#ifdef DFS_USING_POSIX
|
||||
int rc;
|
||||
rc = rename(old, new);
|
||||
return rc;
|
||||
#else
|
||||
LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
|
||||
ptr->_errno = ENOTSUP;
|
||||
return -1;
|
||||
#endif /* DFS_USING_POSIX */
|
||||
}
|
||||
|
||||
int _stat_r(struct _reent *ptr, const char *file, struct stat *pstat)
|
||||
{
|
||||
#ifdef DFS_USING_POSIX
|
||||
int rc;
|
||||
rc = stat(file, pstat);
|
||||
return rc;
|
||||
#else
|
||||
LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
|
||||
ptr->_errno = ENOTSUP;
|
||||
return -1;
|
||||
#endif /* DFS_USING_POSIX */
|
||||
}
|
||||
|
||||
int _unlink_r(struct _reent *ptr, const char *file)
|
||||
{
|
||||
#ifdef DFS_USING_POSIX
|
||||
return unlink(file);
|
||||
#else
|
||||
LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
|
||||
ptr->_errno = ENOTSUP;
|
||||
return -1;
|
||||
#endif /* DFS_USING_POSIX */
|
||||
}
|
||||
|
||||
_ssize_t _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes)
|
||||
{
|
||||
#ifdef DFS_USING_POSIX
|
||||
_ssize_t rc;
|
||||
#endif /* DFS_USING_POSIX */
|
||||
|
||||
if (fd == STDOUT_FILENO || fd == STDERR_FILENO)
|
||||
{
|
||||
#if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
|
||||
rt_device_t console;
|
||||
|
||||
console = rt_console_get_device();
|
||||
if (console)
|
||||
return rt_device_write(console, -1, buf, nbytes);
|
||||
#else
|
||||
ptr->_errno = ENOTSUP;
|
||||
return -1;
|
||||
#endif /* defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE) */
|
||||
}
|
||||
else if (fd == STDIN_FILENO)
|
||||
{
|
||||
ptr->_errno = ENOTSUP;
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef DFS_USING_POSIX
|
||||
rc = write(fd, buf, nbytes);
|
||||
return rc;
|
||||
#else
|
||||
LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
|
||||
ptr->_errno = ENOTSUP;
|
||||
return -1;
|
||||
#endif /* DFS_USING_POSIX */
|
||||
}
|
||||
|
||||
/* for exit() and abort() */
|
||||
__attribute__ ((noreturn)) void _exit (int status)
|
||||
{
|
||||
extern void __rt_libc_exit(int status);
|
||||
__rt_libc_exit(status);
|
||||
while(1);
|
||||
}
|
||||
|
||||
/*
|
||||
These functions are implemented and replaced by the 'common/time.c' file
|
||||
int _gettimeofday_r(struct _reent *ptr, struct timeval *__tp, void *__tzp);
|
||||
_CLOCK_T_ _times_r(struct _reent *ptr, struct tms *ptms);
|
||||
*/
|
8
components/libc/compilers/picolibc/README.md
Normal file
8
components/libc/compilers/picolibc/README.md
Normal file
|
@ -0,0 +1,8 @@
|
|||
# PICOLIBC (LLVM-ARM) porting for RT-Thread
|
||||
|
||||
https://github.com/ARM-software/LLVM-embedded-toolchain-for-Arm
|
||||
|
||||
https://github.com/picolibc/picolibc
|
||||
|
||||
|
||||
|
29
components/libc/compilers/picolibc/SConscript
Normal file
29
components/libc/compilers/picolibc/SConscript
Normal file
|
@ -0,0 +1,29 @@
|
|||
import os
|
||||
from building import *
|
||||
from llvm_arm import *
|
||||
Import('rtconfig')
|
||||
|
||||
group = []
|
||||
|
||||
picolibc_version = GetPicoLibcVersion(rtconfig)
|
||||
|
||||
if picolibc_version and not GetDepend('RT_USING_EXTERNAL_LIBC'):
|
||||
print('PicoLibc version: ' + picolibc_version)
|
||||
|
||||
cwd = GetCurrentDir()
|
||||
src = Glob('*.c')
|
||||
|
||||
CPPPATH = [cwd]
|
||||
CPPDEFINES = ['RT_USING_PICOLIBC', 'RT_USING_LIBC', '_POSIX_C_SOURCE=1', '__PICOLIBC_ERRNO_FUNCTION=pico_get_errno'] # identify this is Newlib, and only enable POSIX.1-1990
|
||||
# LIBS = ['c', 'm'] # link libc and libm
|
||||
AddDepend(['RT_USING_PICOLIBC', 'RT_USING_LIBC'])
|
||||
|
||||
group = group + DefineGroup('Compiler', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES)#, LIBS = LIBS)
|
||||
|
||||
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')
|
16
components/libc/compilers/picolibc/syscall.c
Normal file
16
components/libc/compilers/picolibc/syscall.c
Normal file
|
@ -0,0 +1,16 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2023, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2023-05-17 Flybreak the first version
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
|
||||
int pico_get_errno(void)
|
||||
{
|
||||
return rt_get_errno();
|
||||
}
|
1
components/libc/compilers/readme.md
Normal file
1
components/libc/compilers/readme.md
Normal file
|
@ -0,0 +1 @@
|
|||
This folder provides uniformed header files crossing different compiler platforms, and supports basic standard C library functions, such as memory management and time management, etc.
|
Loading…
Add table
Add a link
Reference in a new issue