1
1
/* Read, sort and compare two directories. Used for GNU DIFF.
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.
6
6
This file is part of GNU DIFF.
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)
10
the Free Software Foundation, either version 3 of the License, or
11
(at your option) any later version.
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.
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/>. */
38
36
char *data; /* Allocated storage for file names. */
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;
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;
47
46
static bool dir_loop (struct comparison const *, int);
48
47
static int compare_names_for_qsort (void const *, void const *);
90
89
while ((errno = 0, (next = readdir (reading)) != 0))
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;
95
94
/* Ignore "." and "..". */
96
95
if (d_name[0] == '.'
97
96
&& (d_name[1] == 0 || (d_name[1] == '.' && d_name[2] == 0)))
100
if (excluded_filename (excluded, d_name))
99
if (excluded_file_name (excluded, d_name))
103
102
while (data_alloc < data_used + d_size)
158
157
error (0, errno, _("cannot compare file names `%s' and `%s'"),
160
longjmp (failed_strcoll, 1);
159
longjmp (failed_locale_specific_sorting, 1);
206
205
if ((cmp->file[0].desc == -1 || dir_loop (cmp, 0))
207
206
&& (cmp->file[1].desc == -1 || dir_loop (cmp, 1)))
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;
226
225
names[1] = dirdata[1].names;
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;
233
232
/* Sort the directories. */
234
233
for (i = 0; i < 2; i++)