X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=index%2Fdir.c;h=6d0e11dd4d7a07a2d1162e6eb9e1138f103876a9;hb=c50c56ac38c5ec857c0d42143267005048ee96dd;hp=c643b40c2bd1917193ca53fc43e458aa3c2d2b5d;hpb=ca3782ca347f861af01437fca99d1009e73e6b7b;p=idzebra-moved-to-github.git diff --git a/index/dir.c b/index/dir.c index c643b40..6d0e11d 100644 --- a/index/dir.c +++ b/index/dir.c @@ -1,10 +1,19 @@ /* - * Copyright (C) 1994, Index Data I/S + * Copyright (C) 1995, Index Data I/S * All rights reserved. * Sebastian Hammer, Adam Dickmeiss * * $Log: dir.c,v $ - * Revision 1.1 1995-09-01 10:34:51 adam + * Revision 1.4 1995-09-04 12:33:41 adam + * Various cleanup. YAZ util used instead. + * + * Revision 1.3 1995/09/01 14:06:35 adam + * Split of work into more files. + * + * Revision 1.2 1995/09/01 10:57:07 adam + * Minor changes. + * + * Revision 1.1 1995/09/01 10:34:51 adam * Added dir.c * */ @@ -17,7 +26,7 @@ #include #include -#include +#include #include "index.h" struct dir_entry *dir_open (const char *rep) @@ -28,48 +37,52 @@ struct dir_entry *dir_open (const char *rep) size_t idx = 0; struct dir_entry *entry; - log (LOG_DEBUG, "dir_open %s", rep); + logf (LOG_DEBUG, "dir_open %s", rep); if (!(dir = opendir(rep))) { - log (LOG_WARN|LOG_ERRNO, "opendir %s", rep); + logf (LOG_WARN|LOG_ERRNO, "opendir %s", rep); if (errno != ENOENT) exit (1); return NULL; } if (!(entry = malloc (sizeof(*entry) * entry_max))) { - log (LOG_FATAL|LOG_ERRNO, "malloc"); + logf (LOG_FATAL|LOG_ERRNO, "malloc"); exit (1); } while ((dent = readdir (dir))) { + if (strcmp (dent->d_name, ".") == 0 || + strcmp (dent->d_name, "..") == 0) + continue; if (idx == entry_max-1) { struct dir_entry *entry_n; if (!(entry_n = malloc (sizeof(*entry) * (entry_max + 100)))) { - log (LOG_FATAL|LOG_ERRNO, "malloc"); + logf (LOG_FATAL|LOG_ERRNO, "malloc"); exit (1); } - memcpy (entry_n, entry, entry_max * sizeof(*entry)); + memcpy (entry_n, entry, idx * sizeof(*entry)); free (entry); entry = entry_n; entry_max += 100; } if (!(entry[idx].name = malloc (strlen(dent->d_name)+1))) { - log (LOG_FATAL|LOG_ERRNO, "malloc"); + logf (LOG_FATAL|LOG_ERRNO, "malloc"); exit (1); } strcpy (entry[idx].name, dent->d_name); + idx++; } entry[idx].name = NULL; closedir (dir); return entry; } -int dir_cmp (const void *p1, const void *p2) +static int dir_cmp (const void *p1, const void *p2) { return strcmp (((struct dir_entry *) p1)->name, ((struct dir_entry *) p2)->name); @@ -90,7 +103,7 @@ void dir_free (struct dir_entry **e_p) assert (e); while (e[i].name) - free (e[i].name); + free (e[i++].name); free (e); *e_p = NULL; }