Răsfoiți Sursa

complete fs interface

0BitBiscuits 1 an în urmă
părinte
comite
d8a51bb59a

+ 1 - 0
include/assert.h

@@ -15,6 +15,7 @@
 #define assert(expr)((void) 0)
 #else
 void __assert_fail (const char* expr, const char* file, int line);
+void __assert_func(const char *file, int line, const char *func, const char *failedexpr);
 
 #define assert(expr) \
     if (!(expr)) \

+ 9 - 0
include/setjmp.h

@@ -0,0 +1,9 @@
+#ifndef MLIBC_SETJMP_H__
+#define MLIBC_SETJMP_H__
+
+#define jmp_buf_t long *
+
+int setjmp(jmp_buf_t env);
+void longjmp(jmp_buf_t env, int val);
+
+#endif

+ 2 - 0
include/stdlib.h

@@ -114,4 +114,6 @@ long strtol(const char *nptr, char **endptr, int base);
 llong_type strtoll(const char *nptr, char **endptr, int base);
 unsigned long strtoul(const char *nptr, char **endptr, int base);
 ullong_type strtoull(const char *nptr, char **endptr, int base);
+void abort(void);
+void exit(int status);
 #endif /*MLIBC_STDLIB_H__*/

+ 1 - 0
include/time.h

@@ -56,6 +56,7 @@ struct itimerspec {
 
 struct tm *gmtime_r(const time_t *timep, struct tm *r);
 struct tm* localtime_r(const time_t* t, struct tm* r);
+size_t strftime(char *s, size_t maxsize, const char *format, const struct tm *tp);
 
 time_t mktime(struct tm* const t);
 char* ctime(const time_t* tim_p);

+ 3 - 3
src/internal/syscall.h

@@ -10,9 +10,9 @@ typedef struct
 } iovec;
 
 /* Filesystem call*/
-int __mlibc_fcntl(int fd, int cmd, ...);
-int __mlibc_ioctl(int fd, unsigned long req, ...);
-ssize_t __mlibc_readv(int fd, iovec *iov, size_t iov_size);
+int __mlibc_sys_fcntl(int fd, int cmd, ...);
+int __mlibc_sys_ioctl(int fd, int cmd, ...);
+ssize_t __mlibc_sys_readv(int fd, iovec *iov, size_t iov_size);
 ssize_t __mlibc_sys_read(int fd, unsigned char *buf, size_t buf_size);
 ssize_t __mlibc_sys_writev(int fd, iovec *iov, size_t iov_size);
 int __mlibc_sys_close(int fd);

+ 0 - 23
src/rtthread/__mlibc_fcntl.c

@@ -1,23 +0,0 @@
-#include "../internal/syscall.h"
-#include <fcntl.h>
-#include <errno.h>
-#include <dfs_file.h>
-#include <rtthread.h>
-
-int __mlibc_fcntl(int fd, int cmd, ...);
-
-static long do_fcntl(int fd, unsigned int cmd, unsigned int cmd, unsigned long arg, 
-        struct dfs_file* filp)
-{
-    
-}
-
-
-
-
-
-
-
-
-
-

+ 23 - 0
src/rtthread/__mlibc_sys_close.c

@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) mlibc & plct lab
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2024/5/6   0Bitbiscuits  realize sys_close
+ */
+#include "../internal/syscall.h"
+#include <dfs_file.h>
+#include <errno.h>
+
+/**
+ * @brief the function will close the open file descriptor.
+ * 
+ * @param fd the file descriptor
+ * @return int 0 on successful, -1 on failed.
+ */
+int __mlibc_sys_close(int fd)
+{
+    return close(fd);
+}

+ 34 - 0
src/rtthread/__mlibc_sys_fcntl.c

@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) mlibc & plct lab
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2024/5/6       0Bitbiscuits    realize fcntl
+ */
+#include "../internal/syscall.h"
+#include <stdarg.h>
+#include <dfs_file.h>
+
+/**
+ * @brief this function is a POSIX compliant version, which shall perform a variety of
+ * control functions on devices.
+ * 
+ * @param fd file descriptor
+ * @param cmd file operation command
+ * @param ... operation args
+ * @return int 0 on successful completion. Otherwise, -1 shall be returned and errno
+ * set to indicate the error.
+ */
+int __mlibc_sys_fcntl(int fd, int cmd, ...)
+{
+    int res = 0;
+    va_list args;
+
+    va_start(args, cmd);
+    res = fcntl(fd, cmd, args);
+    va_end(args);
+
+    return res;
+}

+ 27 - 0
src/rtthread/__mlibc_sys_ioctl.c

