Updated PCI IDs to latest snapshot.
[tangerine.git] / rom / dos / setvbuf.c
blob8d43af69062f800d631ecd9bf5b2eb41273735c2
1 /*
2 Copyright © 1995-2008, The AROS Development Team. All rights reserved.
3 $Id$
4 */
5 #include <proto/exec.h>
7 #include "dos_intern.h"
9 #include <aros/debug.h>
12 /*****************************************************************************
14 NAME */
15 #include <dos/stdio.h>
16 #include <proto/dos.h>
18 AROS_LH4(LONG, SetVBuf,
20 /* SetVBuf -- set buffering modes and size */
22 /* SYNOPSIS */
23 AROS_LHA(BPTR , file, D1),
24 AROS_LHA(STRPTR, buff, D2),
25 AROS_LHA(LONG , type, D3),
26 AROS_LHA(LONG , size, D4),
28 /* LOCATION */
29 struct DosLibrary *, DOSBase, 61, Dos)
31 /* FUNCTION
32 Changes the buffering modes and buffer size for a filehandle.
33 With buff == NULL, the current buffer will be deallocated and a
34 new one of (approximately) size will be allocated. If buffer is
35 non-NULL, it will be used for buffering and must be at least
36 max(size,208) bytes long, and MUST be longword aligned. If size
37 is -1, then only the buffering mode will be changed.
39 INPUTS
40 file - Filehandle
41 buff - buffer pointer for buffered I/O or NULL.
42 type - buffering mode (see <dos/stdio.h>)
43 size - size of buffer for buffered I/O (sizes less than 208 bytes
44 will be rounded up to 208), or -1.
46 RESULT
47 0 if operation succeeded.
49 *****************************************************************************/
51 AROS_LIBFUNC_INIT
53 struct FileHandle *fh = (struct FileHandle *)BADDR(file);
55 ASSERT_VALID_PTR( fh );
56 ASSERT_VALID_PTR_OR_NULL(buff);
58 switch (type)
60 case BUF_LINE:
61 fh->fh_Flags = (fh->fh_Flags & ~FHF_NOBUF) | FHF_LINEBUF;
62 break;
64 case BUF_FULL:
65 fh->fh_Flags = fh->fh_Flags & ~(FHF_NOBUF | FHF_LINEBUF);
66 break;
68 case BUF_NONE:
69 fh->fh_Flags = (fh->fh_Flags | FHF_NOBUF) & ~FHF_LINEBUF;
70 break;
72 default:
73 return EOF;
76 if (size != -1)
78 if (size < 208)
80 size = 208;
83 vbuf_free(fh);
85 if (NULL != buff)
87 fh->fh_Size = size;
88 if(fh->fh_Flags & FHF_WRITE)
90 fh->fh_Pos = fh->fh_Buf = buff;
91 fh->fh_End = fh->fh_Buf + fh->fh_Size;
93 else
95 fh->fh_Pos = fh->fh_Buf = fh->fh_End = buff;
98 else
100 if (NULL == vbuf_alloc(fh, size, DOSBase))
102 return(EOF);
107 return 0;
109 AROS_LIBFUNC_EXIT
110 } /* SetVBuf */
113 void
114 vbuf_free(FileHandlePtr fh)
116 /* free buffer allocated by system */
117 if (fh->fh_Flags & FHF_BUF)
119 FreeMem(fh->fh_Buf, fh->fh_Size);
121 fh->fh_Buf = fh->fh_Pos = fh->fh_End = NULL;
122 fh->fh_Size = 0;
125 fh->fh_Flags &= ~FHF_BUF;
129 APTR
130 vbuf_alloc(FileHandlePtr fh, ULONG size, struct DosLibrary *DOSBase)
132 STRPTR
133 buf = AllocMem(size, MEMF_ANY);
135 if (NULL != buf)
137 fh->fh_Size = size;
138 fh->fh_Flags |= FHF_BUF;
140 if(fh->fh_Flags & FHF_WRITE)
142 fh->fh_Pos = fh->fh_Buf = buf;
143 fh->fh_End = fh->fh_Buf + fh->fh_Size;
145 else
147 fh->fh_Pos = fh->fh_Buf = fh->fh_End = buf;
151 return(fh->fh_Buf);