2 Copyright © 1995-2008, The AROS Development Team. All rights reserved.
5 Desc: Open a file from a lock
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 /*****************************************************************************
18 #include <proto/dos.h>
20 AROS_LH1(BPTR
, OpenFromLock
,
23 AROS_LHA(BPTR
, lock
, D1
),
26 struct DosLibrary
*, DOSBase
, 63, Dos
)
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.
33 lock - Lock to convert.
36 New filehandle or 0 in case of an error. IoErr() will give
37 additional information in that case.
50 *****************************************************************************/
54 struct FileHandle
*fh
;
55 struct FileLock
*fl
= BADDR(lock
);
61 fh
= (struct FileHandle
*)AllocDosObject(DOS_FILEHANDLE
, NULL
);
63 struct MsgPort
*port
= fl
->fl_Task
;
66 /* Special case for NIL: */
67 fh
->fh_Interactive
= DOSFALSE
;
68 FreeMem(fl
, sizeof(*fl
));
72 err
= dopacket2(DOSBase
, NULL
, port
, ACTION_FH_FROM_LOCK
, MKBADDR(fh
), lock
);
75 if (err
== DOSFALSE
) {
76 FreeDosObject(DOS_FILEHANDLE
, fh
);
80 /* Buffering for interactive filehandes defaults to BUF_LINE */
81 if (fh
->fh_Interactive
)
82 SetVBuf(MKBADDR(fh
), NULL
, BUF_LINE
, -1);
84 SetVBuf(MKBADDR(fh
), NULL
, BUF_NONE
, -1);
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
;