2 Copyright © 1995-2013, 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.
49 *****************************************************************************/
53 struct FileHandle
*fh
;
54 struct FileLock
*fl
= BADDR(lock
);
60 fh
= (struct FileHandle
*)AllocDosObject(DOS_FILEHANDLE
, NULL
);
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
);
71 /* Buffering for interactive filehandes defaults to BUF_LINE */
72 if (fh
->fh_Interactive
)
73 SetVBuf(MKBADDR(fh
), NULL
, BUF_LINE
, -1);
75 SetVBuf(MKBADDR(fh
), NULL
, BUF_NONE
, -1);
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
;