2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
5 Desc: Lock the directory a file is located in
8 #include "dos_intern.h"
9 #include <dos/dosasl.h>
10 #include <proto/exec.h>
12 /*****************************************************************************
15 #include <proto/dos.h>
17 AROS_LH1(BPTR
, ParentOfFH
,
20 AROS_LHA(BPTR
, fh
, D1
),
23 struct DosLibrary
*, DOSBase
, 64, Dos
)
26 Lock the directory a file is located in.
29 fh - Filhandle of which you want to obtain the parent
32 lock - Lock on the parent directory of the filehandle or
43 Lock(), UnLock(), Parent()
47 *****************************************************************************/
50 AROS_LIBBASE_EXT_DECL(struct DosLibrary
*,DOSBase
)
52 BPTR lock
= MKBADDR(NULL
);
53 LONG success
= DOSFALSE
;
55 LONG Buffersize
= 256;
58 #define DEF_BUFSIZESTEP 128
62 /* Attempt to get the string of the file fh */
63 while ((DOSFALSE
== success
) && (Attempts
<= 5))
65 Buffer
= (char *) AllocMem(Buffersize
, MEMF_CLEAR
);
70 success
= NameFromFH(fh
, Buffer
, Buffersize
);
72 /* did it fail with a buffer overflow?? */
73 if (DOSFALSE
== success
)
75 if (ERROR_BUFFER_OVERFLOW
== IoErr())
78 FreeMem(Buffer
, Buffersize
);
79 Buffersize
+= DEF_BUFSIZESTEP
;
81 else /* another error occured -> exit */
83 FreeMem(Buffer
, Buffersize
);
88 } /* while ((DOSFALSE == success) && (Attempts <= 5)) */
90 if (DOSTRUE
== success
)
92 char * PP
= PathPart(Buffer
); /* get the path part of the file */
96 lock
= Lock (Buffer
, SHARED_LOCK
);
99 FreeMem(Buffer
, Buffersize
);
101 } /* if (fh != NULL) */