Update to lasso handling. Adjust scroll amount based on difference between mouse...
[AROS.git] / rom / dos / parentoffh.c
bloba375e9139c2725cbd1ddc7ae430325e688654bf3
1 /*
2 Copyright © 1995-2007, 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(), ParentDir()
45 INTERNALS
47 *****************************************************************************/
49 AROS_LIBFUNC_INIT
51 BPTR lock = MKBADDR(NULL);
52 LONG success = DOSFALSE;
53 char * Buffer = NULL;
54 LONG Buffersize = 256;
55 LONG Attempts = 1;
57 #define DEF_BUFSIZESTEP 128
59 if (fh != NULL)
61 /* Attempt to get the string of the file fh */
62 while ((DOSFALSE == success) && (Attempts <= 5))
64 Buffer = (char *) AllocMem(Buffersize, MEMF_CLEAR);
66 if (NULL == Buffer)
67 return NULL;
69 success = NameFromFH(fh, Buffer, Buffersize);
71 /* did it fail with a buffer overflow?? */
72 if (DOSFALSE == success)
74 if (ERROR_BUFFER_OVERFLOW == IoErr())
76 Attempts++;
77 FreeMem(Buffer, Buffersize);
78 Buffersize += DEF_BUFSIZESTEP;
80 else /* another error occured -> exit */
82 FreeMem(Buffer, Buffersize);
83 return NULL;
87 } /* while ((DOSFALSE == success) && (Attempts <= 5)) */
89 if (DOSTRUE == success)
91 char * PP = PathPart(Buffer); /* get the path part of the file */
93 *PP = '\0';
95 lock = Lock (Buffer, SHARED_LOCK);
98 FreeMem(Buffer, Buffersize);
100 } /* if (fh != NULL) */
102 return lock;
104 AROS_LIBFUNC_EXIT
106 } /* ParentOfFH */