Mail Archives: djgpp-workers/2001/09/08/08:47:46
And while at that, I became unhappy with Sed 3.02.80 being so slow,
and found a gross design mistake on my part. Here's a patch to
correct that; now Sed 3.02.80 is as fast as 3.02 :-)
--- sed/utils.c~2 Sat Jan 1 11:32:12 2000
+++ sed/utils.c Sat Sep 8 15:09:08 2001
@@ -185,6 +185,31 @@ ck_fopen(name, mode)
return fp;
}
+#ifdef O_BINARY
+
+static int stdout_is_a_device;
+
+static int __inline__ is_a_device P_((FILE *fp));
+static int __inline__
+is_a_device(fp)
+ FILE *fp;
+{
+ struct stat st;
+
+ if (fp == stdout)
+ {
+ /* Warning! This assumes stdout is never switched during the
+ program's run! */
+ if (stdout_is_a_device == -1
+ && fstat(fileno(stdout), &st) == 0)
+ stdout_is_a_device = S_ISCHR(st.st_mode) != 0;
+ return stdout_is_a_device == 1;
+ }
+ else
+ return fstat(fileno(fp), &st) == 0 && S_ISCHR(st.st_mode);
+}
+#endif
+
/* Panic on failing fwrite */
void
ck_fwrite(ptr, size, nmemb, stream)
@@ -195,11 +220,9 @@ ck_fwrite(ptr, size, nmemb, stream)
{
size_t written;
#ifdef O_BINARY
- struct stat st;
-
if (!size)
return;
- if (fstat(fileno(stream), &st) == 0 && S_ISCHR(st.st_mode))
+ if (is_a_device(stream))
{
char *p;
size_t left = nmemb*size;
--- sed/execute.c~2 Sat Sep 8 14:21:00 2001
+++ sed/execute.c Sat Sep 8 14:22:02 2001
@@ -264,7 +264,7 @@ line_exchange(a, b)
}
static void line_undosify P_((struct line *, size_t, int));
-static void
+static void __inline__
line_undosify(lbuf, from, ch)
struct line *lbuf;
size_t from;
- Raw text -