Skip to content

Commit 19ef112

Browse files
committed
improve and beautify syscalls
1 parent 3ebb48f commit 19ef112

File tree

3 files changed

+42
-23
lines changed

3 files changed

+42
-23
lines changed

components/libc/compilers/armlibc/sys/types.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515

1616
typedef int32_t clockid_t;
1717
typedef int32_t key_t; /* Used for interprocess communication. */
18-
typedef int32_t pid_t; /* Used for process IDs and process group IDs. */
18+
typedef int pid_t; /* Used for process IDs and process group IDs. */
19+
typedef unsigned short uid_t;
20+
typedef unsigned short gid_t;
1921
#ifndef ARCH_CPU_64BIT
2022
typedef signed int ssize_t; /* Used for a count of bytes or an error indication. */
2123
#else

components/libc/compilers/dlib/sys/types.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414

1515
typedef int32_t clockid_t;
1616
typedef int32_t key_t; /* Used for interprocess communication. */
17-
typedef int32_t pid_t; /* Used for process IDs and process group IDs. */
17+
typedef int pid_t; /* Used for process IDs and process group IDs. */
18+
typedef unsigned short uid_t;
19+
typedef unsigned short gid_t;
1820
#ifndef ARCH_CPU_64BIT
1921
typedef signed int ssize_t; /* Used for a count of bytes or an error indication. */
2022
#else

components/libc/compilers/newlib/syscalls.c

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
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

@@ -38,7 +39,9 @@ int
3839
_close_r(struct _reent *ptr, int fd)
3940
{
4041
#ifndef RT_USING_DFS
41-
return 0;
42+
/* return "not supported" */
43+
ptr->_errno = ENOTSUP;
44+
return -1;
4245
#else
4346
return close(fd);
4447
#endif
@@ -85,11 +88,11 @@ _getpid_r(struct _reent *ptr)
8588
int
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

9598
int
@@ -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

@@ -125,7 +130,9 @@ int
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

@@ -138,7 +145,9 @@ int
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

@@ -164,7 +175,9 @@ int
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

@@ -184,7 +197,9 @@ int
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

@@ -197,6 +212,8 @@ int
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 */
239259
void *
@@ -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-
312327
mode_t umask(mode_t mask)
313328
{
314329
return 022;

0 commit comments

Comments
 (0)