This is an automated email from the ASF dual-hosted git repository.

acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new a2a542562f fs: Implment link as a normal function instead macro
a2a542562f is described below

commit a2a542562f3ed0301520f0ca7505db5b56f024e9
Author: Stuart Ianna <[email protected]>
AuthorDate: Mon Jan 23 09:14:48 2023 +1100

    fs: Implment link as a normal function instead macro
    
    so "using ::link;" can pass the compiling. This change also
    simplify the implementation of the hard link in the future.
---
 .../configs/wamr_wasi_debug/defconfig              |  1 +
 fs/vfs/Make.defs                                   |  2 +-
 fs/vfs/fs_link.c                                   | 64 ++++++++++++++++++++++
 include/sys/syscall_lookup.h                       |  1 +
 include/unistd.h                                   |  2 +-
 syscall/syscall.csv                                |  1 +
 6 files changed, 69 insertions(+), 2 deletions(-)

diff --git 
a/boards/xtensa/esp32/esp32-devkitc/configs/wamr_wasi_debug/defconfig 
b/boards/xtensa/esp32/esp32-devkitc/configs/wamr_wasi_debug/defconfig
index 0910713cd6..3440e18ef7 100644
--- a/boards/xtensa/esp32/esp32-devkitc/configs/wamr_wasi_debug/defconfig
+++ b/boards/xtensa/esp32/esp32-devkitc/configs/wamr_wasi_debug/defconfig
@@ -96,6 +96,7 @@ CONFIG_NSH_READLINE=y
 CONFIG_POSIX_SPAWN_DEFAULT_STACKSIZE=2048
 CONFIG_PREALLOC_MQ_MSGS=4
 CONFIG_PREALLOC_TIMERS=4
+CONFIG_PSEUDOFS_SOFTLINKS=y
 CONFIG_PTHREAD_MUTEX_TYPES=y
 CONFIG_RAM_SIZE=114688
 CONFIG_RAM_START=0x20000000
diff --git a/fs/vfs/Make.defs b/fs/vfs/Make.defs
index 20272d745d..5727636820 100644
--- a/fs/vfs/Make.defs
+++ b/fs/vfs/Make.defs
@@ -33,7 +33,7 @@ CSRCS += fs_fsync.c fs_truncate.c
 endif
 
 ifneq ($(CONFIG_PSEUDOFS_SOFTLINKS),0)
-CSRCS += fs_symlink.c fs_readlink.c
+CSRCS += fs_link.c fs_symlink.c fs_readlink.c
 endif
 
 # Stream support
diff --git a/fs/vfs/fs_link.c b/fs/vfs/fs_link.c
new file mode 100644
index 0000000000..864b0a9466
--- /dev/null
+++ b/fs/vfs/fs_link.c
@@ -0,0 +1,64 @@
+/****************************************************************************
+ * fs/vfs/fs_link.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <unistd.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#ifdef CONFIG_PSEUDOFS_SOFTLINKS
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: link
+ *
+ * Description:
+ *  The link function provides a wrapper to symlink. Solely to provide
+ *  compatibility to posix compatibility layer.
+ *
+ *  See symlink for details on limitations.
+ *
+ * Input Parameters:
+ *   path1 - Points to a pathname naming an existing file.
+ *   path2 - Points to a pathname naming the new directory entry to be
+ *           created.
+ *
+ * Returned Value:
+ *   On success, zero (OK) is returned.  Otherwise, -1 (ERROR) is returned
+ *   the errno variable is set appropriately.
+ *
+ ****************************************************************************/
+
+int link(FAR const char *path1, FAR const char *path2)
+{
+  return symlink(path1, path2);
+}
+
+#endif /* CONFIG_PSEUDOFS_SOFTLINKS */
diff --git a/include/sys/syscall_lookup.h b/include/sys/syscall_lookup.h
index 12a75bc014..4c44ea2919 100644
--- a/include/sys/syscall_lookup.h
+++ b/include/sys/syscall_lookup.h
@@ -252,6 +252,7 @@ SYSCALL_LOOKUP(futimens,                   2)
 SYSCALL_LOOKUP(munmap,                     2)
 
 #if defined(CONFIG_PSEUDOFS_SOFTLINKS)
+  SYSCALL_LOOKUP(link,                     2)
   SYSCALL_LOOKUP(symlink,                  2)
   SYSCALL_LOOKUP(readlink,                 3)
 #endif
diff --git a/include/unistd.h b/include/unistd.h
index 41c1125a6c..d219b3cf64 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -259,7 +259,6 @@
 
 /* Helpers and legacy compatibility definitions */
 
-#define link(p1, p2)                     symlink((p1), (p2))
 #define syncfs(f)                        fsync(f)
 #define fdatasync(f)                     fsync(f)
 #define getdtablesize(f)                 ((int)sysconf(_SC_OPEN_MAX))
@@ -372,6 +371,7 @@ int     access(FAR const char *path, int amode);
 int     rmdir(FAR const char *pathname);
 int     unlink(FAR const char *pathname);
 int     truncate(FAR const char *path, off_t length);
+int     link(FAR const char *path1, FAR const char *path2);
 int     symlink(FAR const char *path1, FAR const char *path2);
 ssize_t readlink(FAR const char *path, FAR char *buf, size_t bufsize);
 int     chown(FAR const char *path, uid_t owner, gid_t group);
diff --git a/syscall/syscall.csv b/syscall/syscall.csv
index eb054b0fec..dd3a221d43 100644
--- a/syscall/syscall.csv
+++ b/syscall/syscall.csv
@@ -50,6 +50,7 @@
 "kill","signal.h","","int","pid_t","int"
 "lchmod","sys/stat.h","","int","FAR const char *","mode_t"
 "lchown","unistd.h","","int","FAR const char *","uid_t","gid_t"
+"link","unistd.h","defined(CONFIG_PSEUDOFS_SOFTLINKS)","int","FAR const char 
*","FAR const char *"
 "listen","sys/socket.h","defined(CONFIG_NET)","int","int","int"
 "lseek","unistd.h","","off_t","int","off_t","int"
 "lstat","sys/stat.h","","int","FAR const char *","FAR struct stat *"

Reply via email to