Explorar o código

improve and beautify syscalls

Meco Man %!s(int64=4) %!d(string=hai) anos
pai
achega
19ef112016

+ 3 - 1
components/libc/compilers/armlibc/sys/types.h

@@ -15,7 +15,9 @@
 
 
 typedef int32_t          clockid_t;
 typedef int32_t          clockid_t;
 typedef int32_t          key_t;         /* Used for interprocess communication. */
 typedef int32_t          key_t;         /* Used for interprocess communication. */
-typedef int32_t          pid_t;         /* Used for process IDs and process group IDs. */
+typedef int              pid_t;         /* Used for process IDs and process group IDs. */
+typedef unsigned short   uid_t;
+typedef unsigned short   gid_t;
 #ifndef ARCH_CPU_64BIT
 #ifndef ARCH_CPU_64BIT
 typedef signed int       ssize_t;       /* Used for a count of bytes or an error indication. */
 typedef signed int       ssize_t;       /* Used for a count of bytes or an error indication. */
 #else
 #else

+ 3 - 1
components/libc/compilers/dlib/sys/types.h

@@ -14,7 +14,9 @@
 
 
 typedef int32_t          clockid_t;
 typedef int32_t          clockid_t;
 typedef int32_t          key_t;         /* Used for interprocess communication. */
 typedef int32_t          key_t;         /* Used for interprocess communication. */
-typedef int32_t          pid_t;         /* Used for process IDs and process group IDs. */
+typedef int              pid_t;         /* Used for process IDs and process group IDs. */
+typedef unsigned short   uid_t;
+typedef unsigned short   gid_t;
 #ifndef ARCH_CPU_64BIT
 #ifndef ARCH_CPU_64BIT
 typedef signed int       ssize_t;       /* Used for a count of bytes or an error indication. */
 typedef signed int       ssize_t;       /* Used for a count of bytes or an error indication. */
 #else
 #else

+ 36 - 21
components/libc/compilers/newlib/syscalls.c

@@ -7,12 +7,13 @@
  * Date           Author       Notes
  * Date           Author       Notes
  * 2021-02-11     Meco Man     remove _gettimeofday_r() and _times_r()
  * 2021-02-11     Meco Man     remove _gettimeofday_r() and _times_r()
  * 2020-02-13     Meco Man     re-implement exit() and abort()
  * 2020-02-13     Meco Man     re-implement exit() and abort()
+ * 2020-02-21     Meco Man     improve and beautify syscalls
  */
  */
 
 
 #include <reent.h>
 #include <reent.h>
-#include <sys/errno.h>
-#include <sys/time.h>
+#include <errno.h>
 #include <stdio.h>
 #include <stdio.h>
+#include <sys/time.h>
 
 
 #include <rtthread.h>
 #include <rtthread.h>
 
 
