Changeset 2407 for libcaca


Ignore:
Timestamp:
Jun 15, 2008, 3:50:06 PM (12 years ago)
Author:
Sam Hocevar
Message:
  • Implement cucul_file_tell().
Location:
libcaca/trunk/cucul
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/cucul/cucul.h

    r2406 r2407  
    286286__extern cucul_file_t *cucul_file_open(char const *, const char *);
    287287__extern int cucul_file_close(cucul_file_t *);
     288__extern uint64_t cucul_file_tell(cucul_file_t *);
    288289__extern size_t cucul_file_read(cucul_file_t *, void *, size_t);
    289290__extern size_t cucul_file_write(cucul_file_t *, const void *, size_t);
  • libcaca/trunk/cucul/file.c

    r2406 r2407  
    4444    z_stream stream;
    4545    gzFile gz;
    46     int eof, zip;
     46    int eof, zip, total;
    4747#   endif
    4848    FILE *f;
     
    5858    cucul_file_t *fp = malloc(sizeof(*fp));
    5959
    60     fp->readonly = !strchr(mode, 'r');
     60    fp->readonly = strchr(mode, 'r');
    6161
    6262#   if defined HAVE_ZLIB_H
     
    7373    fp->eof = 0;
    7474    fp->zip = 0;
     75    fp->total = 0;
    7576
    7677    if(fp->readonly)
     
    141142}
    142143
     144uint64_t cucul_file_tell(cucul_file_t *fp)
     145{
     146#if defined __KERNEL__
     147    return 0;
     148#elif defined HAVE_ZLIB_H
     149    if(fp->zip)
     150        return fp->total;
     151    return gztell(fp->gz);
     152#else
     153    return ftell(fp->f);
     154#endif
     155}
     156
    143157size_t cucul_file_read(cucul_file_t *fp, void *ptr, size_t size)
    144158{
     
    162176    return 0;
    163177#elif defined HAVE_ZLIB_H
     178    /* FIXME: zip files are not supported */
    164179    return gzwrite(fp->gz, ptr, size);
    165180#else
     
    247262        {
    248263            fp->eof = 1;
     264            fp->total += total_read;
    249265            return total_read;
    250266        }
     
    254270    }
    255271
     272    fp->total += total_read;
    256273    return total_read;
    257274}
Note: See TracChangeset for help on using the changeset viewer.