home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / perl / 5063 < prev    next >
Encoding:
Text File  |  1992-07-31  |  1.4 KB  |  39 lines

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!haven.umd.edu!darwin.sura.net!eng.ufl.edu!atlantis.cis.ufl.edu!bcs
  3. From: bcs@atlantis.cis.ufl.edu (Bradley C. Spatz)
  4. Subject: open and O_EXCL.
  5. Message-ID: <1992Jul31.192224.27505@eng.ufl.edu>
  6. Keywords: open flags mutex
  7. Sender: news@eng.ufl.edu (Usenet Diskhog System)
  8. Reply-To: bcs@atlantis.cis.ufl.edu (Bradley C. Spatz)
  9. Organization: UF Computer Science Dept.
  10. Date: Fri, 31 Jul 92 19:22:24 GMT
  11. Lines: 26
  12.  
  13. Hi.
  14.  
  15. How can I specify the flags (like O_EXCL) to open(2) with Perl's open?
  16.  
  17. I want to open a file like vipw does with /etc/passwd, such that my Perl
  18. script and vipw will not be able to access the file simultaneously.
  19.  
  20. The way vipw does this is by:
  21.  
  22.     fd = open("/etc/ptmp", O_WRONLY|O_CREAT|O_EXCL, 0644);
  23.     if (fd <0) {
  24.        complain(); exit(1)
  25.     }
  26.  
  27. If opened ok, then the fd is converted to a fp and /etc/passwd is copied to
  28. /etc/ptmp.  The latter serves as a lock.
  29.  
  30. I want to similarly enforce mutual exclusion on this file.  However, Perl's
  31. open doesn't seem to allow the flags (O_WRONLY|O_CREAT|O_EXCL) to be specified.  Can I specify these flags these flags in Perl?
  32.  
  33. Any suggestions?  I'll post a summary.
  34. -- 
  35. Bradley C. Spatz                                    Bytes:        bcs@ufl.edu
  36. Computer & Information Sciences                     Bits:  uunet!uflorida!bcs
  37. College of Engineering                              Waves:       904/392-1499
  38. University of Florida           "School IS hell." -- Matt Groening
  39.