Added a GfxBase parameter to UninstallFB(): more consistent with related
[AROS.git] / rom / dos / openfromlock.c
blobc1ff43a74155e46aaf29e40017f3fb387050e315
1 /*
2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Open a file from a lock
6 Lang: english
7 */
9 #include <aros/debug.h>
10 #include <proto/exec.h>
11 #include <dos/dosextens.h>
12 #include <dos/stdio.h>
13 #include "dos_intern.h"
15 /*****************************************************************************
17 NAME */
18 #include <proto/dos.h>
20 AROS_LH1(BPTR, OpenFromLock,
22 /* SYNOPSIS */
23 AROS_LHA(BPTR, lock, D1),
25 /* LOCATION */
26 struct DosLibrary *, DOSBase, 63, Dos)
28 /* FUNCTION
29 Convert a lock into a filehandle. If all went well the lock
30 will be gone. In case of an error it must still be freed.
32 INPUTS
33 lock - Lock to convert.
35 RESULT
36 New filehandle or 0 in case of an error. IoErr() will give
37 additional information in that case.
39 NOTES
41 EXAMPLE
43 BUGS
45 SEE ALSO
47 INTERNALS
49 *****************************************************************************/
51 AROS_LIBFUNC_INIT
53 struct FileHandle *fh;
54 struct FileLock *fl = BADDR(lock);
55 SIPTR err = -2;
57 if (lock == BNULL)
58 return BNULL;
60 fh = (struct FileHandle *)AllocDosObject(DOS_FILEHANDLE, NULL);
61 if (fh) {
62 struct MsgPort *port = fl->fl_Task;
64 err = dopacket2(DOSBase, NULL, port, ACTION_FH_FROM_LOCK, MKBADDR(fh), lock);
66 if (err == DOSFALSE) {
67 FreeDosObject(DOS_FILEHANDLE, fh);
68 fh = NULL;
69 } else {
70 fh->fh_Type = port;
71 /* Buffering for interactive filehandes defaults to BUF_LINE */
72 if (fh->fh_Interactive)
73 SetVBuf(MKBADDR(fh), NULL, BUF_LINE, -1);
74 else
75 SetVBuf(MKBADDR(fh), NULL, BUF_NONE, -1);
77 } else {
78 SetIoErr(ERROR_NO_FREE_STORE);
81 D(bug("[OpenFromLock] %p => fh = %p (%p), error = %d\n", BADDR(lock), fh, fh->fh_Type, err));
82 return fh ? MKBADDR(fh) : BNULL;
84 AROS_LIBFUNC_EXIT
85 } /* OpenFromLock */