Article View: gnu.utils.bug
Article #871file writing bug in sed 1.09
From: trq
Date: Thu, 08 Oct 1992 09:40
Date: Thu, 08 Oct 1992 09:40
60 lines
1926 bytes
1926 bytes
The following sed command
sed -n -e "s|.*typedef *\(.*\) X*clock_t *;.*|\1|w TMP" < dummy.out
with the following dummy.out:
typedef long clock_t;
typedef long time_t;
should create a "TMP" file that contains "long". Instead, sed 1.09
creates an empty "TMP" file.
This is for sed version 1.09 compiled with GCC version 2.2.2 on a Sun
Sparcstation ELC running SunOS 4.1.1.
The problem is that sed never closes the files it opens, so buffered
writes don't get written. Following is a sample patch to sed.c.
Tom Quinn Theoretical Physics, University of Oxford
Internet: trq@dionysos.thphys.ox.ac.uk
JANET: trq@uk.ac.ox.astro
Phone: 44-865-273956
===================================================================
RCS file: RCS/sed.c,v
retrieving revision 1.1
diff -c -r1.1 sed.c
*** 1.1 1992/10/07 07:51:06
--- sed.c 1992/10/07 09:22:07
***************
*** 181,186 ****
--- 181,187 ----
# define P_(s) ()
#endif
+ void close_files();
void panic P_((char *str, ...));
char *__fp_name P_((FILE *fp));
FILE *ck_fopen P_((char *name, char *mode));
***************
*** 401,409 ****
--- 402,422 ----
if(quit_cmd)
break;
}
+ close_files();
if(bad_input)
exit(2);
exit(0);
+ }
+
+ void close_files()
+ {
+ int nf;
+
+ for(nf = 0; nf < NUM_FPS; nf++)
+ {
+ if(file_ptrs[nf].phile)
+ fclose(file_ptrs[nf].phile);
+ }
}
/* 'str' is a string (from the command line) that contains a sed command.
Technical Details
Message-ID:
<9210080940.AA21721@thphys.ox.ac.uk>Path:
arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!dionysos.thphys.ox.ac.uk!trqShow Full Headers
Complete Article Headers
Newsgroups: gnu.utils.bug Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!dionysos.thphys.ox.ac.uk!trq From: trq@dionysos.thphys.ox.ac.uk Subject: file writing bug in sed 1.09 Message-ID: <9210080940.AA21721@thphys.ox.ac.uk> Sender: gnulists@ai.mit.edu Organization: GNUs Not Usenet Distribution: gnu Date: Thu, 8 Oct 1992 09:40:01 GMT Approved: bug-gnu-utils@prep.ai.mit.edu Lines: 61