77 * Date Author Notes
88 * 2021-02-11 Meco Man remove _gettimeofday_r() and _times_r()
99 * 2020-02-13 Meco Man re-implement exit() and abort()
10+ * 2020-02-21 Meco Man improve and beautify syscalls
1011 */
1112
1213#include <reent.h>
13- #include <sys/errno.h>
14- #include <sys/time.h>
14+ #include <errno.h>
1515#include <stdio.h>
16+ #include <sys/time.h>
1617
1718#include <rtthread.h>
1819
@@ -34,11 +35,19 @@ __errno ()
3435}
3536#endif
3637
38+ int
39+ _getpid_r (struct _reent * ptr )
40+ {
41+ return 0 ;
42+ }
43+
3744int
3845_close_r (struct _reent * ptr , int fd )
3946{
4047#ifndef RT_USING_DFS
41- return 0 ;
48+ /* return "not supported" */
49+ ptr -> _errno = ENOTSUP ;
50+ return -1 ;
4251#else
4352 return close (fd );
4453#endif
@@ -76,20 +85,14 @@ _fstat_r(struct _reent *ptr, int fd, struct stat *pstat)
7685 return -1 ;
7786}
7887
79- int
80- _getpid_r (struct _reent * ptr )
81- {
82- return 0 ;
83- }
84-
8588int
8689_isatty_r (struct _reent * ptr , int fd )
8790{
88- if (fd >=0 && fd < 3 ) return 1 ;
91+ if (fd >=0 && fd < 3 )
92+ return 1 ;
8993
90- /* return "not supported" */
91- ptr -> _errno = ENOTSUP ;
92- return -1 ;
94+ ptr -> _errno = ENOTTY ;
95+ return 0 ;
9396}
9497
9598int
@@ -112,7 +115,9 @@ _off_t
112115_lseek_r (struct _reent * ptr , int fd , _off_t pos , int whence )
113116{
114117#ifndef RT_USING_DFS
115- return 0 ;
118+ /* return "not supported" */
119+ ptr -> _errno = ENOTSUP ;
120+ return -1 ;
116121#else
117122 _off_t rc ;
118123
125130_mkdir_r (struct _reent * ptr , const char * name , int mode )
126131{
127132#ifndef RT_USING_DFS
128- return 0 ;
133+ /* return "not supported" */
134+ ptr -> _errno = ENOTSUP ;
135+ return -1 ;
129136#else
130137 int rc ;
131138
138145_open_r (struct _reent * ptr , const char * file , int flags , int mode )
139146{
140147#ifndef RT_USING_DFS
141- return 0 ;
148+ /* return "not supported" */
149+ ptr -> _errno = ENOTSUP ;
150+ return -1 ;
142151#else
143152 int rc ;
144153
@@ -151,7 +160,9 @@ _ssize_t
151160_read_r (struct _reent * ptr , int fd , void * buf , size_t nbytes )
152161{
153162#ifndef RT_USING_DFS
154- return 0 ;
163+ /* return "not supported" */
164+ ptr -> _errno = ENOTSUP ;
165+ return -1 ;
155166#else
156167 _ssize_t rc ;
157168
164175_rename_r (struct _reent * ptr , const char * old , const char * new )
165176{
166177#ifndef RT_USING_DFS
167- return 0 ;
178+ /* return "not supported" */
179+ ptr -> _errno = ENOTSUP ;
180+ return -1 ;
168181#else
169182 int rc ;
170183
184197_stat_r (struct _reent * ptr , const char * file , struct stat * pstat )
185198{
186199#ifndef RT_USING_DFS
187- return 0 ;
200+ /* return "not supported" */
201+ ptr -> _errno = ENOTSUP ;
202+ return -1 ;
188203#else
189204 int rc ;
190205
197212_unlink_r (struct _reent * ptr , const char * file )
198213{
199214#ifndef RT_USING_DFS
215+ /* return "not supported" */
216+ ptr -> _errno = ENOTSUP ;
200217 return -1 ;
201218#else
202219 return unlink (file );
@@ -211,11 +228,11 @@ _wait_r(struct _reent *ptr, int *status)
211228 return -1 ;
212229}
213230
214- #ifdef RT_USING_DEVICE
215231_ssize_t
216232_write_r (struct _reent * ptr , int fd , const void * buf , size_t nbytes )
217233{
218234#ifndef RT_USING_DFS
235+ #ifdef RT_USING_DEVICE
219236 if (fileno (stdout ) == fd )
220237 {
221238 rt_device_t console ;
@@ -225,15 +242,18 @@ _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes)
225242 }
226243
227244 return 0 ;
228-
245+ #else
246+ /* return "not supported" */
247+ ptr -> _errno = ENOTSUP ;
248+ return -1 ;
249+ #endif /*RT_USING_DEVICE*/
229250#else
230251 _ssize_t rc ;
231252
232253 rc = write (fd , buf , nbytes );
233254 return rc ;
234255#endif
235256}
236- #endif
237257
238258/* Memory routine */
239259void *
@@ -304,11 +324,6 @@ void __libc_init_array(void)
304324 /* we not use __libc init_aray to initialize C++ objects */
305325}
306326
307- uid_t getuid (void )
308- {
309- return 0 ;
310- }
311-
312327mode_t umask (mode_t mask )
313328{
314329 return 022 ;
@@ -320,7 +335,7 @@ int flock(int fd, int operation)
320335}
321336
322337/*
323- These functions will be implemented and replaced by the 'common/time.c' file
338+ These functions are implemented and replaced by the 'common/time.c' file
324339int _gettimeofday_r(struct _reent *ptr, struct timeval *__tp, void *__tzp);
325340_CLOCK_T_ _times_r(struct _reent *ptr, struct tms *ptms);
326341*/
0 commit comments