Article View: comp.sys.amiga.tech
Article #10164Re: Locks
From: Jim Pritchett
Date: Mon, 31 Oct 1988 03:34
Date: Mon, 31 Oct 1988 03:34
80 lines
3392 bytes
3392 bytes
Many thanks to all who tried to help me get the program working! There
were TWO major blunders in my code. Rob Peck explained to me the errors in
the Dos documentation on locks. Phil Staub found a really stealthy bug in my
AllocMem call. So, many thanks to Rob and Phil!!! Thanks also to the others
who tried to help via Email or this newsgroup. Here is a listing of the
revised and working (at least so far) program:
#include <stdio.h>
main()
{
char cd[108];
getcwd(cd, 108);
}
# include <functions.h>
# include <exec/types.h>
# include <exec/memory.h>
# include <libraries/dosextens.h>
getcwd(cd, length)
char *cd;
int length;
{
char name[108];
struct FileLock *lockcd, *lockram, *lockram2;
struct FileInfoBlock *fib;
short success;
lockram = Lock("ram:t", ACCESS_READ);
lockcd = CurrentDir(lockram);
UnLock(lockram);
/* don't UnLock() anything except Lock() and DupLock()ed files - Thanks Rob!! */
fib = AllocMem((long)sizeof(struct FileInfoBlock), MEMF_PUBLIC);
/* Super Stealthy bug was here. This line was: */
/* */
/* fib = AllocMem((long)sizeof(fib), 1L) */
/* */
/* which allocates space for a pointer ONLY!!! NOT enough for FileInfoBlock. */
/* */
/* So, the Super Bug Sleuth Award goes to Phil Staub for finding this one!!! */
/* */
success = Examine(lockcd, fib);
strcpy(name, fib->fib_FileName);
printf(" %s\n", name);
lockram2 = CurrentDir(lockcd);
FreeMem(fib, (long)sizeof(struct FileInfoBlock));
}
Now, I need to add some error checking...
I have another question, though. Several people wrote me that I should
have declared my lock pointers as 'ULONG.' This implies to me that I may be
dealing with the infamous BPTRs here. If so, wouldn't it be more appropriate
to declare them as BPTR rather that ULONG (yes, I realize that there is no
difference in the end result.) Is there a simple rule I can use to tell
whether I should use an APTR or a BPTR? Do all Dos functions use BPTRs?
What else does? The code as written seems to work, but am I setting myself
up for problems later? Why doesn't any of my documentation mention any of
this? (I have the white Dos manuals, the 1.2 includes, the Mortimore book,
the Berry book, and of course, the Aztec C manuals.)
Well, I ended up with more questions than I started with. However,
thanks to you (the net), I am making progress.
Thanks,
Jim Pritchett
UUCP: (backbone)!killer!gtmvax!dms3b1!caleb!jdp
Technical Details
Message-ID:
<5966@killer.DALLAS.TX.US>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!cwjcc!ukma!rutgers!bellcore!texbell!killer!jdpShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!cwjcc!ukma!rutgers!bellcore!texbell!killer!jdp From: jdp@killer.DALLAS.TX.US (Jim Pritchett) Newsgroups: comp.sys.amiga.tech Subject: Re: Locks Keywords: Locks Dos Manx Aztec C help Message-ID: <5966@killer.DALLAS.TX.US> Date: 31 Oct 88 03:34:26 GMT Organization: The Unix(R) Connection, Dallas, Texas Lines: 80