Deleted Added
full compact
savedir.c (126432) savedir.c (131554)
1/* savedir.c -- save the list of files in a directory in a string
1/* savedir.c -- save the list of files in a directory in a string
2 Copyright (C) 1990, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
2 Copyright (C) 1990, 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of

--- 50 unchanged lines hidden (view full) ---

61#ifndef NULL
62# define NULL 0
63#endif
64
65#ifndef stpcpy
66char *stpcpy ();
67#endif
68
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of

--- 50 unchanged lines hidden (view full) ---

61#ifndef NULL
62# define NULL 0
63#endif
64
65#ifndef stpcpy
66char *stpcpy ();
67#endif
68
69#include <fnmatch.h>
69#include "savedir.h"
70
70#include "savedir.h"
71
72char *path;
73size_t pathlen;
74
75static int
76isdir1 (const char *dir, const char *file)
77{
78 int status;
79 int slash;
80 size_t dirlen = strlen (dir);
81 size_t filelen = strlen (file);
82 if ((dirlen + filelen + 2) > pathlen)
83 {
84 path = calloc (dirlen + 1 + filelen + 1, sizeof (*path));
85 pathlen = dirlen + filelen + 2;
86 }
87 strcpy (path, dir);
88 slash = (path[dirlen] != '/');
89 path[dirlen] = '/';
90 strcpy (path + dirlen + slash , file);
91 status = isdir (path);
92 return status;
93}
94
71/* Return a freshly allocated string containing the filenames
72 in directory DIR, separated by '\0' characters;
73 the end is marked by two '\0' characters in a row.
74 NAME_SIZE is the number of bytes to initially allocate
75 for the string; it will be enlarged as needed.
76 Return NULL if DIR cannot be opened or if out of memory. */
95/* Return a freshly allocated string containing the filenames
96 in directory DIR, separated by '\0' characters;
97 the end is marked by two '\0' characters in a row.
98 NAME_SIZE is the number of bytes to initially allocate
99 for the string; it will be enlarged as needed.
100 Return NULL if DIR cannot be opened or if out of memory. */
77
78char *
101char *
79savedir (const char *dir, off_t name_size)
102savedir (const char *dir, off_t name_size, struct exclude *included_patterns,
103 struct exclude *excluded_patterns)
80{
81 DIR *dirp;
82 struct dirent *dp;
83 char *name_space;
84 char *namep;
85
86 dirp = opendir (dir);
87 if (dirp == NULL)

--- 16 unchanged lines hidden (view full) ---

104 {
105 /* Skip "." and ".." (some NFS filesystems' directories lack them). */
106 if (dp->d_name[0] != '.'
107 || (dp->d_name[1] != '\0'
108 && (dp->d_name[1] != '.' || dp->d_name[2] != '\0')))
109 {
110 off_t size_needed = (namep - name_space) + NAMLEN (dp) + 2;
111
104{
105 DIR *dirp;
106 struct dirent *dp;
107 char *name_space;
108 char *namep;
109
110 dirp = opendir (dir);
111 if (dirp == NULL)

--- 16 unchanged lines hidden (view full) ---

128 {
129 /* Skip "." and ".." (some NFS filesystems' directories lack them). */
130 if (dp->d_name[0] != '.'
131 || (dp->d_name[1] != '\0'
132 && (dp->d_name[1] != '.' || dp->d_name[2] != '\0')))
133 {
134 off_t size_needed = (namep - name_space) + NAMLEN (dp) + 2;
135
136 if ((included_patterns || excluded_patterns)
137 && !isdir1 (dir, dp->d_name))
138 {
139 if (included_patterns
140 && !excluded_filename (included_patterns, dp->d_name, 0))
141 continue;
142 if (excluded_patterns
143 && excluded_filename (excluded_patterns, dp->d_name, 0))
144 continue;
145 }
146
112 if (size_needed > name_size)
113 {
114 char *new_name_space;
115
116 while (size_needed > name_size)
117 name_size += 1024;
118
119 new_name_space = realloc (name_space, name_size);

--- 9 unchanged lines hidden (view full) ---

129 }
130 }
131 *namep = '\0';
132 if (CLOSEDIR (dirp))
133 {
134 free (name_space);
135 return NULL;
136 }
147 if (size_needed > name_size)
148 {
149 char *new_name_space;
150
151 while (size_needed > name_size)
152 name_size += 1024;
153
154 new_name_space = realloc (name_space, name_size);

--- 9 unchanged lines hidden (view full) ---

164 }
165 }
166 *namep = '\0';
167 if (CLOSEDIR (dirp))
168 {
169 free (name_space);
170 return NULL;
171 }
172 if (path)
173 {
174 free (path);
175 path = NULL;
176 pathlen = 0;
177 }
137 return name_space;
138}
178 return name_space;
179}