File:  [DVB] / dietlibc / libstdio / fgets.c
Revision 1.8: download - view: text, annotated - select for diffs
Mon Jul 7 18:09:34 2014 UTC (9 years, 10 months ago) by leitner
Branches: MAIN
CVS tags: HEAD
  fix fgets (Andreas Förster)

#include "dietstdio.h"

char *fgets_unlocked(char *s, int size, FILE *stream) {
  int l;
  if (size<=0) return 0;
  for (l=0; l+1<size; ) {
    register int c;
    if (l && __likely(stream->bm<stream->bs)) {
      /* try common case first */
      c=(unsigned char)stream->buf[stream->bm++];
    } else {
      c=fgetc_unlocked(stream);
      if (__unlikely(c==EOF)) {
	if (!l) return 0;
	break;
      }
    }
    s[l]=c;
    ++l;
    if (c=='\n') break;
  }
  s[l]=0;
  return s;
}

char*fgets(char*s,int size,FILE*stream) __attribute__((weak,alias("fgets_unlocked")));

LinuxTV legacy CVS <linuxtv.org/cvs>