Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.3 4.3bsd-beta 6/6/85; site ucbvax.BERKELEY.EDU Path: utzoo!watmath!clyde!burl!ulysses!cbosgd!ucbvax!nbs-vms.arpa!nunn From: nunn@NBS-VMS.ARPA ("NUNN, JOHN C.") Newsgroups: mod.computers.vax Subject: Open bug in VAX C V2.0 Message-ID: <8511071615.AA04882@ucbvax.berkeley.edu> Date: Thu, 7-Nov-85 10:05:00 EST Article-I.D.: ucbvax.8511071615.AA04882 Posted: Thu Nov 7 10:05:00 1985 Date-Received: Fri, 8-Nov-85 21:51:20 EST Sender: daemon@ucbvax.BERKELEY.EDU Reply-To: "NUNN, JOHN C."Organization: The ARPA Internet Lines: 29 Approved: info-vax@ucbvax.berkeley.edu There is a bug in the open function of VAX C V2.0 which will cause some UNIX utilities to fail when compiled and run under VMS. When an open is called for a file which does not exist, the next file descriptor, which would be assigned to the file if it existed, is assigned to the non-existent file. The following code: close(0); fd = open("nonfile.dat",0L,0L); /* file doesn't exist */ if ( fd != -1 ) { /* would be 0 if file existed */ read(0,buffer,nbytes); close(0); } open("sys$input",0L,0L); /* assume that fd = 0 */ read(0,buffer,nbytes); will fail because the second open doesn't actually return a file descriptor of 0, but instead returns the next available file descriptor. Some UNIX code, look at VI/EX, actually count on the second open returning an fd=0. In this specific case adding "else close(0)" corrects the problem, but this may not work when many files are being open and (sometimes) closed. Can someone verify whether this bug also exists in V2.1 of VAX C? Also, does anyone know if this has been SPR'ed? ------