🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.amiga.tech
Article #7210

UnLocking locks returned by CurrentDir()

#7210
From: Bob Laughlin
Date: Wed, 05 Dec 1990 10:47
48 lines
2091 bytes
    I've been using the following code to move around directories 
from within a program and restore the original current directory
on termination.  It seems to work and I originally got the code
from an example posted here a few years ago.

 // at program startup store a lock on the current directory
 if ((startdir = Lock ("", ACCESS_READ)) == NULL)
    error ...
 ........
 // during the program move around the directories with ...
 if ((newlock = Lock (newdir, ACCESS_READ) != NULL)  {
    oldlock = CurrentDir (newlock) ;   // oldlock == NULL is a valid lock!
    UnLock (oldlock) ;
 }
 ........
 // at program termination restore the original directory
 oldlock = CurrentDir (startdir) ; 
 UnLock (oldlock) ;

   However, reading Rob Peck's Programmer's Guide to the Amiga
lately I notice that on page 30 it states that you should NOT
call UnLock() on locks obtained from a call to CurrentDir().
Also, the 1.3 AutoDocs only mention using UnLock() on a lock obtained
from Lock(), DupLock(), or CreateDir(). If this is correct then how do
you move around directories without leaving any locks around when the
program exits? 

 My guess is that you something like the following:  

 // at program startup store a lock on the current directory
 startdir = Lock ("", ACCESS_READ) ;
 ........
 // during the program move around the directories with ...
 if ((newlock = Lock (newdir, ACCESS_READ) != NULL)
    CurrentDir (newlock) ;

 ...... use newlock
 UnLock (newlock) ;
 }
 ........
 // at program termination restore the original directory
 CurrentDir (startdir) ; 
 UnLock (startdir) ;

 Is this correct?
-- 
 Bob Laughlin  laughlin@cs.sfu.ca 
Technical Details
Message-ID: <1733@fornax.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!van-bc!ubc-cs!fornax!laughlin

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!van-bc!ubc-cs!fornax!laughlin
From: laughlin@fornax.UUCP (Bob Laughlin)
Newsgroups: comp.sys.amiga.tech
Subject: UnLocking locks returned by CurrentDir()
Message-ID: <1733@fornax.UUCP>
Date: 5 Dec 90 10:47:06 GMT
Organization: School of Computing Science, Simon Fraser University
Lines: 48