mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2025-12-26 01:07:21 +00:00
[libc] Change libc stubs to compiler folder.
This commit is contained in:
4
components/libc/compilers/dlib/README.md
Normal file
4
components/libc/compilers/dlib/README.md
Normal file
@@ -0,0 +1,4 @@
|
||||
Dlib(IAR) porting for RT-Thread.
|
||||
|
||||
Please define RT_USING_LIBC and compile RT-Thread with IAR compiler.
|
||||
|
||||
19
components/libc/compilers/dlib/SConscript
Normal file
19
components/libc/compilers/dlib/SConscript
Normal file
@@ -0,0 +1,19 @@
|
||||
from building import *
|
||||
import rtconfig
|
||||
|
||||
src = Glob('*.c')
|
||||
cwd = GetCurrentDir()
|
||||
group = []
|
||||
|
||||
CPPPATH = [cwd]
|
||||
CPPDEFINES = ['RT_USING_DLIBC']
|
||||
|
||||
if rtconfig.PLATFORM == 'iar':
|
||||
|
||||
if GetDepend('RT_USING_DFS'):
|
||||
CPPDEFINES = CPPDEFINES + ['_DLIB_FILE_DESCRIPTOR', '_DLIB_THREAD_SUPPORT']
|
||||
|
||||
group = DefineGroup('dlib', src, depend = ['RT_USING_LIBC'],
|
||||
CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES)
|
||||
|
||||
Return('group')
|
||||
25
components/libc/compilers/dlib/environ.c
Normal file
25
components/libc/compilers/dlib/environ.c
Normal file
@@ -0,0 +1,25 @@
|
||||
/* File: environ.c
|
||||
* this file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006 - 2015, RT-Thread Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2015-01-28 Bernard first version
|
||||
*/
|
||||
|
||||
const char *__environ = "OS=RT-Thread";
|
||||
|
||||
74
components/libc/compilers/dlib/rmtx.c
Normal file
74
components/libc/compilers/dlib/rmtx.c
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* File : rmtx.c
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006 - 2015, RT-Thread Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2015-01-28 Bernard first version
|
||||
*/
|
||||
#include <rtthread.h>
|
||||
#include <yfuns.h>
|
||||
|
||||
/*
|
||||
* for IAR compiler, we recommand to define _DLIB_THREAD_SUPPORT
|
||||
* as 2 for dlib multi-thread support.
|
||||
*/
|
||||
|
||||
#if _DLIB_THREAD_SUPPORT
|
||||
typedef void* _Rmtx;
|
||||
void _Mtxinit(_Rmtx *m)
|
||||
{
|
||||
rt_mutex_t mutex;
|
||||
|
||||
RT_ASSERT(m != RT_NULL);
|
||||
|
||||
mutex = (rt_mutex_t)m;
|
||||
rt_mutex_init(mutex, "iarMtx", RT_IPC_FLAG_FIFO);
|
||||
}
|
||||
|
||||
void _Mtxdst(_Rmtx *m)
|
||||
{
|
||||
rt_mutex_t mutex;
|
||||
|
||||
RT_ASSERT(m != RT_NULL);
|
||||
|
||||
mutex = (rt_mutex_t)m;
|
||||
rt_mutex_detach(mutex);
|
||||
}
|
||||
|
||||
void _Mtxlock(_Rmtx *m)
|
||||
{
|
||||
rt_mutex_t mutex;
|
||||
|
||||
RT_ASSERT(m != RT_NULL);
|
||||
|
||||
mutex = (rt_mutex_t)m;
|
||||
rt_mutex_take(mutex, RT_WAITING_FOREVER);
|
||||
}
|
||||
|
||||
void _Mtxunlock(_Rmtx *m)
|
||||
{
|
||||
rt_mutex_t mutex;
|
||||
|
||||
RT_ASSERT(m != RT_NULL);
|
||||
|
||||
mutex = (rt_mutex_t)m;
|
||||
rt_mutex_release(mutex);
|
||||
}
|
||||
#endif
|
||||
|
||||
1
components/libc/compilers/dlib/sys/README.md
Normal file
1
components/libc/compilers/dlib/sys/README.md
Normal file
@@ -0,0 +1 @@
|
||||
Because IAR leaks some system header file, we put them in here.
|
||||
80
components/libc/compilers/dlib/sys/errno.h
Normal file
80
components/libc/compilers/dlib/sys/errno.h
Normal file
@@ -0,0 +1,80 @@
|
||||
#ifndef SYS_ERRNO_H__
|
||||
#define SYS_ERRNO_H__
|
||||
|
||||
#ifdef RT_USING_DFS
|
||||
|
||||
#include <dfs_def.h>
|
||||
|
||||
/* using device error codes */
|
||||
#define ENOENT DFS_STATUS_ENOENT
|
||||
#define EIO DFS_STATUS_EIO
|
||||
#define ENXIO DFS_STATUS_ENXIO
|
||||
#define EBADF DFS_STATUS_EBADF
|
||||
#define EAGAIN DFS_STATUS_EAGAIN
|
||||
#define ENOMEM DFS_STATUS_ENOMEM
|
||||
#define EBUSY DFS_STATUS_EBUSY
|
||||
#define EEXIST DFS_STATUS_EEXIST
|
||||
#define EXDEV DFS_STATUS_EXDEV
|
||||
#define ENODEV DFS_STATUS_ENODEV
|
||||
#define ENOTDIR DFS_STATUS_ENOTDIR
|
||||
#define EISDIR DFS_STATUS_EISDIR
|
||||
#define EINVAL DFS_STATUS_EINVAL
|
||||
#define ENOSPC DFS_STATUS_ENOSPC
|
||||
#define EROFS DFS_STATUS_EROFS
|
||||
#define ENOSYS DFS_STATUS_ENOSYS
|
||||
#define ENOTEMPTY DFS_STATUS_ENOTEMPTY
|
||||
|
||||
#else
|
||||
|
||||
/* error codes */
|
||||
#define ENOENT 2 /* No such file or directory */
|
||||
#define EIO 5 /* I/O error */
|
||||
#define ENXIO 6 /* No such device or address */
|
||||
#define EBADF 9 /* Bad file number */
|
||||
#define EAGAIN 11 /* Try again */
|
||||
#define ENOMEM 12 /* no memory */
|
||||
#define EBUSY 16 /* Device or resource busy */
|
||||
#define EEXIST 17 /* File exists */
|
||||
#define EXDEV 18 /* Cross-device link */
|
||||
#define ENODEV 19 /* No such device */
|
||||
#define ENOTDIR 20 /* Not a directory */
|
||||
#define EISDIR 21 /* Is a directory */
|
||||
#define EINVAL 22 /* Invalid argument */
|
||||
#define ENOSPC 28 /* No space left on device */
|
||||
#define EROFS 30 /* Read-only file system */
|
||||
#define ENOSYS 38 /* Function not implemented */
|
||||
#define ENOTEMPTY 39 /* Directory not empty */
|
||||
|
||||
#endif
|
||||
|
||||
#define EPERM 1 /* Not super-user */
|
||||
#define ESRCH 3 /* No such process */
|
||||
#define EINTR 4 /* Interrupted system call */
|
||||
#define EACCES 13 /* Permission denied */
|
||||
#define EFAULT 14 /* Bad address */
|
||||
#define ENFILE 23 /* Too many open files in system */
|
||||
#define ERANGE 34 /* Math result not representable */
|
||||
#define EDEADLK 45 /* Deadlock condition */
|
||||
#define EBADMSG 77 /* Trying to read unreadable message */
|
||||
#define EMSGSIZE 90 /* Message too long */
|
||||
#define ENOPROTOOPT 92 /* Protocol not available */
|
||||
#define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */
|
||||
#define EAFNOSUPPORT 97 /* Address family not supported by protocol */
|
||||
#define EADDRINUSE 98 /* Address already in use */
|
||||
#define EADDRNOTAVAIL 99 /* Cannot assign requested address */
|
||||
#define ENETDOWN 100 /* Network is down */
|
||||
#define ENETUNREACH 101 /* Network is unreachable */
|
||||
#define ECONNABORTED 103 /* Software caused connection abort */
|
||||
#define ECONNRESET 104 /* Connection reset by peer */
|
||||
#define ENOBUFS 105 /* No buffer space available */
|
||||
#define EISCONN 106 /* Transport endpoint is already connected */
|
||||
#define ENOTCONN 107 /* Transport endpoint is not connected */
|
||||
#define EINPROGRESS 115 /* Operation now in progress */
|
||||
#define ETIMEDOUT 116 /* Connection timed out */
|
||||
#define EHOSTUNREACH 113 /* No route to host */
|
||||
#define EALREADY 114 /* Operation already in progress */
|
||||
#define ENOTSUP 134 /* Not supported */
|
||||
#define ENSRNOTFOUND 163 /* Domain name not found */
|
||||
#define EWOULDBLOCK EAGAIN /* Operation would block */
|
||||
|
||||
#endif
|
||||
45
components/libc/compilers/dlib/sys/time.h
Normal file
45
components/libc/compilers/dlib/sys/time.h
Normal file
@@ -0,0 +1,45 @@
|
||||
#ifndef _SYS_TIME_H_
|
||||
#define _SYS_TIME_H_
|
||||
|
||||
#include <time.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef _TIMEVAL_DEFINED
|
||||
#define _TIMEVAL_DEFINED
|
||||
/*
|
||||
* Structure returned by gettimeofday(2) system call,
|
||||
* and used in other calls.
|
||||
*/
|
||||
struct timeval {
|
||||
long tv_sec; /* seconds */
|
||||
long tv_usec; /* and microseconds */
|
||||
};
|
||||
#endif /* _TIMEVAL_DEFINED */
|
||||
|
||||
#ifndef _TIMESPEC_DEFINED
|
||||
#define _TIMESPEC_DEFINED
|
||||
/*
|
||||
* Structure defined by POSIX.1b to be like a timeval.
|
||||
*/
|
||||
struct timespec {
|
||||
time_t tv_sec; /* seconds */
|
||||
long tv_nsec; /* and nanoseconds */
|
||||
};
|
||||
#endif /* _TIMESPEC_DEFINED */
|
||||
|
||||
struct timezone {
|
||||
int tz_minuteswest; /* minutes west of Greenwich */
|
||||
int tz_dsttime; /* type of dst correction */
|
||||
};
|
||||
|
||||
int gettimeofday(struct timeval *tp, void *ignore);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _SYS_TIME_H_ */
|
||||
14
components/libc/compilers/dlib/sys/types.h
Normal file
14
components/libc/compilers/dlib/sys/types.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef __TYPES_H__
|
||||
#define __TYPES_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <rtthread.h>
|
||||
|
||||
typedef rt_int32_t clockid_t;
|
||||
typedef rt_int32_t key_t; /* Used for interprocess communication. */
|
||||
typedef rt_int32_t pid_t; /* Used for process IDs and process group IDs. */
|
||||
typedef signed long ssize_t; /* Used for a count of bytes or an error indication. */
|
||||
|
||||
typedef int mode_t;
|
||||
|
||||
#endif
|
||||
34
components/libc/compilers/dlib/sys/unistd.h
Normal file
34
components/libc/compilers/dlib/sys/unistd.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#ifndef _SYS_UNISTD_H
|
||||
#define _SYS_UNISTD_H
|
||||
|
||||
#ifdef RT_USING_DFS
|
||||
#include <dfs_posix.h>
|
||||
#else
|
||||
#define _FREAD 0x0001 /* read enabled */
|
||||
#define _FWRITE 0x0002 /* write enabled */
|
||||
#define _FAPPEND 0x0008 /* append (writes guaranteed at the end) */
|
||||
#define _FMARK 0x0010 /* internal; mark during gc() */
|
||||
#define _FDEFER 0x0020 /* internal; defer for next gc pass */
|
||||
#define _FASYNC 0x0040 /* signal pgrp when data ready */
|
||||
#define _FSHLOCK 0x0080 /* BSD flock() shared lock present */
|
||||
#define _FEXLOCK 0x0100 /* BSD flock() exclusive lock present */
|
||||
#define _FCREAT 0x0200 /* open with file create */
|
||||
#define _FTRUNC 0x0400 /* open with truncation */
|
||||
#define _FEXCL 0x0800 /* error on open if file exists */
|
||||
#define _FNBIO 0x1000 /* non blocking I/O (sys5 style) */
|
||||
#define _FSYNC 0x2000 /* do all writes synchronously */
|
||||
#define _FNONBLOCK 0x4000 /* non blocking I/O (POSIX style) */
|
||||
#define _FNDELAY _FNONBLOCK /* non blocking I/O (4.2 style) */
|
||||
#define _FNOCTTY 0x8000 /* don't assign a ctty on this open */
|
||||
|
||||
#define O_RDONLY 0 /* +1 == FREAD */
|
||||
#define O_WRONLY 1 /* +1 == FWRITE */
|
||||
#define O_RDWR 2 /* +1 == FREAD|FWRITE */
|
||||
#define O_APPEND _FAPPEND
|
||||
#define O_CREAT _FCREAT
|
||||
#define O_TRUNC _FTRUNC
|
||||
#define O_EXCL _FEXCL
|
||||
#define O_SYNC _FSYNC
|
||||
#endif
|
||||
|
||||
#endif /* _SYS_UNISTD_H */
|
||||
43
components/libc/compilers/dlib/syscall_close.c
Normal file
43
components/libc/compilers/dlib/syscall_close.c
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* File : syscall_close.c
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006 - 2015, RT-Thread Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2015-01-28 Bernard first version
|
||||
*/
|
||||
#include <rtthread.h>
|
||||
#ifdef RT_USING_DFS
|
||||
#include <dfs_posix.h>
|
||||
#endif
|
||||
#include <yfuns.h>
|
||||
|
||||
#pragma module_name = "?__close"
|
||||
int __close(int handle)
|
||||
{
|
||||
if (handle == _LLIO_STDOUT ||
|
||||
handle == _LLIO_STDERR ||
|
||||
handle == _LLIO_STDIN)
|
||||
return _LLIO_ERROR;
|
||||
|
||||
#ifdef RT_USING_DFS
|
||||
return close(handle - _LLIO_STDERR - 1);
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
43
components/libc/compilers/dlib/syscall_lseek.c
Normal file
43
components/libc/compilers/dlib/syscall_lseek.c
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* File : syscall_lseek.c
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006 - 2015, RT-Thread Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2015-01-28 Bernard first version
|
||||
*/
|
||||
#include <rtthread.h>
|
||||
#ifdef RT_USING_DFS
|
||||
#include <dfs_posix.h>
|
||||
#endif
|
||||
#include <yfuns.h>
|
||||
|
||||
#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 RT_USING_DFS
|
||||
return lseek(handle - _LLIO_STDERR - 1, offset, whence);
|
||||
#else
|
||||
return _LLIO_ERROR;
|
||||
#endif
|
||||
}
|
||||
44
components/libc/compilers/dlib/syscall_mem.c
Normal file
44
components/libc/compilers/dlib/syscall_mem.c
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* File : syscall_mem.c
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006 - 2015, RT-Thread Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2015-01-28 Bernard first version
|
||||
*/
|
||||
#include <rtthread.h>
|
||||
|
||||
void *malloc(rt_size_t n)
|
||||
{
|
||||
return rt_malloc(n);
|
||||
}
|
||||
|
||||
void *realloc(void *rmem, rt_size_t newsize)
|
||||
{
|
||||
return rt_realloc(rmem, newsize);
|
||||
}
|
||||
|
||||
void *calloc(rt_size_t nelem, rt_size_t elsize)
|
||||
{
|
||||
return rt_calloc(nelem, elsize);
|
||||
}
|
||||
|
||||
void free(void *rmem)
|
||||
{
|
||||
rt_free(rmem);
|
||||
}
|
||||
88
components/libc/compilers/dlib/syscall_open.c
Normal file
88
components/libc/compilers/dlib/syscall_open.c
Normal file
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* File : syscall_open.c
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006 - 2015, RT-Thread Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2015-01-28 Bernard first version
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <yfuns.h>
|
||||
#ifdef RT_USING_DFS
|
||||
#include <dfs_posix.h>
|
||||
#endif
|
||||
|
||||
#pragma module_name = "?__open"
|
||||
|
||||
int __open(const char *filename, int mode)
|
||||
{
|
||||
#ifndef RT_USING_DFS
|
||||
return -1;
|
||||
#else
|
||||
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 -1;
|
||||
}
|
||||
|
||||
handle = open(filename, open_mode, 0);
|
||||
if (handle < 0)
|
||||
return -1;
|
||||
|
||||
return handle + _LLIO_STDERR + 1;
|
||||
#endif
|
||||
}
|
||||
53
components/libc/compilers/dlib/syscall_read.c
Normal file
53
components/libc/compilers/dlib/syscall_read.c
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* File : syscall_read.c
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006 - 2015, RT-Thread Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2015-01-28 Bernard first version
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
#ifdef RT_USING_DFS
|
||||
#include <dfs_posix.h>
|
||||
#endif
|
||||
#include <yfuns.h>
|
||||
|
||||
#pragma module_name = "?__read"
|
||||
size_t __read(int handle, unsigned char *buf, size_t len)
|
||||
{
|
||||
#ifdef RT_USING_DFS
|
||||
int size;
|
||||
#endif
|
||||
|
||||
if (handle == _LLIO_STDIN)
|
||||
{
|
||||
/* TODO */
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((handle == _LLIO_STDOUT) || (handle == _LLIO_STDERR))
|
||||
return _LLIO_ERROR;
|
||||
|
||||
#ifndef RT_USING_DFS
|
||||
return _LLIO_ERROR;
|
||||
#else
|
||||
size = read(handle - _LLIO_STDERR - 1, buf, len);
|
||||
return size;
|
||||
#endif
|
||||
}
|
||||
38
components/libc/compilers/dlib/syscall_remove.c
Normal file
38
components/libc/compilers/dlib/syscall_remove.c
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* File : syscall_remove.c
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006 - 2015, RT-Thread Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2015-01-28 Bernard first version
|
||||
*/
|
||||
#include <rtthread.h>
|
||||
#ifdef RT_USING_DFS
|
||||
#include <dfs_file.h>
|
||||
#endif
|
||||
#include <yfuns.h>
|
||||
|
||||
#pragma module_name = "?remove"
|
||||
int remove(const char *val)
|
||||
{
|
||||
#ifdef RT_USING_DFS
|
||||
dfs_file_unlink(val);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
62
components/libc/compilers/dlib/syscall_write.c
Normal file
62
components/libc/compilers/dlib/syscall_write.c
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* File : syscall_write.c
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006 - 2015, RT-Thread Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2015-01-28 Bernard first version
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
#ifdef RT_USING_DFS
|
||||
#include <dfs_posix.h>
|
||||
#endif
|
||||
#include <yfuns.h>
|
||||
|
||||
#pragma module_name = "?__write"
|
||||
|
||||
size_t __write(int handle, const unsigned char *buf, size_t len)
|
||||
{
|
||||
#ifdef RT_USING_DFS
|
||||
int size;
|
||||
#endif
|
||||
|
||||
if ((handle == _LLIO_STDOUT) || (handle == _LLIO_STDERR))
|
||||
{
|
||||
#ifndef RT_USING_CONSOLE
|
||||
return _LLIO_ERROR;
|
||||
#else
|
||||
rt_device_t console_device;
|
||||
|
||||
console_device = rt_console_get_device();
|
||||
if (console_device != 0) rt_device_write(console_device, 0, buf, len);
|
||||
|
||||
return len;
|
||||
#endif
|
||||
}
|
||||
|
||||
if (handle == _LLIO_STDIN) return -1;
|
||||
|
||||
#ifndef RT_USING_DFS
|
||||
return _LLIO_ERROR;
|
||||
#else
|
||||
size = write(handle - _LLIO_STDERR - 1, buf, len);
|
||||
return size;
|
||||
#endif
|
||||
}
|
||||
|
||||
23
components/libc/compilers/dlib/syscalls.h
Normal file
23
components/libc/compilers/dlib/syscalls.h
Normal file
@@ -0,0 +1,23 @@
|
||||
/* File: syscalls.h
|
||||
* this file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006 - 2015, RT-Thread Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2015-01-28 Bernard first version
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user