Changeset 4028 for zzuf/trunk


Ignore:
Timestamp:
Nov 24, 2009, 2:25:37 AM (10 years ago)
Author:
Sam Hocevar
Message:

More zzcat additions.

Location:
zzuf/trunk/test
Files:
2 edited

Legend:

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

    r4010 r4028  
    2424                 200 201 202 203 204 205 206 207 208 209 210 211 212 \
    2525                 300 301 302 303 304 305 306 307 308 309 310 311 \
    26                  400 \
    27                  500 \
    28                  600; do
     26                 400 401 402 403 404 \
     27                 500; do
    2928            check "$ZZOPTS" "$ZZCAT $n $file" "zzcat $n"
    3029        done
  • zzuf/trunk/test/zzcat.c

    r4010 r4028  
    4040static int zzcat_read(char const *, unsigned char *, int64_t, int64_t);
    4141static int zzcat_fread(char const *, unsigned char *, int64_t);
     42static int zzcat_fread_fseek(char const *, unsigned char *, int64_t, int64_t);
    4243#if defined HAVE_GETLINE
    4344static int zzcat_getline_getc(char const *, unsigned char *, int64_t, int);
     
    140141#   endif
    141142#endif
    142         /* Complex socket calls */
    143         case 400: ret = zzcat_random_socket(name, data, len); break;
    144         /* Complex stream calls */
    145         case 500: ret = zzcat_random_stream(name, data, len); break;
     143        /* Incomplete calls (but still OK since data is pre-filled) */
     144        case 400: ret = zzcat_fread_fseek(name, data, len, 1); break;
     145        case 401: ret = zzcat_fread_fseek(name, data, len, 2); break;
     146        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;
    146149        /* Misc */
    147150#if defined HAVE_MMAP
    148         case 600: ret = zzcat_random_mmap(name, data, len); break;
     151        case 500: ret = zzcat_random_mmap(name, data, len); break;
    149152#endif
    150153        default: ret = EXIT_SUCCESS;
     
    180183    for(i = 0; i < len; i++)
    181184        fread(data + i, 1, 1, stream);
     185    fclose(stream);
     186    return EXIT_SUCCESS;
     187}
     188
     189/* Only fread() and fseek() calls */
     190static int zzcat_fread_fseek(char const *name, unsigned char *data,
     191                             int64_t len, int64_t chunk)
     192{
     193    FILE *stream = fopen(name, "r");
     194    int i;
     195    if(!stream)
     196        return EXIT_FAILURE;
     197    for(i = 0; i < len; )
     198    {
     199        fread(data + i, chunk, 1, stream);
     200        i += chunk;
     201        if (i >= len)
     202            break;
     203        fseek(stream, chunk, SEEK_CUR);
     204        i += chunk;
     205    }
    182206    fclose(stream);
    183207    return EXIT_SUCCESS;
Note: See TracChangeset for help on using the changeset viewer.