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

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: fgets.c,v 1.3 1997/01/27 00:36:19 ldp Exp $
  4.  
  5.     Desc:
  6.     Lang: english
  7. */
  8. #include "dos_intern.h"
  9.  
  10. /*****************************************************************************
  11.  
  12.     NAME */
  13. #include <proto/dos.h>
  14.  
  15.     AROS_LH3(STRPTR, FGets,
  16.  
  17. /*  SYNOPSIS */
  18.     AROS_LHA(BPTR  , fh, D1),
  19.     AROS_LHA(STRPTR, buf, D2),
  20.     AROS_LHA(ULONG , buflen, D3),
  21.  
  22. /*  LOCATION */
  23.     struct DosLibrary *, DOSBase, 56, Dos)
  24.  
  25. /*  FUNCTION
  26.     Read until NEWLINE (\n), EOF is encountered or buflen-1
  27.     characters have been read. If a NEWLINE is read, it will
  28.     be the last character in the buffer. The buffer will always
  29.     be \0-terminated.
  30.  
  31.     INPUTS
  32.     fh - Read buffered from this filehandle
  33.     buf - Put read chars in this buffer
  34.     buflen - The size of the buffer
  35.  
  36.     RESULT
  37.     buf or NULL if the first thing read is EOF.
  38.  
  39.     NOTES
  40.  
  41.     EXAMPLE
  42.  
  43.     BUGS
  44.  
  45.     SEE ALSO
  46.  
  47.     INTERNALS
  48.  
  49.     HISTORY
  50.     27-11-96    digulla automatically created from
  51.                 dos_lib.fd and clib/dos_protos.h
  52.  
  53. *****************************************************************************/
  54. {
  55.     AROS_LIBFUNC_INIT
  56.     AROS_LIBBASE_EXT_DECL(struct DosLibrary *,DOSBase)
  57.     ULONG len;
  58.     LONG  c;
  59.  
  60.     buflen --;
  61.  
  62.     for (len=0; len<buflen; len++)
  63.     {
  64.     c = FGetC (fh);
  65.  
  66.     if (c == EOF)
  67.     {
  68.         if (len == 0)
  69.         return NULL;
  70.         else
  71.         break;
  72.     }
  73.  
  74.     buf[len++] = c;
  75.  
  76.     if (c == '\n')
  77.         break;
  78.     }
  79.  
  80.     buf[len] = 0;
  81.  
  82.     return buf;
  83.     AROS_LIBFUNC_EXIT
  84. } /* FGets */
  85.