2 Copyright © 1995-2007, 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 *****************************************************************************/
51 BPTR lock
= MKBADDR(NULL
);
52 LONG success
= DOSFALSE
;
54 LONG Buffersize
= 256;
57 #define DEF_BUFSIZESTEP 128
61 /* Attempt to get the string of the file fh */
62 while ((DOSFALSE
== success
) && (Attempts
<= 5))
64 Buffer
= (char *) AllocMem(Buffersize
, MEMF_CLEAR
);
69 success
= NameFromFH(fh
, Buffer
, Buffersize
);
71 /* did it fail with a buffer overflow?? */
72 if (DOSFALSE
== success
)
74 if (ERROR_BUFFER_OVERFLOW
== IoErr())
77 FreeMem(Buffer
, Buffersize
);
78 Buffersize
+= DEF_BUFSIZESTEP
;
80 else /* another error occured -> exit */
82 FreeMem(Buffer
, Buffersize
);
87 } /* while ((DOSFALSE == success) && (Attempts <= 5)) */
89 if (DOSTRUE
== success
)
91 char * PP
= PathPart(Buffer
); /* get the path part of the file */
95 lock
= Lock (Buffer
, SHARED_LOCK
);
98 FreeMem(Buffer
, Buffersize
);
100 } /* if (fh != NULL) */