/* read a single line from stdin, replace the '\n' with '\0' */ char * gets(char *buf) { char *ptr = buf; ssize_t n; char *p; Uchar *bufend; rmutex_t *lk; FLOCKFILE(lk, stdin); _SET_ORIENTATION_BYTE(stdin); if (!(stdin->_flag & (_IOREAD | _IORW))) { errno = EBADF; FUNLOCKFILE(lk); return (0); } if (stdin->_base == NULL) { if ((bufend = _findbuf(stdin)) == 0) { FUNLOCKFILE(lk); return (0); } } else bufend = _bufend(stdin); for (;;) /* until get a '\n' */ { if (stdin->_cnt <= 0) /* empty buffer */ { if (__filbuf(stdin) != EOF) { stdin->_ptr--; /* put back the character */ stdin->_cnt++; } else if (ptr == buf) { /* never read anything */ FUNLOCKFILE(lk); return (0); } else break; /* nothing left to read */ } n = stdin->_cnt; if ((p = (char *)memccpy(ptr, (char *)stdin->_ptr, '\n', (size_t)n)) != 0) n = p - ptr; ptr += n; stdin->_cnt -= n; stdin->_ptr += n; if (_needsync(stdin, bufend)) _bufsync(stdin, bufend); if (p != 0) /* found a '\n' */ { ptr--; /* step back over the '\n' */ break; } } *ptr = '\0'; FUNLOCKFILE(lk); return (buf); }
_WCRTLINK int fgetc( FILE *fp ) { int c; _ValidFile( fp, EOF ); _AccessFile( fp ); /*** Deal with stream orientation ***/ ORIENT_STREAM( fp, EOF ); if( (fp->_flag & _READ) == 0 ) { _RWD_errno = EBADF; fp->_flag |= _SFERR; c = EOF; } else { fp->_cnt--; // it is important that this remain a relative comparison // to ensure that the getc() macro works properly if( fp->_cnt < 0 ) { c = __filbuf( fp ); } else { c = *fp->_ptr; fp->_ptr++; } } #ifndef __UNIX__ if( !(fp->_flag & _BINARY) ) { if( c == '\r' ) { fp->_cnt--; // it is important that this remain a relative comparison // to ensure that the getc() macro works properly if( fp->_cnt < 0 ) { c = __filbuf( fp ); } else { c = *fp->_ptr; fp->_ptr++; } } if( c == DOS_EOF_CHAR ) { fp->_flag |= _EOF; c = EOF; } } #endif _ReleaseFile( fp ); return( c ); }
int getc(FILE *iop) { rmutex_t *lk; int c; FLOCKFILE(lk, iop); _SET_ORIENTATION_BYTE(iop); c = (--iop->_cnt < 0) ? __filbuf(iop) : *iop->_ptr++; FUNLOCKFILE(lk); return (c); }
int getc_unlocked(FILE *iop) { return ((--iop->_cnt < 0) ? __filbuf(iop) : *iop->_ptr++); }
main() { int c, i; i = 0; while((c = (__us_rsthread_stdio ? __semgetc((&__iob[0])) : (--((&__iob[0]))->_count < 0 ? __filbuf((&__iob[0])) : (int)*((&__iob[0]))->_ptr++)) ) != (-1) ) { if (++i > 100) { printf("\n"); i = 0; } if (c == '\n') i = 0; (__us_rsthread_stdio ? __semputc((c), (&__iob[1])) : (--( (&__iob[1]))->_count < 0 ? __flsbuf(((c)), ( (&__iob[1]))) : (int)(*( (&__iob[1]))->_ptr++ = (unsigned char)((c))))) ; } }
int main () { int c_p743; int i_p744; int quesCol_p748; int pref_p752; int quesCol_p753; i_p744 = 0; goto whileCont_p746; whileTop_p745: ; i_p744 = (i_p744+1); pref_p752 = i_p744; if (pref_p752>100) { printf ((char *) "\n"); i_p744 = 0; } if (c_p743==10) i_p744 = 0; if (__us_rsthread_stdio) quesCol_p753 = __semputc (c_p743,(FILE_t96 *) (&__iob[1])); else { int quesCol_p754; int pref_p755; (*(&__iob[1]))._count = (((*(&__iob[1]))._count)-1); pref_p755 = ((*(&__iob[1]))._count); if (pref_p755<0) quesCol_p754 = __flsbuf (c_p743,(FILE_t96 *) (&__iob[1])); else { char *post_p756; post_p756 = ((*(&__iob[1]))._ptr); (*(&__iob[1]))._ptr = ((char *) (((int) ((*(&__iob[1]))._ptr))+1)); *post_p756 = ((char) c_p743); quesCol_p754 = ((int) (*post_p756)); } quesCol_p753 = quesCol_p754; } quesCol_p753; whileCont_p746: ; if (__us_rsthread_stdio) quesCol_p748 = __semgetc ((FILE_t96 *) (&__iob[0])); else { int quesCol_p749; int pref_p750; (*(&__iob[0]))._count = (((*(&__iob[0]))._count)-1); pref_p750 = ((*(&__iob[0]))._count); if (pref_p750<0) quesCol_p749 = __filbuf ((FILE_t96 *) (&__iob[0])); else { char *post_p751; post_p751 = ((*(&__iob[0]))._ptr); (*(&__iob[0]))._ptr = ((char *) (((int) ((*(&__iob[0]))._ptr))+1)); quesCol_p749 = ((int) (*post_p751)); } quesCol_p748 = quesCol_p749; } c_p743 = quesCol_p748; if (c_p743!=(-1)) goto whileTop_p745; }
int main () { int c_p600; int i_p601; int quesCol_p605; int pref_p609; int quesCol_p610; i_p601 = 0; goto whileCont_p603; whileTop_p602: ; i_p601 = (i_p601+1); pref_p609 = i_p601; if (pref_p609>100) goto whileBrk_p604; if (__us_rsthread_stdio) quesCol_p610 = __semputc (c_p600,(FILE_t81 *) (&__iob[1])); else { int quesCol_p611; int pref_p612; (*(&__iob[1]))._count = (((*(&__iob[1]))._count)-1); pref_p612 = ((*(&__iob[1]))._count); if (pref_p612<0) quesCol_p611 = __flsbuf (c_p600,(FILE_t81 *) (&__iob[1])); else { char *post_p613; post_p613 = ((*(&__iob[1]))._ptr); (*(&__iob[1]))._ptr = ((char *) (((int) ((*(&__iob[1]))._ptr))+1)); *post_p613 = ((char) c_p600); quesCol_p611 = ((int) (*post_p613)); } quesCol_p610 = quesCol_p611; } quesCol_p610; whileCont_p603: ; if (__us_rsthread_stdio) quesCol_p605 = __semgetc ((FILE_t81 *) (&__iob[0])); else { int quesCol_p606; int pref_p607; (*(&__iob[0]))._count = (((*(&__iob[0]))._count)-1); pref_p607 = ((*(&__iob[0]))._count); if (pref_p607<0) quesCol_p606 = __filbuf ((FILE_t81 *) (&__iob[0])); else { char *post_p608; post_p608 = ((*(&__iob[0]))._ptr); (*(&__iob[0]))._ptr = ((char *) (((int) ((*(&__iob[0]))._ptr))+1)); quesCol_p606 = ((int) (*post_p608)); } quesCol_p605 = quesCol_p606; } c_p600 = quesCol_p605; if (c_p600!=(-1)) goto whileTop_p602; whileBrk_p604: ; }