Minor fixes to comments.
[AROS.git] / rom / dos / openfromlock.c
blob4ffe477733de18e4870d834caf28021e1231f552
1 /*
2 Copyright © 1995-2008, 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
50 *****************************************************************************/
52 AROS_LIBFUNC_INIT
54 struct FileHandle *fh;
55 struct FileLock *fl = BADDR(lock);
56 SIPTR err = -2;
58 if (lock == BNULL)
59 return BNULL;
61 fh = (struct FileHandle *)AllocDosObject(DOS_FILEHANDLE, NULL);
62 if (fh) {
63 struct MsgPort *port = fl->fl_Task;
65 if (port == BNULL) {
66 /* Special case for NIL: */
67 fh->fh_Interactive = DOSFALSE;
68 FreeMem(fl, sizeof(*fl));
69 err = DOSTRUE;
70 } else {
71 /* Normal case */
72 err = dopacket2(DOSBase, NULL, port, ACTION_FH_FROM_LOCK, MKBADDR(fh), lock);
75 if (err == DOSFALSE) {
76 FreeDosObject(DOS_FILEHANDLE, fh);
77 fh = NULL;
78 } else {
79 fh->fh_Type = port;
80 /* Buffering for interactive filehandes defaults to BUF_LINE */
81 if (fh->fh_Interactive)
82 SetVBuf(MKBADDR(fh), NULL, BUF_LINE, -1);
83 else
84 SetVBuf(MKBADDR(fh), NULL, BUF_NONE, -1);
86 } else {
87 SetIoErr(ERROR_NO_FREE_STORE);
90 D(bug("[OpenFromLock] %p => fh = %p (%p), error = %d\n", BADDR(lock), fh, fh->fh_Type, err));
91 return fh ? MKBADDR(fh) : BNULL;
93 AROS_LIBFUNC_EXIT
94 } /* OpenFromLock */