New bitmap method SetRGBConversionFunction which can be used to
[tangerine.git] / rom / dos / changemode.c
blob93b589453f764bdf7e327263c2c4b60570fe2c19
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Change the mode of a filehandle or -lock.
6 Lang: English
7 */
8 #include <proto/exec.h>
9 #include <dos/dosextens.h>
10 #include <dos/filesystem.h>
11 #include "dos_intern.h"
13 /*****************************************************************************
15 NAME */
16 #include <proto/dos.h>
18 AROS_LH3(BOOL, ChangeMode,
20 /* SYNOPSIS */
21 AROS_LHA(ULONG, type, D1),
22 AROS_LHA(BPTR, object, D2),
23 AROS_LHA(ULONG, newmode, D3),
25 /* LOCATION */
26 struct DosLibrary *, DOSBase, 75, Dos)
28 /* FUNCTION
29 Try to change the mode used by a lock or filehandle.
31 INPUTS
32 type - CHANGE_FH or CHANGE_LOCK.
33 object - Filehandle or lock.
34 newmode - New mode (see <dos/dos.h>).
36 RESULT
37 != 0 if all went well, otherwise 0. IoErr() gives additional
38 information in the latter case.
40 NOTES
41 Since filehandles and locks are identical under AROS the type
42 argument is ignored.
44 EXAMPLE
46 BUGS
48 SEE ALSO
50 INTERNALS
52 *****************************************************************************/
54 AROS_LIBFUNC_INIT
55 AROS_LIBBASE_EXT_DECL(struct DosLibrary *,DOSBase)
57 /* Get pointer to filehandle */
58 struct FileHandle *fh = (struct FileHandle *)BADDR(object);
60 /* Get pointer to I/O request. Use stackspace for now. */
61 struct IOFileSys iofs;
63 /* Convert Open() and Lock() constants to filehandler flags. */
64 ULONG newflags, mask;
66 if(newmode == MODE_OLDFILE || newmode == MODE_READWRITE ||
67 newmode == ACCESS_READ)
69 newflags = 0;
70 mask = FMF_LOCK;
72 else if(newmode == MODE_NEWFILE || newmode == ACCESS_WRITE)
74 newflags = FMF_LOCK;
75 mask = FMF_LOCK;
77 else
79 if (newmode & FMF_APPEND)
81 /* See if the handler supports FSA_SEEK */
82 if (!(fh->fh_Flags & FHF_APPEND) && Seek(MKBADDR(fh), 0, OFFSET_END) != -1)
84 /* if so then set the proper flag in the FileHandle struct */
85 fh->fh_Flags |= FHF_APPEND;
88 else
89 fh->fh_Flags &= ~FHF_APPEND;
91 newmode &= ~FMF_APPEND;
93 newflags = newmode;
94 mask = 0xFFFFFFFF;
97 /* Prepare I/O request. */
98 InitIOFS(&iofs, FSA_FILE_MODE, DOSBase);
100 iofs.IOFS.io_Device = fh->fh_Device;
101 iofs.IOFS.io_Unit = fh->fh_Unit;
103 iofs.io_Union.io_FILE_MODE.io_FileMode = newflags;
104 iofs.io_Union.io_FILE_MODE.io_Mask = mask;
106 /* Send the request. */
107 DosDoIO(&iofs.IOFS);
109 /* Set error code and return */
110 if (iofs.io_DosError != 0)
112 SetIoErr(iofs.io_DosError);
113 return DOSFALSE;
116 return DOSTRUE;
118 AROS_LIBFUNC_EXIT
119 } /* ChangeMode */