@@ -38,7 +39,9 @@ int
 _close_r(struct _reent *ptr, int fd)
 _close_r(struct _reent *ptr, int fd)
 {
 {
 #ifndef RT_USING_DFS
 #ifndef RT_USING_DFS
-    return 0;
+    /* return "not supported" */
+    ptr->_errno = ENOTSUP;
+    return -1;
 #else
 #else
     return close(fd);
     return close(fd);
 #endif
 #endif
@@ -85,11 +88,11 @@ _getpid_r(struct _reent *ptr)
 int
 int
 _isatty_r(struct _reent *ptr, int fd)
 _isatty_r(struct _reent *ptr, int fd)
 {
 {
-    if (fd >=0 && fd < 3) return 1;
+    if (fd >=0 && fd < 3)
+        return 1;
 
 
-    /* return "not supported" */
-    ptr->_errno = ENOTSUP;
-    return -1;
+    ptr->_errno = ENOTTY ;
+    return 0;
 }
 }
 
 
 int
 int
@@ -112,7 +115,9 @@ _off_t
 _lseek_r(struct _reent *ptr, int fd, _off_t pos, int whence)
 _lseek_r(struct _reent *ptr, int fd, _off_t pos, int whence)
 {
 {
 #ifndef RT_USING_DFS
 #ifndef RT_USING_DFS
-    return 0;
+    /* return "not supported" */
+    ptr->_errno = ENOTSUP;
+    return -1;
 #else
 #else
     _off_t rc;
     _off_t rc;
 
 
@@ -125,7 +130,9 @@ int
 _mkdir_r(struct _reent *ptr, const char *name, int mode)
 _mkdir_r(struct _reent *ptr, const char *name, int mode)
 {
 {
 #ifndef RT_USING_DFS
 #ifndef RT_USING_DFS
-    return 0;
+    /* return "not supported" */
+    ptr->_errno = ENOTSUP;
+    return -1;
 #else
 #else
     int rc;
     int rc;
 
 
@@ -138,7 +145,9 @@ int
 _open_r(struct _reent *ptr, const char *file, int flags, int mode)
 _open_r(struct _reent *ptr, const char *file, int flags, int mode)
 {
 {
 #ifndef RT_USING_DFS
 #ifndef RT_USING_DFS
-    return 0;
+    /* return "not supported" */
+    ptr->_errno = ENOTSUP;
+    return -1;
 #else
 #else
     int rc;
     int rc;
 
 
@@ -151,7 +160,9 @@ _ssize_t
 _read_r(struct _reent *ptr, int fd, void *buf, size_t nbytes)
 _read_r(struct _reent *ptr, int fd, void *buf, size_t nbytes)
 {
 {
 #ifndef RT_USING_DFS
 #ifndef RT_USING_DFS
-    return 0;
+    /* return "not supported" */
+    ptr->_errno = ENOTSUP;
+    return -1;
 #else
 #else
     _ssize_t rc;
     _ssize_t rc;
 
 
@@ -164,7 +175,9 @@ int
 _rename_r(struct _reent *ptr, const char *old, const char *new)
 _rename_r(struct _reent *ptr, const char *old, const char *new)
 {
 {
 #ifndef RT_USING_DFS
 #ifndef RT_USING_DFS
-    return 0;
+    /* return "not supported" */
+    ptr->_errno = ENOTSUP;
+    return -1;
 #else
 #else
     int rc;
     int rc;
 
 
@@ -184,7 +197,9 @@ int
 _stat_r(struct _reent *ptr, const char *file, struct stat *pstat)
 _stat_r(struct _reent *ptr, const char *file, struct stat *pstat)
 {
 {
 #ifndef RT_USING_DFS
 #ifndef RT_USING_DFS
-    return 0;
+    /* return "not supported" */
+    ptr->_errno = ENOTSUP;
+    return -1;
 #else
 #else
     int rc;
     int rc;
 
 
@@ -197,6 +212,8 @@ int
 _unlink_r(struct _reent *ptr, const char *file)
 _unlink_r(struct _reent *ptr, const char *file)
 {
 {
 #ifndef RT_USING_DFS
 #ifndef RT_USING_DFS
+    /* return "not supported" */
+    ptr->_errno = ENOTSUP;
     return -1;
     return -1;
 #else
 #else
     return unlink(file);
     return unlink(file);
@@ -211,11 +228,11 @@ _wait_r(struct _reent *ptr, int *status)
     return -1;
     return -1;
 }
 }
 
 
-#ifdef RT_USING_DEVICE
 _ssize_t
 _ssize_t
 _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes)
 _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes)
 {
 {
 #ifndef RT_USING_DFS
 #ifndef RT_USING_DFS
+#ifdef RT_USING_DEVICE
     if (fileno(stdout) == fd)
     if (fileno(stdout) == fd)
     {
     {
         rt_device_t console;
         rt_device_t console;
@@ -225,7 +242,11 @@ _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes)
     }
     }
 
 
     return 0;
     return 0;
-
+#else
+    /* return "not supported" */
+    ptr->_errno = ENOTSUP;
+    return -1;
+#endif /*RT_USING_DEVICE*/
 #else
 #else
     _ssize_t rc;
     _ssize_t rc;
 
 
@@ -233,7 +254,6 @@ _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes)
     return rc;
     return rc;
 #endif
 #endif
 }
 }
-#endif
 
 
 /* Memory routine */
 /* Memory routine */
 void *
 void *
@@ -304,11 +324,6 @@ void __libc_init_array(void)
     /* we not use __libc init_aray to initialize C++ objects */
     /* we not use __libc init_aray to initialize C++ objects */
 }
 }
 
 
-uid_t getuid(void)
-{
-    return 0;
-}
-
 mode_t umask(mode_t mask)
 mode_t umask(mode_t mask)
 {
 {
     return 022;
     return 022;