2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
8 #include <proto/exec.h>
9 #include "dos_intern.h"
15 /*****************************************************************************
18 #include <proto/dos.h>
20 AROS_LH2(LONG
, UnGetC
,
23 AROS_LHA(BPTR
, file
, D1
),
24 AROS_LHA(LONG
, character
, D2
),
28 struct DosLibrary
*, DOSBase
, 53, Dos
)
31 Push a character back into a read filehandle. If you've read
32 a character from that file you may always push at least 1 character
33 back. UnGetC(file,-1) ungets the last character read. This also
37 file - Filehandle you've read from.
38 character - Character to push back or EOF.
41 !=0 if all went well, 0 if the character couldn't be pushed back.
42 IoErr() gives additional information in that case.
55 *****************************************************************************/
59 SIPTR
*result
=&((struct Process
*)FindTask(NULL
))->pr_Result2
;
61 /* Get pointer to filehandle */
62 struct FileHandle
*fh
=(struct FileHandle
*)BADDR(file
);
64 /* If the file is in write mode there was nothing read recently */
65 if(fh
->fh_Flags
&FHF_WRITE
)
67 *result
=ERROR_SEEK_ERROR
;
71 /* Unget EOF character if the last character read was an EOF */
72 if(character
==EOF
&&fh
->fh_End
==0)
78 /* Test if I may unget a character on this file */
81 *result
=ERROR_SEEK_ERROR
;
85 /* OK. Unget character and return. */
88 ((UBYTE
*)BADDR(fh
->fh_Buf
))[fh
->fh_Pos
]=character
;
89 return character
?character
:1;