Turkish Q Standard PC105 Keymap
[AROS.git] / rom / dos / ungetc.c
blob15b9db46aa3c8cc109b1926d8ac9926140bbdc9c
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: english
7 */
8 #include <proto/exec.h>
9 #include "dos_intern.h"
11 #ifndef EOF
12 #define EOF -1
13 #endif
15 /*****************************************************************************
17 NAME */
18 #include <proto/dos.h>
20 AROS_LH2(LONG, UnGetC,
22 /* SYNOPSIS */
23 AROS_LHA(BPTR, file, D1),
24 AROS_LHA(LONG, character, D2),
26 /* LOCATION */
28 struct DosLibrary *, DOSBase, 53, Dos)
30 /* FUNCTION
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
34 works for EOF.
36 INPUTS
37 file - Filehandle you've read from.
38 character - Character to push back or EOF.
40 RESULT
41 !=0 if all went well, 0 if the character couldn't be pushed back.
42 IoErr() gives additional information in that case.
44 NOTES
46 EXAMPLE
48 BUGS
50 SEE ALSO
51 FGetC(), IoErr()
53 INTERNALS
55 *****************************************************************************/
57 AROS_LIBFUNC_INIT
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;
68 return 0;
71 /* Unget EOF character if the last character read was an EOF */
72 if(character==EOF&&fh->fh_End==0)
74 fh->fh_Pos++;
75 return EOF;
78 /* Test if I may unget a character on this file */
79 if(fh->fh_Pos==0)
81 *result=ERROR_SEEK_ERROR;
82 return 0;
85 /* OK. Unget character and return. */
86 fh->fh_Pos--;
87 if(character!=EOF)
88 ((UBYTE *)BADDR(fh->fh_Buf))[fh->fh_Pos]=character;
89 return character?character:1;
90 AROS_LIBFUNC_EXIT
91 } /* UnGetC */