2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
8 #include <aros/debug.h>
10 #include <proto/exec.h>
11 #include "dos_intern.h"
17 /*****************************************************************************
20 #include <proto/dos.h>
22 AROS_LH2(LONG
, UnGetC
,
25 AROS_LHA(BPTR
, file
, D1
),
26 AROS_LHA(LONG
, character
, D2
),
30 struct DosLibrary
*, DOSBase
, 53, Dos
)
33 Push a character back into a read filehandle. If you've read
34 a character from that file you may always push at least 1 character
35 back. UnGetC(file,-1) ungets the last character read. This also
39 file - Filehandle you've read from.
40 character - Character to push back or EOF.
43 !=0 if all went well, 0 if the character couldn't be pushed back.
44 IoErr() gives additional information in that case.
57 *****************************************************************************/
61 struct Process
*me
= (struct Process
*)FindTask(NULL
);
64 ASSERT_VALID_PROCESS(me
);
66 result
=&me
->pr_Result2
;
68 /* Get pointer to filehandle */
69 struct FileHandle
*fh
=(struct FileHandle
*)BADDR(file
);
71 /* If the file is in write mode there was nothing read recently */
72 if(fh
->fh_Flags
&FHF_WRITE
)
74 *result
=ERROR_SEEK_ERROR
;
78 /* Unget EOF character if the last character read was an EOF */
79 if(character
==EOF
&&fh
->fh_End
==0)
85 /* Test if I may unget a character on this file */
88 *result
=ERROR_SEEK_ERROR
;
92 /* OK. Unget character and return. */
95 ((UBYTE
*)BADDR(fh
->fh_Buf
))[fh
->fh_Pos
]=character
;
96 return character
?character
:1;