s3-lib: introduce sys_realpath()
authorUri Simchoni <uri@samba.org>
Mon, 18 Jan 2016 21:34:06 +0000 (23:34 +0200)
committerJeremy Allison <jra@samba.org>
Tue, 26 Jan 2016 23:22:22 +0000 (00:22 +0100)
Add sys_realpath() function that captures the OS variations
on realpath().

Signed-off-by: Uri Simchoni <uri@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/include/proto.h
source3/lib/system.c
source3/modules/vfs_default.c

index e18aaf4811583db4b17109856d76473a07579685..09e991507fcb3f6617e6dd35326ae391b73e56ce 100644 (file)
@@ -264,6 +264,7 @@ int sys_setxattr (const char *path, const char *name, const void *value, size_t
 int sys_fsetxattr (int filedes, const char *name, const void *value, size_t size, int flags);
 uint32_t unix_dev_major(SMB_DEV_T dev);
 uint32_t unix_dev_minor(SMB_DEV_T dev);
+char *sys_realpath(const char *path);
 #if 0
 int sys_get_number_of_cores(void);
 #endif
index e54b946d33c0c0fbd252ff0427dbf4435aeaf041..0351e376265f386482ac0492bb94dd61c516e065 100644 (file)
@@ -1236,6 +1236,31 @@ uint32_t unix_dev_minor(SMB_DEV_T dev)
 #endif
 }
 
+/**************************************************************************
+ Wrapper for realpath.
+****************************************************************************/
+
+char *sys_realpath(const char *path)
+{
+       char *result;
+
+#ifdef REALPATH_TAKES_NULL
+       result = realpath(path, NULL);
+#else
+       result = SMB_MALLOC_ARRAY(char, PATH_MAX + 1);
+       if (result) {
+               char *resolved_path = realpath(path, result);
+               if (!resolved_path) {
+                       SAFE_FREE(result);
+               } else {
+                       /* SMB_ASSERT(result == resolved_path) ? */
+                       result = resolved_path;
+               }
+       }
+#endif
+       return result;
+}
+
 #if 0
 /*******************************************************************
  Return the number of CPUs.
index 2eb9a1794a08688243c768d8e3302c6188557ef0..762624bec66d68a8e2ffe7d058f62e038e9bcffc 100644 (file)
@@ -2145,20 +2145,7 @@ static char *vfswrap_realpath(vfs_handle_struct *handle, const char *path)
        char *result;
 
        START_PROFILE(syscall_realpath);
-#ifdef REALPATH_TAKES_NULL
-       result = realpath(path, NULL);
-#else
-       result = SMB_MALLOC_ARRAY(char, PATH_MAX+1);
-       if (result) {
-               char *resolved_path = realpath(path, result);
-               if (!resolved_path) {
-                       SAFE_FREE(result);
-               } else {
-                       /* SMB_ASSERT(result == resolved_path) ? */
-                       result = resolved_path;
-               }
-       }
-#endif
+       result = sys_realpath(path);
        END_PROFILE(syscall_realpath);
        return result;
 }