Changeset 1791 for zzuf/trunk/src/fd.c
- Timestamp:
- Jul 6, 2007, 3:40:55 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
zzuf/trunk/src/fd.c
r1730 r1791 35 35 #include "libzzuf.h" 36 36 #include "fd.h" 37 #include "fuzz.h" 37 38 38 39 /* Regex stuff */ … … 41 42 static int has_include = 0, has_exclude = 0; 42 43 #endif 44 45 /* File descriptor cherry picking */ 46 static int *ranges = NULL; 47 static int ranges_static[512]; 43 48 44 49 /* File descriptor stuff. When program is launched, we use the static array of … … 50 55 static struct files 51 56 { 52 int managed, locked ;57 int managed, locked, active; 53 58 int64_t pos; 54 59 /* Public stuff */ … … 88 93 (void)regex; 89 94 #endif 95 } 96 97 /* This function is the same as _zz_bytes() */ 98 void _zz_pick(char const *list) 99 { 100 char const *parser; 101 unsigned int i, chunks; 102 103 /* Count commas */ 104 for(parser = list, chunks = 1; *parser; parser++) 105 if(*parser == ',') 106 chunks++; 107 108 /* TODO: free(ranges) if ranges != ranges_static */ 109 if(chunks >= 256) 110 ranges = malloc((chunks + 1) * 2 * sizeof(unsigned int)); 111 else 112 ranges = ranges_static; 113 114 /* Fill ranges list */ 115 for(parser = list, i = 0; i < chunks; i++) 116 { 117 char const *comma = strchr(parser, ','); 118 char const *dash = strchr(parser, '-'); 119 120 ranges[i * 2] = (dash == parser) ? 0 : atoi(parser); 121 if(dash && (dash + 1 == comma || dash[1] == '\0')) 122 ranges[i * 2 + 1] = ranges[i * 2]; /* special case */ 123 else if(dash && (!comma || dash < comma)) 124 ranges[i * 2 + 1] = atoi(dash + 1) + 1; 125 else 126 ranges[i * 2 + 1] = ranges[i * 2] + 1; 127 parser = comma + 1; 128 } 129 130 ranges[i * 2] = ranges[i * 2 + 1] = 0; 90 131 } 91 132 … … 259 300 files[i].fuzz.uflag = 0; 260 301 302 /* Check whether we should ignore the fd */ 303 if(ranges) 304 { 305 static int idx = 0; 306 int *r; 307 308 idx++; 309 310 for(r = ranges; r[1]; r += 2) 311 if(idx >= r[0] && (r[0] == r[1] || idx < r[1])) 312 goto range_ok; 313 314 files[i].active = 0; 315 } 316 else 317 { 318 range_ok: 319 files[i].active = 1; 320 } 321 261 322 if(autoinc) 262 323 seed++; … … 312 373 } 313 374 375 int _zz_isactive(int fd) 376 { 377 if(fd < 0 || fd >= maxfd || fds[fd] == -1) 378 return 1; 379 380 return files[fds[fd]].active; 381 } 382 314 383 int64_t _zz_getpos(int fd) 315 384 {
Note: See TracChangeset
for help on using the changeset viewer.