@@ -0,0 +1,27 @@
+#include "../internal/syscall.h"
+#include <stdarg.h>
+#include <dfs_file.h>
+
+/**
+ * @brief  * this function is a POSIX compliant version, which shall perform a variety of
+ * control functions on devices.
+ * 
+ * @param fildes the file description
+ * @param cmd the specified command
+ * @param ... represents the additional information that is needed by this
+ * specific device to perform the requested function.
+ *
+ * @return 0 on successful completion. Otherwise, -1 shall be returned and errno
+ * set to indicate the error.
+ */
+int __mlibc_sys_ioctl(int fd, int cmd, ...)
+{
+    int res = 0;
+    va_list args;
+
+    va_start(args, cmd);
+    res = ioctl(fd, cmd, args);
+    va_end(args);
+
+    return res;
+}

+ 24 - 0
src/rtthread/__mlibc_sys_read.c

@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) mlibc & plct lab
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2024/5/6    0Bitbiscuits  realize sys_read
+ */
+#include "../internal/syscall.h"
+#include <dfs_file.h>
+
+/**
+ * @brief The function is used to read data from a file descriptor into the buffer.
+ * 
+ * @param fd the file descriptor
+ * @param buf buffer
+ * @param buf_size buffer size
+ * @return ssize_t The number of bytes read, which returns -1 if the read operation fails.
+ */
+ssize_t __mlibc_sys_read(int fd, unsigned char *buf, size_t buf_size)
+{
+    return read(fd, buf, buf_size);
+}

+ 43 - 0
src/rtthread/__mlibc_sys_readv.c

@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) mlibc & plct lab
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2024/5/6    0Bitbiscuits  realize sys_readv
+ */
+#include "../internal/syscall.h"
+#include <dfs_file.h>
+#include <errno.h>
+
+/**
+ * @brief The function is used to read data from a file descriptor into multiple buffers.
+ * 
+ * @param fd the file descriptor.
+ * @param iov buffer array
+ * @param iov_size the number of buffer
+ * @return ssize_t The number of bytes read, which returns -1 if the read operation fails.
+ */
+ssize_t __mlibc_sys_readv(int fd, iovec *iov, size_t iov_size)
+{
+    int i = 0;
+    ssize_t cnt = 0;
+    ssize_t ret = -EBADF;
+
+    for(; i < iov_size; ++i)
+    {
+        ret = read(fd, iov[i].buf, iov[i].buf_size);
+        if(ret <= 0)
+        {
+            break;
+        }
+        cnt += ret;
+    }
+
+    if(ret < 0)
+    {
+        return ret;
+    }
+    return cnt;
+}

+ 44 - 0
src/rtthread/__mlibc_sys_writev.c

@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) mlibc & plct lab
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2024/5/6   0Bitbiscuits  realize sys_writev
+ */
+#include "../internal/syscall.h"
+#include <dfs_file.h>
+#include <errno.h>
+
+/**
+ * @brief Write data from multiple buffers to a file.
+ * 
+ * @param fd the file descriptor.
+ * @param iov buffer array
+ * @param iov_size the number of buffer
+ * @return ssize_t The number of bytes write, which returns -1 if the write operation fails
+ */
+ssize_t __mlibc_sys_writev(int fd, iovec *iov, size_t iov_size)
+{
+    int i = 0;
+    ssize_t cnt = 0;
+    ssize_t ret = -EBADF;
+
+    for(; i < iov_size; i++)
+    {
+        ret = write(fd, (iov + i)->buf, (iov + i)->buf_size);
+        if(ret <= 0)
+        {
+            break;
+        }
+        cnt += ret;
+    }
+
+    if(ret < 0)
+    {
+        return ret;
+    }
+    
+    return cnt;
+}

+ 23 - 0
src/setjmp.c

@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) mlibc & plct lab
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2024/5/6    0Bitbiscuits  undefine
+ */
+#include <setjmp.h>
+
+
+int setjmp(jmp_buf_t env)
+{
+    return 0;
+}
+
+void longjmp(jmp_buf_t env, int val)
+{
+    return;
+}
+
+

+ 10 - 0
src/stdio/SConscript

@@ -0,0 +1,10 @@
+from building import *
+import os
+
+cwd     = GetCurrentDir()
+src     = Glob('*.c')
+CPPPATH = [cwd]
+
+group = DefineGroup('__mlibc_stdio', src, depend = [''], CPPPATH = CPPPATH)
+
+Return('group')

+ 0 - 0
src/stdio.c → src/stdio/stdio.c


+ 2 - 0
src/time.c

@@ -8,3 +8,5 @@
  */
 
 #include <stdint.h>
+#include <time.h>
+