bin/68797: cut(1) patches to fflush after each write if an option
is specified.
Dan Ponte
dcp1990 at cox.net
Wed Jul 7 20:10:03 PDT 2004
>Number: 68797
>Category: bin
>Synopsis: cut(1) patches to fflush after each write if an option is specified.
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: change-request
>Submitter-Id: current-users
>Arrival-Date: Thu Jul 08 03:10:02 GMT 2004
>Closed-Date:
>Last-Modified:
>Originator: Dan Ponte
>Release: FreeBSD 5.2.1-RELEASE-p9 i386
>Organization:
Unix Users Anonymous
>Environment:
System: FreeBSD styx.cox.net 5.2.1-RELEASE-p9 FreeBSD 5.2.1-RELEASE-p9 #7: Thu Jul 1 13:17:08 EDT 2004 dcp1990 at styx.cox.net:/usr/obj/usr/src/sys/STYX i386
>Description:
Some applications require that the stream be flushed after each write (such as tail -f). This adds a new option, -u, that does this.
>How-To-Repeat:
(none)
>Fix:
Apply the following patches:
--- cut.c.patch begins here ---
--- /usr/src/usr.bin/cut/cut.c Wed Sep 4 19:28:59 2002
+++ cut.c Wed Jul 7 22:51:23 2004
@@ -59,6 +59,7 @@
int fflag;
int nflag;
int sflag;
+int uflag;
void b_n_cut(FILE *, const char *);
void c_cut(FILE *, const char *);
@@ -83,7 +84,7 @@
* Since we don't support multi-byte characters, the -c and -b
* options are equivalent.
*/
- while ((ch = getopt(argc, argv, "b:c:d:f:sn")) != -1)
+ while ((ch = getopt(argc, argv, "b:c:d:f:snu")) != -1)
switch(ch) {
case 'b':
fcn = c_cut;
@@ -110,6 +111,9 @@
case 'n':
nflag = 1;
break;
+ case 'u':
+ uflag = 1;
+ break;
case '?':
default:
usage();
@@ -268,6 +272,8 @@
canwrite &= positions[1 + i];
if (canwrite)
fwrite(lbuf, 1, clen, stdout);
+ if(uflag)
+ fflush(stdout);
} else {
/*
* Print the character if all of it has
@@ -282,6 +288,8 @@
}
if (canwrite)
fwrite(lbuf, 1, clen, stdout);
+ if(uflag)
+ fflush(stdout);
}
lbuf += clen;
lbuflen -= clen;
@@ -349,6 +357,8 @@
if (ch == '\n') {
if (!isdelim && !sflag)
(void)fwrite(lbuf, lbuflen, 1, stdout);
+ if(uflag)
+ fflush(stdout);
break;
}
}
@@ -388,8 +398,8 @@
usage(void)
{
(void)fprintf(stderr, "%s\n%s\n%s\n",
- "usage: cut -b list [-n] [file ...]",
- " cut -c list [file ...]",
- " cut -f list [-s] [-d delim] [file ...]");
+ "usage: cut -b list [-nu] [file ...]",
+ " cut -c list [-u] [file ...]",
+ " cut -f list [-su] [-d delim] [file ...]");
exit(1);
}
--- cut.c.patch ends here ---
--- cut.1.patch begins here ---
--- /usr/src/usr.bin/cut/cut.1 Sat May 3 11:55:23 2003
+++ cut.1 Wed Jul 7 22:54:45 2004
@@ -116,6 +116,8 @@
.It Fl s
Suppress lines with no field delimiter characters.
Unless specified, lines with no delimiters are passed through unmodified.
+.It Fl u
+Flush the output stream after every write. Useful for applications involving tail -f and similar ``keep-stream-open'' applications.
.El
.Sh ENVIRONMENT
The
--- cut.1.patch ends here ---
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-bugs
mailing list