Skip to content

Commit

Permalink
fix the bug about large fsname not being trunkated
Browse files Browse the repository at this point in the history
  • Loading branch information
rolinh committed Mar 20, 2012
1 parent 7e763b9 commit 40855f9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
26 changes: 23 additions & 3 deletions dfc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}

Expand Down Expand Up @@ -342,13 +343,15 @@ disp(struct list lst)
strcmp(p->fsname, "devpts") == 0) {
p = p->next;
continue;
/* NOTREACHED */
}

if (!aflag) {
/* skip some stuff we do not care about */
if (strncmp(p->fsname, "/dev/", 5) != 0) {
p = p->next;
continue;
/* NOTREACHED */
}
}

Expand Down Expand Up @@ -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 */
}
1 change: 1 addition & 0 deletions dfc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

0 comments on commit 40855f9

Please sign in to comment.