Changeset 2334 for zzuf


Ignore:
Timestamp:
May 18, 2008, 2:38:32 PM (12 years ago)
Author:
Sam Hocevar
Message:
  • Implement getchar() and getchar_unlocked().
Location:
zzuf/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • zzuf/trunk/doc/zzuf.1

    r2331 r2334  
    418418Standard IO streams:
    419419\fBfopen\fR(), \fBfreopen\fR(), \fBfseek\fR(), \fBfseeko\fR(), \fBrewind\fR(),
    420 \fBfread\fR(), \fBgetc\fR(), \fBfgetc\fR(), \fBfgets\fR(), \fBungetc\fR(),
    421 \fBfclose\fR()
     420\fBfread\fR(), \fBgetc\fR(), \fBgetchar\fR(), \fBfgetc\fR(), \fBfgets\fR(),
     421\fBungetc\fR(), \fBfclose\fR()
    422422.TP
    423423Memory management:
     
    428428\fBopen64\fR(), \fBlseek64\fR(), \fBmmap64\fR(), \fB_IO_getc\fR(),
    429429\fBgetline\fR(), \fBgetdelim\fR(), \fB__getdelim\fR(), \fBgetc_unlocked\fR(),
    430 \fBfgetc_unlocked\fR(), \fBfgets_unlocked\fR(), \fBfread_unlocked\fR()
     430\fBgetchar_unlocked\fR(), \fBfgetc_unlocked\fR(), \fBfgets_unlocked\fR(),
     431\fBfread_unlocked\fR()
    431432.TP
    432433BSD-specific:
     
    463464\fBhttp://sam.zoy.org/wtfpl/COPYING\fR for more details.
    464465.PP
    465 \fBzzuf\fR's webpage can be found at \fBhttp://libcaca.zoy.org/wiki/zzuf/\fR.
     466\fBzzuf\fR's webpage can be found at \fBhttp://libcaca.zoy.org/wiki/zzuf\fR.
  • zzuf/trunk/src/lib-stream.c

    r2332 r2334  
    6363#endif
    6464static int     (*ORIG(getc))     (FILE *stream);
     65static int     (*ORIG(getchar))  (void);
    6566static int     (*ORIG(fgetc))    (FILE *stream);
    6667#if defined HAVE__IO_GETC
     
    6869#endif
    6970#if defined HAVE_GETC_UNLOCKED
    70 static int     (*ORIG(getc_unlocked))  (FILE *stream);
     71static int     (*ORIG(getc_unlocked))    (FILE *stream);
     72#endif
     73#if defined HAVE_GETCHAR_UNLOCKED
     74static int     (*ORIG(getchar_unlocked)) (void);
    7175#endif
    7276#if defined HAVE_FGETC_UNLOCKED
    73 static int     (*ORIG(fgetc_unlocked)) (FILE *stream);
     77static int     (*ORIG(fgetc_unlocked))   (FILE *stream);
    7478#endif
    7579static char *  (*ORIG(fgets))    (char *s, int size, FILE *stream);
    7680#if defined HAVE_FGETS_UNLOCKED
    77 static char *  (*ORIG(fgets_unlocked)) (char *s, int size, FILE *stream);
     81static char *  (*ORIG(fgets_unlocked))   (char *s, int size, FILE *stream);
    7882#endif
    7983static int     (*ORIG(ungetc))   (int c, FILE *stream);
     
    318322#endif
    319323
    320 #define FGETC(fn) \
     324#define FGETC(fn, s, arg) \
    321325    do { \
    322326        int fd; \
    323327        LOADSYM(fn); \
    324         fd = fileno(stream); \
     328        fd = fileno(s); \
    325329        if(!_zz_ready || !_zz_iswatched(fd) || !_zz_isactive(fd)) \
    326             return ORIG(fn)(stream); \
     330            return ORIG(fn)(arg); \
    327331        _zz_lock(fd); \
    328         ret = ORIG(fn)(stream); \
     332        ret = ORIG(fn)(arg); \
    329333        _zz_unlock(fd); \
    330334        FGETC_FUZZ \
     
    338342int NEW(getc)(FILE *stream)
    339343{
    340     int ret; FGETC(getc); return ret;
     344    int ret; FGETC(getc, stream, stream); return ret;
     345}
     346
     347#undef getchar /* can be a macro; we don’t want that */
     348int NEW(getchar)(void)
     349{
     350    int ret; FGETC(getchar, stdin, /* empty */); return ret;
    341351}
    342352
    343353int NEW(fgetc)(FILE *stream)
    344354{
    345     int ret; FGETC(fgetc); return ret;
     355    int ret; FGETC(fgetc, stream, stream); return ret;
    346356}
    347357
     
    349359int NEW(_IO_getc)(FILE *stream)
    350360{
    351     int ret; FGETC(_IO_getc); return ret;
     361    int ret; FGETC(_IO_getc, stream, stream); return ret;
    352362}
    353363#endif
     
    357367int NEW(getc_unlocked)(FILE *stream)
    358368{
    359     int ret; FGETC(getc_unlocked); return ret;
     369    int ret; FGETC(getc_unlocked, stream, stream); return ret;
     370}
     371#endif
     372
     373#if defined HAVE_GETCHAR_UNLOCKED
     374#undef getchar_unlocked /* can be a macro; we don’t want that */
     375int NEW(getchar_unlocked)(void)
     376{
     377    int ret; FGETC(getchar_unlocked, stdin, /* empty */); return ret;
    360378}
    361379#endif
     
    365383int NEW(fgetc_unlocked)(FILE *stream)
    366384{
    367     int ret; FGETC(fgetc_unlocked); return ret;
     385    int ret; FGETC(fgetc_unlocked, stream, stream); return ret;
    368386}
    369387#endif
Note: See TracChangeset for help on using the changeset viewer.