From: Christos Zoulas Date: Mon, 17 Oct 2005 17:39:39 +0000 (+0000) Subject: Fix the '\n' chopping. X-Git-Tag: FILE5_05~792 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bdb9dd07d0916f9bcffff330af32eeb84b1bf68a;p=file Fix the '\n' chopping. --- diff --git a/src/file.c b/src/file.c index 3a181762..019d754a 100644 --- a/src/file.c +++ b/src/file.c @@ -71,7 +71,7 @@ #include "patchlevel.h" #ifndef lint -FILE_RCSID("@(#)$Id: file.c,v 1.98 2005/10/17 15:31:10 christos Exp $") +FILE_RCSID("@(#)$Id: file.c,v 1.99 2005/10/17 17:39:39 christos Exp $") #endif /* lint */ @@ -347,6 +347,7 @@ unwrap(char *fn) char buf[MAXPATHLEN]; FILE *f; int wid = 0, cwid; + size_t len; if (strcmp("-", fn) == 0) { f = stdin; @@ -359,7 +360,10 @@ unwrap(char *fn) } while (fgets(buf, MAXPATHLEN, f) != NULL) { - cwid = file_mbswidth(buf) - 1; + len = strlen(buf); + if (len > 0 && buf[len - 1] == '\n') + buf[len - 1] = '\0'; + cwid = file_mbswidth(buf); if (cwid > wid) wid = cwid; } @@ -368,7 +372,9 @@ unwrap(char *fn) } while (fgets(buf, MAXPATHLEN, f) != NULL) { - buf[file_mbswidth(buf)-1] = '\0'; + len = strlen(buf); + if (len > 0 && buf[len - 1] == '\n') + buf[len - 1] = '\0'; process(buf, wid); if(nobuffer) (void) fflush(stdout);