Fix for the (stupid) case of app (always) passing
[tangerine.git] / rom / dos / parentoffh.c
bloba506d91bf64da9f3084eab27476eb530cd60c713
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Lock the directory a file is located in
6 Lang: english
7 */
8 #include "dos_intern.h"
9 #include <dos/dosasl.h>
10 #include <proto/exec.h>
12 /*****************************************************************************
14 NAME */
15 #include <proto/dos.h>
17 AROS_LH1(BPTR, ParentOfFH,
19 /* SYNOPSIS */
20 AROS_LHA(BPTR, fh, D1),
22 /* LOCATION */
23 struct DosLibrary *, DOSBase, 64, Dos)
25 /* FUNCTION
26 Lock the directory a file is located in.
28 INPUTS
29 fh - Filhandle of which you want to obtain the parent
31 RESULT
32 lock - Lock on the parent directory of the filehandle or
33 NULL for failure.
36 NOTES
38 EXAMPLE
40 BUGS
42 SEE ALSO
43 Lock(), UnLock(), Parent()
45 INTERNALS
47 *****************************************************************************/
49 AROS_LIBFUNC_INIT
50 AROS_LIBBASE_EXT_DECL(struct DosLibrary *,DOSBase)
52 BPTR lock = MKBADDR(NULL);
53 LONG success = DOSFALSE;
54 char * Buffer = NULL;
55 LONG Buffersize = 256;
56 LONG Attempts = 1;
58 #define DEF_BUFSIZESTEP 128
60 if (fh != NULL)
62 /* Attempt to get the string of the file fh */
63 while ((DOSFALSE == success) && (Attempts <= 5))
65 Buffer = (char *) AllocMem(Buffersize, MEMF_CLEAR);
67 if (NULL == Buffer)
68 return NULL;
70 success = NameFromFH(fh, Buffer, Buffersize);
72 /* did it fail with a buffer overflow?? */
73 if (DOSFALSE == success)
75 if (ERROR_BUFFER_OVERFLOW == IoErr())
77 Attempts++;
78 FreeMem(Buffer, Buffersize);
79 Buffersize += DEF_BUFSIZESTEP;
81 else /* another error occured -> exit */
83 FreeMem(Buffer, Buffersize);
84 return NULL;
88 } /* while ((DOSFALSE == success) && (Attempts <= 5)) */
90 if (DOSTRUE == success)
92 char * PP = PathPart(Buffer); /* get the path part of the file */
94 *PP = '\0';
96 lock = Lock (Buffer, SHARED_LOCK);
99 FreeMem(Buffer, Buffersize);
101 } /* if (fh != NULL) */
103 return lock;
105 AROS_LIBFUNC_EXIT
107 } /* ParentOfFH */