Changeset 4030 for zzuf/trunk


Ignore:
Timestamp:
Nov 25, 2009, 1:42:17 AM (11 years ago)
Author:
Sam Hocevar
Message:

More zzcat stuff.

Location:
zzuf/trunk/test
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • zzuf/trunk/test/check-utils

    r4028 r4030  
    2222        fi
    2323        for n in 100 101 102 \
    24                  200 201 202 203 204 205 206 207 208 209 210 211 212 \
     24                 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 \
    2525                 300 301 302 303 304 305 306 307 308 309 310 311 \
    26                  400 401 402 403 404 \
     26                 400 401 402 403 404 405 406 407 \
    2727                 500; do
    2828            check "$ZZOPTS" "$ZZCAT $n $file" "zzcat $n"
  • zzuf/trunk/test/zzcat.c

    r4028 r4030  
    3939
    4040static int zzcat_read(char const *, unsigned char *, int64_t, int64_t);
    41 static int zzcat_fread(char const *, unsigned char *, int64_t);
     41static int zzcat_fread(char const *, unsigned char *, int64_t, int64_t);
    4242static int zzcat_fread_fseek(char const *, unsigned char *, int64_t, int64_t);
     43static int zzcat_fseek_fread(char const *, unsigned char *, int64_t, int64_t);
    4344#if defined HAVE_GETLINE
    4445static int zzcat_getline_getc(char const *, unsigned char *, int64_t, int);
     
    109110        case 102: ret = zzcat_read(name, data, len, len); break;
    110111        /* Simple stream calls */
    111         case 200: ret = zzcat_fread(name, data, len); break;
    112         case 201: ret = zzcat_fseek_getc(name, data, len, 0, 0); break;
    113         case 202: ret = zzcat_fseek_getc(name, data, len, 0, 1); break;
    114         case 203: ret = zzcat_fseek_getc(name, data, len, 2, 0); break;
    115         case 204: ret = zzcat_fseek_getc(name, data, len, 2, 1); break;
    116         case 205: ret = zzcat_fseek_getc(name, data, len, len / 2, 0); break;
    117         case 206: ret = zzcat_fseek_getc(name, data, len, len / 2, 1); break;
    118         case 207: ret = zzcat_fread_getc(name, data, len, 2, 0); break;
    119         case 208: ret = zzcat_fread_getc(name, data, len, 2, 1); break;
    120         case 209: ret = zzcat_fread_getc(name, data, len, len / 2, 0); break;
    121         case 210: ret = zzcat_fread_getc(name, data, len, len / 2, 1); break;
     112        case 200: ret = zzcat_fread(name, data, len, 1); break;
     113        case 201: ret = zzcat_fread(name, data, len, 2); break;
     114        case 202: ret = zzcat_fread(name, data, len, len); break;
     115        case 203: ret = zzcat_fseek_getc(name, data, len, 0, 0); break;
     116        case 204: ret = zzcat_fseek_getc(name, data, len, 0, 1); break;
     117        case 205: ret = zzcat_fseek_getc(name, data, len, 2, 0); break;
     118        case 206: ret = zzcat_fseek_getc(name, data, len, 2, 1); break;
     119        case 207: ret = zzcat_fseek_getc(name, data, len, len / 2, 0); break;
     120        case 208: ret = zzcat_fseek_getc(name, data, len, len / 2, 1); break;
     121        case 209: ret = zzcat_fread_getc(name, data, len, 2, 0); break;
     122        case 210: ret = zzcat_fread_getc(name, data, len, 2, 1); break;
     123        case 211: ret = zzcat_fread_getc(name, data, len, len / 2, 0); break;
     124        case 212: ret = zzcat_fread_getc(name, data, len, len / 2, 1); break;
    122125#if defined HAVE_GETLINE
    123         case 211: ret = zzcat_getline_getc(name, data, len, 0); break;
    124         case 212: ret = zzcat_getline_getc(name, data, len, 1); break;
     126        case 213: ret = zzcat_getline_getc(name, data, len, 0); break;
     127        case 214: ret = zzcat_getline_getc(name, data, len, 1); break;
    125128#endif
    126129        /* Simple unlocked stream calls */
     
    145148        case 401: ret = zzcat_fread_fseek(name, data, len, 2); break;
    146149        case 402: ret = zzcat_fread_fseek(name, data, len, 4000); break;
    147         case 403: ret = zzcat_random_socket(name, data, len); break;
    148         case 404: ret = zzcat_random_stream(name, data, len); break;
     150        case 403: ret = zzcat_fseek_fread(name, data, len, 1); break;
     151        case 404: ret = zzcat_fseek_fread(name, data, len, 2); break;
     152        case 405: ret = zzcat_fseek_fread(name, data, len, 4000); break;
     153        case 406: ret = zzcat_random_socket(name, data, len); break;
     154        case 407: ret = zzcat_random_stream(name, data, len); break;
    149155        /* Misc */
    150156#if defined HAVE_MMAP
     
    175181
    176182/* Only fread() calls */
    177 static int zzcat_fread(char const *name, unsigned char *data, int64_t len)
    178 {
    179     FILE *stream = fopen(name, "r");
    180     int i;
    181     if(!stream)
    182         return EXIT_FAILURE;
    183     for(i = 0; i < len; i++)
    184         fread(data + i, 1, 1, stream);
     183static int zzcat_fread(char const *name, unsigned char *data, int64_t len,
     184                       int64_t chunk)
     185{
     186    FILE *stream = fopen(name, "r");
     187    int i;
     188    if(!stream)
     189        return EXIT_FAILURE;
     190    for(i = 0; i < len; i += chunk)
     191        fread(data + i, chunk, 1, stream);
    185192    fclose(stream);
    186193    return EXIT_SUCCESS;
     
    202209            break;
    203210        fseek(stream, chunk, SEEK_CUR);
     211        i += chunk;
     212    }
     213    fclose(stream);
     214    return EXIT_SUCCESS;
     215}
     216
     217/* Only fseek() and fread() calls */
     218static int zzcat_fseek_fread(char const *name, unsigned char *data,
     219                             int64_t len, int64_t chunk)
     220{
     221    FILE *stream = fopen(name, "r");
     222    int i;
     223    if(!stream)
     224        return EXIT_FAILURE;
     225    for(i = 0; i < len; )
     226    {
     227        fseek(stream, chunk, SEEK_CUR);
     228        i += chunk;
     229        if (i >= len)
     230            break;
     231        fread(data + i, chunk, 1, stream);
    204232        i += chunk;
    205233    }
Note: See TracChangeset for help on using the changeset viewer.