aboutsummaryrefslogtreecommitdiffstats
path: root/misc/mc/files/patch-src-find.c
blob: 072b11eb452e1bbdd4e17dcf9c32994c483df5f9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
--- src/find.c.orig Tue Dec 24 17:28:26 2002
+++ src/find.c  Tue Jun 15 03:15:09 2004
@@ -312,7 +312,7 @@
     dir_stack *new;
 
     new = g_new (dir_stack, 1);
-    new->name = g_strdup (dir);
+    new->name = concat_dir_and_file (dir, "");
     new->prev = dir_stack_base;
     dir_stack_base = new;
 }
@@ -338,17 +338,9 @@
 {
     char *tmp_name;
     static char *dirname;
-    int i;
 
-    if (dir [0] == PATH_SEP && dir [1] == PATH_SEP)
+    while (dir [0] == PATH_SEP && dir [1] == PATH_SEP)
    dir++;
-    i = strlen (dir);
-    if (i){
-   if (dir [i - 1] != PATH_SEP){
-       dir [i] = PATH_SEP;
-       dir [i + 1] = 0;
-   }
-    }
 
     if (old_dir){
    if (strcmp (old_dir, dir)){
@@ -401,7 +393,7 @@
     char ch = 0;
     int  i = 0;
 
-    do {
+    for (;;) {
    if (*pos >= *n_read){
        *pos = 0;
        if ((*n_read = mc_read (file_fd, buf, buf_size)) <= 0)
@@ -420,10 +412,12 @@
    if (i >= buffer_size - 1){
        buffer = g_realloc (buffer, buffer_size += 80);
    }
+   /* Strip newline to fix $ matching */
+   if (ch == '\n')
+       break;
 
    buffer [i++] = ch;
-
-    } while (ch != '\n');
+    }
 
     *has_newline = ch ? 1 : 0;
 
@@ -502,7 +496,7 @@
 {
     static struct dirent *dp   = 0;
     static DIR  *dirp = 0;
-    static char directory [MC_MAXPATHLEN+2];
+    static char *directory;
     struct stat tmp_stat;
     static int pos;
     static int subdirs_left = 0;
@@ -513,6 +507,10 @@
        mc_closedir (dirp);
        dirp = 0;
    }
+   if (directory) {
+       g_free (directory);
+       directory = NULL;
+   }
         dp = 0;
    return 1;
     }
@@ -550,8 +548,9 @@
            break;
        } 
        
-       strcpy (directory, tmp);
-       g_free (tmp);
+       if (directory)
+       g_free (directory);
+       directory = tmp;
 
        if (verbose){
            char buffer [BUF_SMALL];
@@ -582,8 +581,8 @@
     tmp_name = concat_dir_and_file (directory, dp->d_name);
 
     if (subdirs_left){
-   mc_lstat (tmp_name, &tmp_stat);
-   if (S_ISDIR (tmp_stat.st_mode)){
+   if (!mc_lstat (tmp_name, &tmp_stat)
+       && S_ISDIR (tmp_stat.st_mode)){
        push_directory (tmp_name);
        subdirs_left--;
    }