#include "strverscmp.h"
#include "quotearg.h"
#include "filemode.h"
+#include "path-concat.h"
#define obstack_chunk_alloc malloc
#define obstack_chunk_free free
static int file_interesting PARAMS ((const struct dirent *next));
static uintmax_t gobble_file PARAMS ((const char *name, int explicit_arg,
const char *dirname));
-static int is_not_dot_or_dotdot PARAMS ((const char *name));
static void print_color_indicator PARAMS ((const char *name, unsigned int mode,
int linkok));
static void put_indicator PARAMS ((const struct bin_str *ind));
}
#endif
+/* Return nonzero if base_name (NAME) ends in `.' or `..'
+ This is so we don't try to recurse on `././././. ...' */
+
+static int
+basename_is_dot_or_dotdot (const char *name)
+{
+ char *base = base_name (name);
+ return DOT_OR_DOTDOT (base);
+}
+
/* Remove any entries from `files' that are for directories,
and queue them to be listed as directories instead.
`dirname' is the prefix to prepend to each dirname
extract_dirs_from_files (const char *dirname, int recursive)
{
register int i, j;
- register char *path;
int dirlen;
dirlen = strlen (dirname) + 2;
order. */
for (i = files_index - 1; i >= 0; i--)
if ((files[i].filetype == directory || files[i].filetype == arg_directory)
- && (!recursive || is_not_dot_or_dotdot (files[i].name)))
+ && (!recursive || !basename_is_dot_or_dotdot (files[i].name)))
{
if (files[i].name[0] == '/' || dirname[0] == 0)
{
}
else
{
- path = (char *) xmalloc (strlen (files[i].name) + dirlen);
- attach (path, dirname, files[i].name);
+ char *path = path_concat (dirname, files[i].name, NULL);
queue_directory (path, files[i].linkname);
free (path);
}
files_index = j;
}
-/* Return nonzero if `name' doesn't end in `.' or `..'
- This is so we don't try to recurse on `././././. ...' */
-
-static int
-is_not_dot_or_dotdot (const char *name)
-{
- char *t;
-
- t = strrchr (name, '/');
- if (t)
- name = t + 1;
-
- if (name[0] == '.'
- && (name[1] == '\0'
- || (name[1] == '.' && name[2] == '\0')))
- return 0;
-
- return 1;
-}
-
/* Sort the files now in the table. */
static void
}
/* Put DIRNAME/NAME into DEST, handling `.' and `/' properly. */
+/* FIXME: maybe remove this function someday. See about using a
+ non-malloc'ing version of path_concat. */
static void
attach (char *dest, const char *dirname, const char *name)