filan -s prefixes output with FD number if more than one FD

This commit is contained in:
Gerhard Rieger 2008-02-11 21:54:01 +01:00
parent d70b8963aa
commit 9809b977e2
4 changed files with 26 additions and 11 deletions

View file

@ -35,6 +35,9 @@ corrections:
replaced the select() calls by poll() to cleanly fix the problems with replaced the select() calls by poll() to cleanly fix the problems with
many file descriptors already open many file descriptors already open
further changes:
filan -s prefixes output with FD number if more than one FD
####################### V 1.6.0.1: ####################### V 1.6.0.1:
new features: new features:

View file

@ -1,5 +1,5 @@
/* source: fdname.c */ /* source: fdname.c */
/* Copyright Gerhard Rieger 2003-2007 */ /* Copyright Gerhard Rieger 2003-2008 */
/* Published under the GNU General Public License V.2, see file COPYING */ /* Published under the GNU General Public License V.2, see file COPYING */
/* the subroutine sockname prints the basic info about the address of a socket /* the subroutine sockname prints the basic info about the address of a socket
@ -32,7 +32,7 @@ int unixame(int fd, FILE *outfile);
int tcpname(int fd, FILE *outfile); int tcpname(int fd, FILE *outfile);
int fdname(const char *file, int fd, FILE *outfile) { int fdname(const char *file, int fd, FILE *outfile, const char *numform) {
struct stat buf = {0}; struct stat buf = {0};
int filetype; int filetype;
Debug1("checking file descriptor %u", fd); Debug1("checking file descriptor %u", fd);
@ -46,6 +46,9 @@ int fdname(const char *file, int fd, FILE *outfile) {
} }
} }
filetype = (buf.st_mode&S_IFMT)>>12; filetype = (buf.st_mode&S_IFMT)>>12;
if (numform != NULL) {
fprintf(outfile, numform, fd);
}
return statname(file, fd, filetype, outfile); return statname(file, fd, filetype, outfile);
} else { } else {
if (Stat(file, &buf) < 0) { if (Stat(file, &buf) < 0) {

View file

@ -1,5 +1,5 @@
/* source: filan.h */ /* source: filan.h */
/* Copyright Gerhard Rieger 2001-2007 */ /* Copyright Gerhard Rieger 2001-2008 */
/* Published under the GNU General Public License V.2, see file COPYING */ /* Published under the GNU General Public License V.2, see file COPYING */
@ -33,6 +33,7 @@ extern int ipan(int fd, FILE *outfile);
extern int ip6an(int fd, FILE *outfile); extern int ip6an(int fd, FILE *outfile);
#endif /* WITH_SOCKET */ #endif /* WITH_SOCKET */
extern int fdname(const char *file, int fd, FILE *outfile); extern
int fdname(const char *file, int fd, FILE *outfile, const char *numform);
#endif /* !defined(__filan_h_included) */ #endif /* !defined(__filan_h_included) */

View file

@ -1,5 +1,5 @@
/* source: filan_main.c */ /* source: filan_main.c */
/* Copyright Gerhard Rieger 2001-2006 */ /* Copyright Gerhard Rieger 2001-2008 */
/* Published under the GNU General Public License V.2, see file COPYING */ /* Published under the GNU General Public License V.2, see file COPYING */
const char copyright[] = "filan by Gerhard Rieger - see http://www.dest-unreach.org/socat/"; const char copyright[] = "filan by Gerhard Rieger - see http://www.dest-unreach.org/socat/";
@ -23,7 +23,8 @@ static void filan_usage(FILE *fd);
int main(int argc, const char *argv[]) { int main(int argc, const char *argv[]) {
const char **arg1, *a; const char **arg1, *a;
const char *filename = NULL, *waittimetxt; const char *filename = NULL, *waittimetxt;
unsigned int m = 0, n = 1024; /* this is default on my Linux */ unsigned int m = 0; /* first FD (default) */
unsigned int n = 1024; /* last excl.; this is default on my Linux */
unsigned int i; unsigned int i;
int style = 0; int style = 0;
struct timespec waittime = { 0, 0 }; struct timespec waittime = { 0, 0 };
@ -57,7 +58,7 @@ int main(int argc, const char *argv[]) {
} }
} }
m = strtoul(a, (char **)&a, 0); m = strtoul(a, (char **)&a, 0);
n = m+1; n = m;
break; break;
case 'n': if (arg1[0][2]) { case 'n': if (arg1[0][2]) {
a = *arg1+2; a = *arg1+2;
@ -168,6 +169,9 @@ int main(int argc, const char *argv[]) {
#endif #endif
filan_file(filename, fdout); filan_file(filename, fdout);
} else { } else {
if (m == n) {
++n;
}
for (i = m; i < n; ++i) { for (i = m; i < n; ++i) {
filan_fd(i, fdout); filan_fd(i, fdout);
} }
@ -189,12 +193,16 @@ int main(int argc, const char *argv[]) {
Debug2("open(\"%s\", O_RDONLY|O_NOCTTY|O_NONBLOCK|O_LARGEFILE, 0700): %s", Debug2("open(\"%s\", O_RDONLY|O_NOCTTY|O_NONBLOCK|O_LARGEFILE, 0700): %s",
filename, strerror(errno)); filename, strerror(errno));
} }
fdname(filename, fd, fdout); fdname(filename, fd, fdout, NULL);
#endif #endif
fdname(filename, -1, fdout); fdname(filename, -1, fdout, NULL);
} else { } else {
for (i = m; i < n; ++i) { if (m == n) {
fdname("", i, fdout); fdname("", m, fdout, NULL);
} else {
for (i = m; i < n; ++i) {
fdname("", i, fdout, "%5u ");
}
} }
} }
} }