[ From:	CRDGW2::CRDGW2::MRGATE::"SMTP::CRVAX.SRI.COM::RELAY-INFO-VAX" 30-OCT-1990 05:25:07.23  To:	MRGATE::"ARISIA::EVERHART" CC:	! Subj:	Re: fflush() and open files   * Received:  by crdgw1.ge.com (5.57/GE 1.76)) 	 id AA26012; Tue, 30 Oct 90 05:05:19 EST Y Received: From UCBVAX.BERKELEY.EDU by CRVAX.SRI.COM with TCP; Tue, 30 OCT 90 01:59:21 PDT , Received: by ucbvax.Berkeley.EDU (5.63/1.42)* 	id AA28820; Tue, 30 Oct 90 01:47:13 -08009 Received: from USENET by ucbvax.Berkeley.EDU with netnews . 	for info-vax@kl.sri.com (info-vax@kl.sri.com); 	(contact usenet@ucbvax.Berkeley.EDU if you have questions)  Date: 30 Oct 90 03:23:24 GMTL From: usc!samsung!umich!sharkey!bnlux0!bnlls1!rivers@ucsd.edu  (Mark Rivers), Organization: Brookhaven National Labs(NSLS)$ Subject: Re: fflush() and open files! Message-Id: <2269@bnlux0.bnl.gov>  References: <278@talarian.UUCP> # Sender: info-vax-request@kl.sri.com  To: info-vax@kl.sri.com   B This routine shows how to do file sharing under VMS with VAXC. OneH process can write to the file while others simultaneuously read from it.D The important lines below are the creat() and open() function calls.F I have not worried about fflush(), since I don't care if I am one or 2= lines behind when I read the file. Experiment to see if it is 
 necessary.   #include <stdio.h> #include <file.h>  #include "image_header.h"  #include "image_buffer.h" F #define PMODE 0644     /* Default protection on UNIX systems = RW for   			owner, R for everyone else */  2 /* This buffer is defined in write_image_record */( extern char scratch_buffer[MAX_REC_LEN];  < open_image_file(file_id, file_name, file_name_len, new_file)  F /* This routine opens an existing or new BSIF image file. It is system; dependent and has conditional compilation for UNIX and VMS.   K    13-DEC-1988  Changed VMS version to allow shared access to files, so one A program can be writing to a file while other programs read it. */   
 int *file_id;  char *file_name; int *file_name_len;  int *new_file;   {    	char max_rec_size[20];   E /*	Copy the file name to the scratch buffer and terminate with a NULL A 	since this may be being called from FORTRAN, which doesn't null   	terminate strings */ 4 	strncpy(scratch_buffer, file_name, *file_name_len);$ 	scratch_buffer[*file_name_len] = 0;  " /*	Format maximum record length */. 	sprintf(max_rec_size, "mrs=%d", MAX_REC_LEN); 	if (*new_file) { 
 #ifdef VMS@ 	   *file_id = creat(scratch_buffer, 0, "rfm=var", max_rec_size, 					"ctx=rec", "shr=get");  #endif #ifdef unix , 	   *file_id = creat(scratch_buffer, PMODE); #endif 	} 	else { 
 #ifdef VMS1 	   *file_id = open(scratch_buffer, O_RDONLY, 0,  & 				"shr=put,get,del,upd", "ctx=rec"); #endif #ifdef unix ' 	   *file_id = open(scratch_buffer, 0);  #endif 	}    	if (*file_id == -1) return (0); 	return(1);  }     ? Mark Rivers                              (516) 282-7708 or 5626 O Building 815                             rivers@bnlx26.nsls.bnl.gov (Internet)  O Brookhaven National Laboratory           rivers@bnl (Bitnet)                    O Upton, NY 11973                          BNLX26::RIVERS  (Physnet)                