2 Copyright © 1995-2008, The AROS Development Team. All rights reserved.
5 #include <proto/exec.h>
7 #include "dos_intern.h"
9 #include <aros/debug.h>
12 /*****************************************************************************
15 #include <dos/stdio.h>
16 #include <proto/dos.h>
18 AROS_LH4(LONG
, SetVBuf
,
20 /* SetVBuf -- set buffering modes and size */
23 AROS_LHA(BPTR
, file
, D1
),
24 AROS_LHA(STRPTR
, buff
, D2
),
25 AROS_LHA(LONG
, type
, D3
),
26 AROS_LHA(LONG
, size
, D4
),
29 struct DosLibrary
*, DOSBase
, 61, Dos
)
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.
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.
47 0 if operation succeeded.
49 *****************************************************************************/
53 struct FileHandle
*fh
= (struct FileHandle
*)BADDR(file
);
55 ASSERT_VALID_PTR( fh
);
56 ASSERT_VALID_PTR_OR_NULL(buff
);
61 fh
->fh_Flags
= (fh
->fh_Flags
& ~FHF_NOBUF
) | FHF_LINEBUF
;
65 fh
->fh_Flags
= fh
->fh_Flags
& ~(FHF_NOBUF
| FHF_LINEBUF
);
69 fh
->fh_Flags
= (fh
->fh_Flags
| FHF_NOBUF
) & ~FHF_LINEBUF
;
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
;
95 fh
->fh_Pos
= fh
->fh_Buf
= fh
->fh_End
= buff
;
100 if (NULL
== vbuf_alloc(fh
, size
, DOSBase
))
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
;
125 fh
->fh_Flags
&= ~FHF_BUF
;
130 vbuf_alloc(FileHandlePtr fh
, ULONG size
, struct DosLibrary
*DOSBase
)
133 buf
= AllocMem(size
, MEMF_ANY
);
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
;
147 fh
->fh_Pos
= fh
->fh_Buf
= fh
->fh_End
= buf
;