Partially sync files.el from XEmacs 21.5 for wildcard support.
[sxemacs] / src / dired.c
index 3b0af90..8cec22b 100644 (file)
@@ -1,4 +1,4 @@
- /* Lisp functions for making directory listings.
+/* Lisp functions for making directory listings.
     Copyright (C) 1985, 1986, 1992, 1993, 1994 Free Software Foundation, Inc.
 
 This file is part of SXEmacs
@@ -128,10 +128,12 @@ static int pathname_matches_p(Lisp_Object, Lisp_Object,
 static char *
 dired_realpath(const char *file)
 {
-       char *result = xmalloc_atomic(4096);    
-
-       realpath(file, result);
+       char *result = xmalloc_atomic(4096);
 
+       if ( realpath(file, result) == NULL ) {
+               xfree(result);
+               result = NULL;
+       }
        return result;
 }
 #endif
@@ -247,10 +249,11 @@ dfr_inner(dirent_t *res,
                 * store it to our companion bloom filter
                 */
                canon_name = CANONICALISE_FILENAME(statnam);
-
-               /* now, recycle full name */
-               fullname = make_ext_string(
-                       canon_name, strlen(canon_name), Qfile_name);
+               if (canon_name) {
+                       /* now, recycle full name */
+                       fullname = make_ext_string(
+                               canon_name, strlen(canon_name), Qfile_name);
+               }
                fullname = fname_as_directory(fullname);
 
                /* now stat statnam */
@@ -283,10 +286,12 @@ dfr_inner(dirent_t *res,
                 */
                canon_name = CANONICALISE_FILENAME(statnam);
 
-               /* now, recycle full name */
-               fullname = make_ext_string(
-                       canon_name, strlen(canon_name),
-                       Qfile_name);
+               if (canon_name) {
+                       /* now, recycle full name */
+                       fullname = make_ext_string(
+                               canon_name, strlen(canon_name),
+                               Qfile_name);
+               }
                fullname = fname_as_directory(fullname);
 
                /* now stat statnam */
@@ -323,7 +328,7 @@ dfr_inner(dirent_t *res,
           - With the former variant it is NOT possible to have
           the trivial filenames on the result list, since a
           match against "^[.]$" would exclude everything, while
-          actually it was likely meant to _solely_ exclude "." 
+          actually it was likely meant to _solely_ exclude "."
           from the result list
           - Furthermore, we _MUST_ traverse in preorder,
           otherwise there is the possibility that pathnames are
@@ -356,7 +361,7 @@ dfr_inner(dirent_t *res,
        }
 
 #if USE_MATCH_ARG
-       if (!NILP(match) && !pathname_matches_p(name, match, bufp)) {
+       if (!NILP(match) && bufp && !pathname_matches_p(name, match, bufp)) {
                result_p = 0;
        }
 #endif
@@ -576,7 +581,7 @@ directory_files_resultify(Lisp_Object result, Lisp_Object result_type)
        } else if (EQ(result_type, Qdesc_sorted_list)) {
                final_result = Fdllist_to_list(result);
                final_result = Fsort(final_result, Qstring_greaterp);
-       } else if (EQ(result_type, Qt) || EQ(result_type, Qlist)) {
+       } else if (!NILP(result_type) || EQ(result_type, Qlist)) {
                final_result = Fdllist_to_list(result);
        }
 
@@ -629,6 +634,10 @@ Optional argument RESULT-TYPE can be one of:
 The two latter types can be useful if you plan to sort the result
 yourself, or want to feed the result to further processing.
 
+For compatibility with XEmacs' NOSORT argument to this function,
+RESULT-TYPE can also be any non-nil value.  In that case it will
+return an unsorted list. (http://issues.sxemacs.org/show_bug.cgi?id=163)
+
 Optional argument FILES-ONLY can be one of:
 - t  to return only files and symlinks in DIRECTORY
 - nil (default)  to return all entries (files, symlinks, and
@@ -702,7 +711,7 @@ Optional argument MAXDEPTH \(a positive integer\) specifies the
 maximal recursion depth, use 0 to emulate old `directory-files'.
 
 Optional argument SYMLINK-IS-FILE specifies whether symlinks
-should be resolved \(which is the default behaviour\) or whether 
+should be resolved \(which is the default behaviour\) or whether
 they are treated as ordinary files \(non-nil\), in the latter
 case symlinks to directories are not recurred.
 
@@ -1050,8 +1059,8 @@ file_name_completion(Lisp_Object file, Lisp_Object directory, int all_flag,
                                               ==
                                               XSTRING_CHAR_LENGTH(bestmatch)))
                                             /* If there is more than one exact match aside from
-                                               case, and one of them is exact including case,
-                                               prefer that one.  */
+                                               case, and one of them is exact including case,
+                                               prefer that one.  */
                                             && 0 > scmp_1(p2,
                                                           XSTRING_DATA(file),
                                                           file_name_length, 0)