home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / os / vms / 19782 < prev    next >
Encoding:
Text File  |  1992-12-23  |  2.1 KB  |  53 lines

  1. Path: sparky!uunet!news.claremont.edu!nntp-server.caltech.edu!SOL1.GPS.CALTECH.EDU!CARL
  2. From: carl@SOL1.GPS.CALTECH.EDU (Carl J Lydick)
  3. Newsgroups: comp.os.vms
  4. Subject: Re: Problem with file open detection
  5. Date: 23 Dec 1992 13:59:08 GMT
  6. Organization: HST Wide Field/Planetary Camera
  7. Lines: 39
  8. Distribution: world
  9. Message-ID: <1h9rbcINN1c9@gap.caltech.edu>
  10. References: <1992Dec23.024625.20490@ee.ubc.ca>
  11. Reply-To: carl@SOL1.GPS.CALTECH.EDU
  12. NNTP-Posting-Host: sol1.gps.caltech.edu
  13.  
  14. In article <1992Dec23.024625.20490@ee.ubc.ca>, mhui@ee.ubc.ca (HUI MAN HOI SAMUEL) writes:
  15. >Hi,
  16. >   Can I use any DCL command or C Library function call to find out that 
  17. >if a particular file is already  opened by any process.  
  18. >   Is there anyone who can give me some help? Thank you!
  19.  
  20. Yes.  Try to open the file for APPEND access with NO sharing.  If the file's
  21. already open, you'll get the error status %X1001828A (%RMS-E-FLK, file
  22. currently locked by another user).  Unfortunately, in a misguided effort to
  23. make VAXC look like UNIX C, DEC implemented the run-time library in such a way
  24. that you've got to go through some (mild) contortions to get the actual error
  25. status (I thought there was a "vmserr" variable, but a quick look at HELP CC
  26. RUN didn't show it, so here's a routine to do it using RMS (the routine returns
  27. 0 if the file's already open, 1 if it's not):
  28.  
  29. #include fab
  30.  
  31. is_open(char *file)
  32. {    struct FAB my_fab;
  33.  
  34.     my_fab = cc$rms_fab;
  35.     my_fab.fab$b_fac = FAB$M_PUT;
  36.     my_fab.fab$l_fna = file;
  37.     my_fab.fab$b_fns = strlen(my_fab.fab$l_fna);
  38.     if((stat = SYS$OPEN(&my_fab)) = 0x0001828A)
  39.         return 0;
  40.     else
  41.     {    SYS$CLOSE(&my_fab);
  42.         return(1);
  43.     }
  44. }
  45. --------------------------------------------------------------------------------
  46. Carl J Lydick | INTERnet: CARL@SOL1.GPS.CALTECH.EDU | NSI/HEPnet: SOL1::CARL
  47.  
  48. Disclaimer:  Hey, I understand VAXen and VMS.  That's what I get paid for.  My
  49. understanding of astronomy is purely at the amateur level (or below).  So
  50. unless what I'm saying is directly related to VAX/VMS, don't hold me or my
  51. organization responsible for it.  If it IS related to VAX/VMS, you can try to
  52. hold me responsible for it, but my organization had nothing to do with it.
  53.