From 40855f93dda553c294c5ee10181cdba7e6c8f535 Mon Sep 17 00:00:00 2001 From: Rolinh - Robin Hahling Date: Wed, 21 Mar 2012 00:09:43 +0100 Subject: [PATCH] fix the bug about large fsname not being trunkated --- dfc.c | 26 +++++++++++++++++++++++--- dfc.h | 1 + 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/dfc.c b/dfc.c index 8fa5f7a..ff499bc 100644 --- a/dfc.c +++ b/dfc.c @@ -128,13 +128,14 @@ main(int argc, char *argv[]) /* NOTREACHED */ } else { /* infos from getmntent */ - if ((fmi->fsname = strdup(entbuf->mnt_fsname)) == NULL) { + if ((fmi->fsname = strdup(trk(entbuf->mnt_fsname))) + == NULL) { fmi->fsname = "unknown"; } - if ((fmi->dir = strdup(entbuf->mnt_dir)) == NULL) { + if ((fmi->dir = strdup(trk(entbuf->mnt_dir))) == NULL) { fmi->dir = "unknown"; } - if ((fmi->type = strdup(entbuf->mnt_type)) == NULL) { + if ((fmi->type = strdup(trk(entbuf->mnt_type))) == NULL) { fmi->type = "unknown"; } @@ -342,6 +343,7 @@ disp(struct list lst) strcmp(p->fsname, "devpts") == 0) { p = p->next; continue; + /* NOTREACHED */ } if (!aflag) { @@ -349,6 +351,7 @@ disp(struct list lst) if (strncmp(p->fsname, "/dev/", 5) != 0) { p = p->next; continue; + /* NOTREACHED */ } } @@ -552,4 +555,21 @@ int imax(int a, int b) { return (a > b ? a : b); + /* NOTREACHED */ +} + +/* + * Trunkate the fsname if it is too long + * @fsname: fsname to trunkate + */ +char * +trk(char *fsname) +{ + char *ptr; + + if ((ptr = strchr(strchr(fsname, '/'), '/')) != NULL) + ptr = '\0'; + + return fsname; + /* NOTREACHED */ } diff --git a/dfc.h b/dfc.h index e2601f2..f1e5aa5 100644 --- a/dfc.h +++ b/dfc.h @@ -50,5 +50,6 @@ void disp(struct list lst); void disp_header(struct list *lst); double cvrt(double nb); int imax(int a, int b); +char* trk(char *fsname); #endif /* ndef DFC_H */