+ *result = path;
+ return length;
+}
+
+/* Return the leading directories part of PATH,
+ allocated with malloc. If out of memory, return 0.
+ Works properly even if there are trailing slashes
+ (by effectively ignoring them). */
+
+char *
+dir_name (char const *path)
+{
+ char const *result;
+ size_t length = dir_name_r (path, &result);
+ int append_dot = (length && length == FILESYSTEM_PREFIX_LEN (newpath));
+ char *newpath = (char *) malloc (length + append_dot + 1);