home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / rom / dos / ungetc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-27  |  2.6 KB  |  115 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: ungetc.c,v 1.6 1997/01/27 00:36:33 ldp Exp $
  4.     $Log: ungetc.c,v $
  5.     Revision 1.6  1997/01/27 00:36:33  ldp
  6.     Polish
  7.  
  8.     Revision 1.5  1996/12/09 13:53:48  aros
  9.     Added empty templates for all missing functions
  10.  
  11.     Moved #include's into first column
  12.  
  13.     Revision 1.4  1996/10/24 15:50:38  aros
  14.     Use the official AROS macros over the __AROS versions.
  15.  
  16.     Revision 1.3  1996/08/13 13:52:52  digulla
  17.     Replaced <dos/dosextens.h> by "dos_intern.h" or added "dos_intern.h"
  18.     Replaced AROS_LA by AROS_LHA
  19.  
  20.     Revision 1.2  1996/08/01 17:40:58  digulla
  21.     Added standard header for all files
  22.  
  23.     Desc:
  24.     Lang: english
  25. */
  26. #include <proto/exec.h>
  27. #include "dos_intern.h"
  28.  
  29. #ifndef EOF
  30. #define EOF -1
  31. #endif
  32.  
  33. /*****************************************************************************
  34.  
  35.     NAME */
  36. #include <proto/dos.h>
  37.  
  38.     AROS_LH2(LONG, UnGetC,
  39.  
  40. /*  SYNOPSIS */
  41.     AROS_LHA(BPTR, file,      D1),
  42.     AROS_LHA(LONG, character, D2),
  43.  
  44. /*  LOCATION */
  45.  
  46.     struct DosLibrary *, DOSBase, 53, Dos)
  47.  
  48. /*  FUNCTION
  49.     Push a character back into a read filehandle. If you've read
  50.     a character from that file you may always push at least 1 character
  51.     back. UnGetC(file,-1) ungets the last character read. This also
  52.     works for EOF.
  53.  
  54.     INPUTS
  55.     file      - Filehandle you've read from.
  56.     character - Character to push back or EOF.
  57.  
  58.     RESULT
  59.     !=0 if all went well, 0 if the character couldn't be pushed back.
  60.     IoErr() gives additional information in that case.
  61.  
  62.     NOTES
  63.  
  64.     EXAMPLE
  65.  
  66.     BUGS
  67.  
  68.     SEE ALSO
  69.     FGetC(), IoErr()
  70.  
  71.     INTERNALS
  72.  
  73.     HISTORY
  74.     29-10-95    digulla automatically created from
  75.                 dos_lib.fd and clib/dos_protos.h
  76.  
  77. *****************************************************************************/
  78. {
  79.     AROS_LIBFUNC_INIT
  80.     AROS_LIBBASE_EXT_DECL(struct DosLibrary *,DOSBase)
  81.  
  82.     LONG *result=&((struct Process *)FindTask(NULL))->pr_Result2;
  83.  
  84.     /* Get pointer to filehandle */
  85.     struct FileHandle *fh=(struct FileHandle *)BADDR(file);
  86.  
  87.     /* If the file is in write mode there was nothing read recently */
  88.     if(fh->fh_Flags&FHF_WRITE)
  89.     {
  90.     *result=ERROR_SEEK_ERROR;
  91.     return 0;
  92.     }
  93.  
  94.     /* Unget EOF character if the last character read was an EOF */
  95.     if(character==EOF&&fh->fh_End==fh->fh_Buf)
  96.     {
  97.     fh->fh_Pos++;
  98.     return EOF;
  99.     }
  100.  
  101.     /* Test if I may unget a character on this file */
  102.     if(fh->fh_Pos==fh->fh_Buf)
  103.     {
  104.     *result=ERROR_SEEK_ERROR;
  105.     return 0;
  106.     }
  107.  
  108.     /* OK. Unget character and return. */
  109.     fh->fh_Pos--;
  110.     if(character!=EOF)
  111.     *fh->fh_Pos=character;
  112.     return character?character:1;
  113.     AROS_LIBFUNC_EXIT
  114. } /* UnGetC */
  115.