yamt commented on code in PR #8868:
URL: https://github.com/apache/nuttx/pull/8868#discussion_r1161477288


##########
arch/sim/Kconfig:
##########
@@ -159,6 +159,15 @@ config SIM_HOSTFS
        ---help---
                Access host filesystem through HostFS.
 
+if SIM_HOSTFS
+config SIM_HOSTFS_PATH_CONVERSION
+bool "Simulated HostFS path conversion"
+default n
+---help---
+       If this option is enabled, the nuttx image folder will be used as the 
root path
+       when hostfs accesses the file, otherwise $CWD will be used as the root 
path to search

Review Comment:
   my understanding is this option doesn't affect `mount -t hostfs -o 
fs=/absolutepath /mnt`. right?
   this description makes me think otherwise.
   especially the term `the root path` gives me an impression it changes the 
behavior of absolute paths.



##########
arch/sim/src/sim/posix/sim_hostfs.c:
##########
@@ -36,10 +36,66 @@
 
 #include "hostfs.h"
 
+#ifdef CONFIG_HOST_MACOS
+#include <sys/syslimits.h>
+#include <mach-o/dyld.h>
+#endif
+
 /****************************************************************************
  * Private Functions
  ****************************************************************************/
 
+/****************************************************************************
+ * Name: host_path_convert
+ ****************************************************************************/
+
+static int host_path_convert(const char *path, char *abspath,
+                             uint32_t buflen)
+{
+#ifndef CONFIG_SIM_HOSTFS_PATH_CONVERSION
+      strncpy(abspath, path, buflen);
+      abspath[buflen - 1] = '\0';
+      return 0;
+#else
+  int ret;
+  char *name;
+
+  if (path[0] == '/')
+    {
+      strncpy(abspath, path, buflen);
+      abspath[buflen - 1] = '\0';
+      return 0;
+    }
+
+  /* Get the absolute path of the executable file */
+
+#  ifdef CONFIG_HOST_LINUX
+  ret = readlink("/proc/self/exe", abspath, buflen);

Review Comment:
   isn't it simpler to use chdir(2)?
   or maybe even openat family?
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to