FreeBSD Bugzilla – Attachment 14266 Details for
Bug 26810
[PATCH] make cut(1) work with long lines
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
file.diff
file.diff (text/plain), 1.55 KB, created by
dd
on 2001-04-24 05:00:01 UTC
(
hide
)
Description:
file.diff
Filename:
MIME Type:
Creator:
dd
Created:
2001-04-24 05:00:01 UTC
Size:
1.55 KB
patch
obsolete
>Index: cut.c >=================================================================== >RCS file: /st/src/FreeBSD/src/usr.bin/cut/cut.c,v >retrieving revision 1.12 >diff -u -r1.12 cut.c >--- cut.c 2001/02/06 20:03:48 1.12 >+++ cut.c 2001/04/20 20:49:08 >@@ -43,6 +43,7 @@ > "$FreeBSD: src/usr.bin/cut/cut.c,v 1.12 2001/02/06 20:03:48 charnier Exp $"; > #endif /* not lint */ > >+#include <assert.h> > #include <ctype.h> > #include <err.h> > #include <limits.h> >@@ -228,19 +229,30 @@ > int ch, field, isdelim; > char *pos, *p, sep; > int output; >- char lbuf[_POSIX2_LINE_MAX + 1]; >+ char *lbuf, *mlbuf = NULL; >+ size_t lbuflen; > >- for (sep = dchar; fgets(lbuf, sizeof(lbuf), fp);) { >+ for (sep = dchar; (lbuf = fgetln(fp, &lbuflen)) != NULL;) { >+ /* Assert EOL has a newline. */ >+ if (*(lbuf + lbuflen - 1) != '\n') { >+ /* Can't have > 1 line with no trailing newline. */ >+ assert(mlbuf == NULL); >+ mlbuf = malloc(lbuflen + 1); >+ if (mlbuf == NULL) >+ err(1, "malloc"); >+ memcpy(mlbuf, lbuf, lbuflen); >+ *(mlbuf + lbuflen) = '\n'; >+ lbuf = mlbuf; >+ } > output = 0; >- for (isdelim = 0, p = lbuf;; ++p) { >- if (!(ch = *p)) >- errx(1, "%s: line too long.", fname); >+ for (isdelim = 0, p = lbuf; p < lbuf + lbuflen; ++p) { >+ ch = *p; > /* this should work if newline is delimiter */ > if (ch == sep) > isdelim = 1; > if (ch == '\n') { > if (!isdelim && !sflag) >- (void)printf("%s", lbuf); >+ (void)fwrite(lbuf, lbuflen, 1, stdout); > break; > } > } >@@ -272,6 +284,8 @@ > } > (void)putchar('\n'); > } >+ if (mlbuf != NULL) >+ free(mlbuf); > } > > static void
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 26810
: 14266