1
Patch for #452068: wanted: 'ftwhich' option to not print links or symlinks
3
diff -Nur whichman-2.4.old/ftwhich.c whichman-2.4/ftwhich.c
4
--- whichman-2.4.old/ftwhich.c 2001-05-04 22:56:04.000000000 +0200
5
+++ whichman-2.4/ftwhich.c 2008-01-27 14:46:54.000000000 +0100
10
+#include "statduplcheck.h"
13
static char **splitpath();
15
matchfilename(*pathcomp, searchkey);
19
+ free_statduplicates();
21
return (nomatchfound);
25
if ((stbuf.st_mode & S_IFREG)==0) return(0);
26
/* test if executable for user or grp or others */
27
if ((stbuf.st_mode & S_IXUSR) || (stbuf.st_mode & S_IXGRP)\
28
- ||(stbuf.st_mode & S_IXOTH)) return(1);
30
+ ||(stbuf.st_mode & S_IXOTH))
31
+ if (is_statduplicate(&stbuf)) return(0);
35
* match all entries in the directory variable path points to
36
diff -Nur whichman-2.4.old/Makefile whichman-2.4/Makefile
37
--- whichman-2.4.old/Makefile 2008-01-27 14:45:55.000000000 +0100
38
+++ whichman-2.4/Makefile 2008-01-27 14:46:54.000000000 +0100
41
all:whichman ftff ftwhich
43
-whichman: whichman.o levdist.o
44
- $(CC) -o $@ whichman.o levdist.o
45
+whichman: whichman.o levdist.o statduplcheck.o
46
+ $(CC) -o $@ whichman.o levdist.o statduplcheck.o
48
-ftwhich: ftwhich.o levdist.o
49
- $(CC) -o $@ ftwhich.o levdist.o
50
+ftwhich: ftwhich.o levdist.o statduplcheck.o
51
+ $(CC) -o $@ ftwhich.o levdist.o statduplcheck.o
53
ftff: ftff.o levdist.o
54
$(CC) -o $@ ftff.o levdist.o
56
$(CC) $(CFLAGS) -c ftff.c
57
levdist.o: levdist.c levdist.h
58
$(CC) $(CFLAGS) -c levdist.c
59
+statduplcheck.o: statduplcheck.c statduplcheck.h
60
+ $(CC) $(CFLAGS) -c statduplcheck.c
62
install: whichman ftff ftwhich $(MANP)
64
diff -Nur whichman-2.4.old/statduplcheck.c whichman-2.4/statduplcheck.c
65
--- whichman-2.4.old/statduplcheck.c 1970-01-01 01:00:00.000000000 +0100
66
+++ whichman-2.4/statduplcheck.c 2008-01-27 14:46:54.000000000 +0100
68
+#define _GNU_SOURCE /* for tdestroy */
69
+#include "statduplcheck.h"
81
+static void * info_root = NULL;
83
+/* compare function passed to tsearch */
84
+static int stat_info_compare(const void *si1, const void * si2)
88
+ res = ((struct stat_info*)si1)->st_dev - ((struct stat_info*)si2)->st_dev;
90
+ res = ((struct stat_info*)si1)->st_ino - ((struct stat_info*)si2)->st_ino;
94
+int is_statduplicate(const struct stat *st) {
95
+ static struct stat_info * stinfo = NULL;
96
+ struct stat_info ** res;
99
+ stinfo = (struct stat_info*) malloc (sizeof(*stinfo));
102
+ fprintf(stderr, "cannot allocate memory\n");
108
+ stinfo->st_dev = st->st_dev;
109
+ stinfo->st_ino = st->st_ino;
111
+ if (!(res = tsearch(stinfo, &info_root, stat_info_compare))) {
112
+ fprintf(stderr, "cannot allocate memory\n");
116
+ if (*res == stinfo) {
125
+int is_fileduplicate(const char *dir, const char *name) {
126
+ static struct stat stbuf;
127
+ static char fullpath[255];
129
+ if (strlen(dir) + strlen(name) + 2 > sizeof(fullpath)) return (-1);
130
+ strcpy(fullpath, dir);
131
+ strcat(fullpath, "/");
132
+ strcat(fullpath, name);
134
+ if (stat(fullpath,&stbuf)!=0) return(-1); /* file does not exists */
136
+ return is_statduplicate(&stbuf);
140
+void free_statduplicates(void) {
142
+ if (!info_root) return;
144
+ tdestroy(info_root, free);
152
diff -Nur whichman-2.4.old/statduplcheck.h whichman-2.4/statduplcheck.h
153
--- whichman-2.4.old/statduplcheck.h 1970-01-01 01:00:00.000000000 +0100
154
+++ whichman-2.4/statduplcheck.h 2008-01-27 14:46:54.000000000 +0100
156
+#ifndef STATDUPLCHECK_H
157
+#define STATDUPLCHECK_H
159
+#include <sys/stat.h>
161
+extern int is_statduplicate(const struct stat *st);
162
+extern int is_fileduplicate(const char *dir, const char *name);
163
+extern void free_statduplicates(void);
167
diff -Nur whichman-2.4.old/whichman.c whichman-2.4/whichman.c
168
--- whichman-2.4.old/whichman.c 2008-01-27 14:45:55.000000000 +0100
169
+++ whichman-2.4/whichman.c 2008-01-27 14:46:54.000000000 +0100
174
+#include "statduplcheck.h"
177
static char **splitman();
179
findmandir(*pathcomp, searchkey);
183
+ free_statduplicates();
184
return (nomanfilefound);
188
/* xxxxx.1.gz ->xxxxx :*/
189
manname=removemanextesions(entry->d_name);
190
d=stringmatch(manname,key);
192
+ if (d != -1 && !is_fileduplicate(path, entry->d_name) ){
193
if (printdist) printf("%03d ",d);
194
printf("%s/%s\n", path, entry->d_name);