New bitmap method SetRGBConversionFunction which can be used to
[tangerine.git] / rom / dos / lock.c
blob6bede35ac9eb4906b141fb6d8a6faf27fa4f79f5
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Locks a file or directory.
6 Lang: English
7 */
9 #include <proto/exec.h>
10 #include <utility/tagitem.h>
11 #include <dos/dosextens.h>
12 #include <dos/filesystem.h>
13 #include <proto/dos.h>
14 #include <proto/utility.h>
15 #include "dos_intern.h"
17 #define DEBUG 0
18 #include <aros/debug.h>
21 /*****************************************************************************
23 NAME */
24 #include <proto/dos.h>
26 AROS_LH2(BPTR, Lock,
28 /* SYNOPSIS */
29 AROS_LHA(CONST_STRPTR, name, D1),
30 AROS_LHA(LONG, accessMode, D2),
32 /* LOCATION */
33 struct DosLibrary *, DOSBase, 14, Dos)
35 /* FUNCTION
36 Gets a lock on a file or directory. There may be more than one
37 shared lock on a file but only one if it is an exclusive one.
38 Locked files or directories may not be deleted.
40 INPUTS
41 name - NUL terminated name of the file or directory.
42 accessMode - One of SHARED_LOCK
43 EXCLUSIVE_LOCK
45 RESULT
46 Handle to the file or directory or 0 if the object couldn't be locked.
47 IoErr() gives additional information in that case.
49 NOTES
50 The lock structure returned by this function is different
51 from that of AmigaOS (in fact it is identical to a filehandle).
52 Do not try to read any internal fields.
54 *****************************************************************************/
57 AROS_LIBFUNC_INIT
58 AROS_LIBBASE_EXT_DECL(struct DosLibrary *,DOSBase)
60 ASSERT_VALID_PTR(name);
62 /* Sanity check */
63 if (name == NULL)
65 return NULL;
68 BPTR con = NULL, ast = NULL;
69 LONG error;
71 /* Get pointer to process structure */
72 struct Process *
73 me = (struct Process *)FindTask(NULL);
75 /* Create filehandle */
76 struct FileHandle *
77 ret = (struct FileHandle *)AllocDosObject(DOS_FILEHANDLE, NULL);
79 if (ret != NULL)
81 /* Get pointer to I/O request. Use stackspace for now. */
82 struct IOFileSys iofs;
84 /* Prepare I/O request. */
85 InitIOFS(&iofs, FSA_OPEN, DOSBase);
87 /* io_Args[0] is the name which is set by DoName(). */
88 switch (accessMode)
90 case EXCLUSIVE_LOCK:
91 iofs.io_Union.io_OPEN.io_FileMode = FMF_LOCK | FMF_READ;
92 con = me->pr_COS;
93 ast = me->pr_CES ? me->pr_CES : me->pr_COS;
94 break;
96 case SHARED_LOCK:
97 iofs.io_Union.io_OPEN.io_FileMode = FMF_READ;
98 con = ast = me->pr_CIS;
99 break;
101 default:
102 iofs.io_Union.io_OPEN.io_FileMode = accessMode;
103 con = ast = me->pr_CIS;
104 break;
107 #define iofs_SetDeviceUnit(_iofs, _fh) \
109 (_iofs).IOFS.io_Device = ((struct FileHandle *)BADDR((_fh)))->fh_Device; \
110 (_iofs).IOFS.io_Unit = ((struct FileHandle *)BADDR((_fh)))->fh_Unit; \
113 if(!Stricmp(name, "IN:") || !Stricmp(name, "STDIN:"))
115 iofs_SetDeviceUnit(iofs, me->pr_CIS);
117 iofs.io_Union.io_OPEN_FILE.io_Filename = "";
119 DosDoIO(&iofs.IOFS);
121 error = me->pr_Result2 = iofs.io_DosError;
123 else if(!Stricmp(name, "OUT:") || !Stricmp(name, "STDOUT:"))
125 iofs_SetDeviceUnit(iofs, me->pr_COS);
127 iofs.io_Union.io_OPEN_FILE.io_Filename = "";
129 DosDoIO(&iofs.IOFS);
131 error = me->pr_Result2 = iofs.io_DosError;
133 else if(!Stricmp(name, "ERR:") || !Stricmp(name, "STDERR:"))
135 if (NULL != me->pr_CES)
137 iofs_SetDeviceUnit(iofs, me->pr_CES);
139 else
141 iofs_SetDeviceUnit(iofs, me->pr_COS);
144 iofs.io_Union.io_OPEN_FILE.io_Filename = "";
146 DosDoIO(&iofs.IOFS);
148 error = me->pr_Result2 = iofs.io_DosError;
150 else if(!Stricmp(name, "CONSOLE:"))
152 iofs_SetDeviceUnit(iofs, con);
154 iofs.io_Union.io_OPEN_FILE.io_Filename = "";
156 DosDoIO(&iofs.IOFS);
158 error = me->pr_Result2 = iofs.io_DosError;
160 else if(!Stricmp(name, "*"))
162 iofs_SetDeviceUnit(iofs, ast);
164 iofs.io_Union.io_OPEN_FILE.io_Filename = "";
166 DosDoIO(&iofs.IOFS);
168 error = me->pr_Result2 = iofs.io_DosError;
170 else
172 error = DoName(&iofs, name, DOSBase);
175 if (!error)
177 ret->fh_Device = iofs.IOFS.io_Device;
178 ret->fh_Unit = iofs.IOFS.io_Unit;
180 return MKBADDR(ret);
182 else
184 FreeDosObject(DOS_FILEHANDLE, ret);
187 else
189 SetIoErr(ERROR_NO_FREE_STORE);
192 return NULL;
194 AROS_LIBFUNC_EXIT
195 } /* Lock */