s3-lib: introduce sys_realpath()
[amitay/samba.git] / source3 / lib / system.c
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.