[comp.sys.hp] Anyone had problems with fflush or freopen under HP-UX ?

evgabb@sdrc.UUCP (Rob Gabbard) (05/07/90)

I have a program that splits a large file into smaller ones. The large
file is of the format:

	*FILE* /data/dir/file1
	file1 data
	file1 data2
	*FILE* /data/dir/file2
	file2 data
	file2 data2
	file2 data3
	*FILE* /data/dir/file3
	etc

When fed to this program the above would produce three files, /data/dir/file1,
/data/dir/file2 and /data/dir/file3 with the data in them between the *FILE*
cards.

	The code to do this is simple:
		
	while (fgets(input_line,82,stdin) != NULL)
		if (!strncmp(input_line,"*FILE*",6))	/* Description line */
			{
			fflush(stdout);
			/* Just get name */
			sscanf(input_line,"%*s %s",filename);
			if(freopen(filename,"w",stdout) == NULL)
				fprintf(stderr,"%s: could not open %s\n",
					argv[0],filename);
			} 
		else
			fputs(input_line,stdout); /* Just a normal line */

	fflush(stdout);

For the most part this works like a charm and we pump TONS of data through it.
However, every now and then it goes nuts and creates a bunch of empty files.
It is as though the freopen call doesn't correctly close the previous file.
I do have code in the actual program that ensures the directory exists before
freopn'ing and does all sorts of checking and calls perror in the event of
failure so I'm sure that step isn't the problem.

Anyone run across this ?

-- 

Rob Gabbard (uunet!sdrc!evgabb)  
Technical Development Engineer   
Structural Dynamics Research Corp