delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2001/09/08/08:47:46

Date: Sat, 08 Sep 2001 15:28:50 +0300
From: "Eli Zaretskii" <eliz AT is DOT elta DOT co DOT il>
Sender: halo1 AT zahav DOT net DOT il
To: djgpp-workers AT delorie DOT com
Message-Id: <8011-Sat08Sep2001152847+0300-eliz@is.elta.co.il>
X-Mailer: Emacs 20.6 (via feedmail 8.3.emacs20_6 I) and Blat ver 1.8.9
CC: pavenis AT lanet DOT lv, ST001906 AT HRZ1 DOT HRZ DOT TU-Darmstadt DOT De
In-reply-to: <7263-Sat08Sep2001132012+0300-eliz@is.elta.co.il>
Subject: Re: Problem with sed3028b.zip
References: <Pine DOT A41 DOT 4 DOT 05 DOT 10109081013060 DOT 53626-100000 AT ieva06> <7263-Sat08Sep2001132012+0300-eliz AT is DOT elta DOT co DOT il>
Reply-To: djgpp-workers AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp-workers AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019