Changeset 63088cc1 in mainline for uspace/lib/libc/generic/io/stdio.c


Ignore:
Timestamp:
2008-12-29T13:30:19Z (15 years ago)
Author:
Jiri Svoboda <jirik.svoboda@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1c1002a
Parents:
04b687b
Message:

fgetc(), fputc(), fputs(), fseek().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/libc/generic/io/stdio.c

    r04b687b r63088cc1  
    216216}
    217217
     218/** Read character from a stream. */
     219int fgetc(FILE *f)
     220{
     221        unsigned char c;
     222        size_t n;
     223
     224        n = fread(&c, sizeof(c), 1, f);
     225        if (n < 1) return EOF;
     226
     227        return (int) c;
     228}
     229
     230/** Write character to a stream. */
     231int fputc(int c, FILE *f)
     232{
     233        unsigned char cc;
     234        size_t n;
     235
     236        cc = (unsigned char) c;
     237        n = fwrite(&cc, sizeof(cc), 1, f);
     238        if (n < 1) return EOF;
     239
     240        return (int) cc;
     241}
     242
     243/** Write string to a stream. */
     244int fputs(const char *s, FILE *f)
     245{
     246        int rc;
     247
     248        rc = 0;
     249
     250        while (*s && rc >= 0) {
     251                rc = fputc(*s++, f);
     252        }
     253
     254        if (rc < 0) return EOF;
     255
     256        return 0;
     257}
     258
     259/** Seek to position in stream. */
     260int fseek(FILE *f, long offset, int origin)
     261{
     262        off_t rc;
     263
     264        rc = lseek(f->fd, offset, origin);
     265        if (rc == (off_t) (-1)) {
     266                /* errno has been set by lseek. */
     267                return -1;
     268        }
     269
     270        f->eof = 0;
     271
     272        return 0;
     273}
     274
    218275/** @}
    219276 */
Note: See TracChangeset for help on using the changeset viewer.