~ubuntu-branches/ubuntu/vivid/diffutils/vivid

« back to all changes in this revision

Viewing changes to src/dir.c

  • Committer: Bazaar Package Importer
  • Author(s): Santiago Vila
  • Date: 2010-02-13 11:49:00 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100213114900-09lz8jx6wct52qp8
Tags: 1:2.9-1
* New upstream release, now under GPL version 3 or later.
* There is now a --tab-size option. Closes: #82923.
* Manpage for cmp describes exit status. Closes: #200614.
* Manpage for diff describes exit status. Closes: #228441, #473233.
* The file de.po is now more recent. Closes: #313686.
* Fixed bad sdiff behaviour. Closes: #320222.
* Added wdiff to Suggests. Closes: #324627.
* Fixed cmp behaviour regarding stdout and stderr. Closes: #356083.
* The file ru.po is now more recent. Closes: #409274.
* The file es.po is now more recent. Closes: #418005, #481708.
* The file nl.po is now more recent. Closes: #427370.
* Modified watch file to use http instead of ftp.
* Removed .comment section from executables.
* Added Homepage field to control file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* Read, sort and compare two directories.  Used for GNU DIFF.
2
2
 
3
 
   Copyright (C) 1988, 1989, 1992, 1993, 1994, 1995, 1998, 2001, 2002,
4
 
   2004 Free Software Foundation, Inc.
 
3
   Copyright (C) 1988-1989, 1992-1995, 1998, 2001-2002, 2004, 2006-2007,
 
4
   2009-2010 Free Software Foundation, Inc.
5
5
 
6
6
   This file is part of GNU DIFF.
7
7
 
8
 
   GNU DIFF is free software; you can redistribute it and/or modify
 
8
   This program is free software: you can redistribute it and/or modify
9
9
   it under the terms of the GNU General Public License as published by
10
 
   the Free Software Foundation; either version 2, or (at your option)
11
 
   any later version.
 
10
   the Free Software Foundation, either version 3 of the License, or
 
11
   (at your option) any later version.
12
12
 
13
 
   GNU DIFF is distributed in the hope that it will be useful,
 
13
   This program is distributed in the hope that it will be useful,
14
14
   but WITHOUT ANY WARRANTY; without even the implied warranty of
15
15
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
16
   GNU General Public License for more details.
17
17
 
18
18
   You should have received a copy of the GNU General Public License
19
 
   along with this program; see the file COPYING.
20
 
   If not, write to the Free Software Foundation,
21
 
   59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
19
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
22
20
 
23
21
#include "diff.h"
24
22
#include <error.h>
38
36
  char *data;   /* Allocated storage for file names.  */
39
37
};
40
38
 
41
 
/* Whether file names in directories should be compared with strcoll.  */
 
39
/* Whether file names in directories should be compared with
 
40
   locale-specific sorting.  */
42
41
static bool locale_specific_sorting;
43
42
 
44
 
/* Where to go if strcoll fails.  */
45
 
static jmp_buf failed_strcoll;
 
43
/* Where to go if locale-specific sorting fails.  */
 
44
static jmp_buf failed_locale_specific_sorting;
46
45
 
47
46
static bool dir_loop (struct comparison const *, int);
48
47
static int compare_names_for_qsort (void const *, void const *);
76
75
      /* Open the directory and check for errors.  */
77
76
      register DIR *reading = opendir (dir->name);
78
77
      if (!reading)
79
 
        return 0;
 
78
        return false;
80
79
 
81
80
      /* Initialize the table of filenames.  */
82
81
 
90
89
      while ((errno = 0, (next = readdir (reading)) != 0))
91
90
        {
92
91
          char *d_name = next->d_name;
93
 
          size_t d_size = NAMLEN (next) + 1;
 
92
          size_t d_size = _D_EXACT_NAMLEN (next) + 1;
94
93
 
95
94
          /* Ignore "." and "..".  */
96
95
          if (d_name[0] == '.'
97
96
              && (d_name[1] == 0 || (d_name[1] == '.' && d_name[2] == 0)))
98
97
            continue;
99
98
 
100
 
          if (excluded_filename (excluded, d_name))
 
99
          if (excluded_file_name (excluded, d_name))
101
100
            continue;
102
101
 
103
102
          while (data_alloc < data_used + d_size)
116
115
          int e = errno;
117
116
          closedir (reading);
118
117
          errno = e;
119
 
          return 0;
 
118
          return false;
120
119
        }
121
120
#if CLOSEDIR_VOID
122
121
      closedir (reading);
123
122
#else
124
123
      if (closedir (reading) != 0)
125
 
        return 0;
 
124
        return false;
126
125
#endif
127
126
    }
128
127
 
137
136
      data += strlen (data) + 1;
138
137
    }
139
138
  names[nnames] = 0;
140
 
  return 1;
 
139
  return true;
141
140
}
142
141
 
143
142
/* Compare file names, returning a value compatible with strcmp.  */
157
156
        {
158
157
          error (0, errno, _("cannot compare file names `%s' and `%s'"),
159
158
                 name1, name2);
160
 
          longjmp (failed_strcoll, 1);
 
159
          longjmp (failed_locale_specific_sorting, 1);
161
160
        }
162
161
      return r;
163
162
    }
206
205
  if ((cmp->file[0].desc == -1 || dir_loop (cmp, 0))
207
206
      && (cmp->file[1].desc == -1 || dir_loop (cmp, 1)))
208
207
    {
209
 
      error (0, 0, "%s: recursive directory loop",
 
208
      error (0, 0, _("%s: recursive directory loop"),
210
209
             cmp->file[cmp->file[0].desc == -1].name);
211
210
      return EXIT_TROUBLE;
212
211
    }
226
225
      names[1] = dirdata[1].names;
227
226
 
228
227
      /* Use locale-specific sorting if possible, else native byte order.  */
229
 
      locale_specific_sorting = 1;
230
 
      if (setjmp (failed_strcoll))
231
 
        locale_specific_sorting = 0;
 
228
      locale_specific_sorting = true;
 
229
      if (setjmp (failed_locale_specific_sorting))
 
230
        locale_specific_sorting = false;
232
231
 
233
232
      /* Sort the directories.  */
234
233
      for (i = 0; i < 2; i++)
264
263
 
265
264
  for (i = 0; i < 2; i++)
266
265
    {
267
 
      if (dirdata[i].names)
268
 
        free (dirdata[i].names);
269
 
      if (dirdata[i].data)
270
 
        free (dirdata[i].data);
 
266
      free (dirdata[i].names);
 
267
      free (dirdata[i].data);
271
268
    }
272
269
 
273
270
  return val;
281
278
  struct comparison const *p = cmp;
282
279
  while ((p = p->parent))
283
280
    if (0 < same_file (&p->file[i].stat, &cmp->file[i].stat))
284
 
      return 1;
285
 
  return 0;
 
281
      return true;
 
282
  return false;
286
283
}