Article View: comp.sys.amiga.tech
Article #9858scdir() function replacment
From: J. Brian Waters
Date: Wed, 21 Sep 1988 18:52
Date: Wed, 21 Sep 1988 18:52
69 lines
2638 bytes
2638 bytes
After running into some problems with the Manx supplied scdir() function I
wanted to write my own replacment for it. I used the arp.library function
to be able to take advantage of its wildcard features. The routine below
worked until I tried to use the resource tracking features of arp. Can
anyone see what I am doing wrong? It bombs on the free(Anchor) command
with the guru for AN_Free_Twice.
#include <exec/types.h>
#include <libraries/arpbase.h>
extern void *calloc();
extern long FindNext(), FindFirst();
extern struct DefaultTracker *GetTracker();
extern struct DefaultTracker *LastTracker;
struct UserAnchor {
struct AnchorPath ua_AP;
BYTE moremem[255]; /* cheap way to extend ap_Buf[] */
};
char *
scdir(pat)
char *pat;
{
static int first_time = 1;
static struct UserAnchor *Anchor;
static struct DefaultTracker *anchor_tracker; /* track so we can always clean up */
LONG Result;
/* Chk_Abort(); */
if (first_time) {
/* calloc works as Manx passes [cm]alloc() on to AllocMem so longword
alignment requirment is satisfied */
if ( Anchor = calloc( 1, sizeof( *Anchor )) ) {
Anchor->ua_AP.ap_Length = 255; /* Want full path info */
}
else
return(0L);
}
while (1) {
if (first_time) {
first_time = 0;
Result = FindFirst(pat, Anchor);
if ( anchor_tracker = GetTracker( TRAK_ANCHOR ) )
anchor_tracker->dt_Object.dt_Resource = (CPTR)Anchor;
else
Result = 0; /* can not get tracker so force failure */
}
else Result = FindNext(Anchor);
if ((Result == 0) && Anchor->ua_AP.ap_Info.fib_DirEntryType >= 0) continue; /* skip dirs */
if (Result == 0) return(Anchor->ua_AP.ap_Buf);
else { /* failed to find more files */
first_time = 1; /* reset first_time to TRUE */
FreeTrackedItem(anchor_tracker);
free(Anchor); /* bombs here with AN_FreeTwice is arp freeing it on me? */
return(0L);
}
} /* end of while (1) */
} /* end of scdir() */
--
Brian Waters <backbone>!{iuvax|pur-ee}!bsu-cs!jbwaters
uunet!---/
Technical Details
Message-ID:
<4051@bsu-cs.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!iuvax!bsu-cs!jbwatersShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!iuvax!bsu-cs!jbwaters From: jbwaters@bsu-cs.UUCP (J. Brian Waters) Newsgroups: comp.sys.amiga.tech Subject: scdir() function replacment Keywords: Manx scdir() arp Message-ID: <4051@bsu-cs.UUCP> Date: 21 Sep 88 18:52:54 GMT Distribution: na Organization: The Binary Bin Lines: 69