Changes in benchmark/io/http/filecache.cfa [53e4562:0aec496]
- File:
-
- 1 edited
-
benchmark/io/http/filecache.cfa (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
benchmark/io/http/filecache.cfa
r53e4562 r0aec496 56 56 } 57 57 58 static inline [unsigned size, char unit] human_size( size_t size ) {59 int idx = 0;60 static char units [] = { ' ', 'K', 'M', 'G', 'T' };61 while( size >= 1024 ) {62 idx++;63 size /= 1024;64 if(idx >= 5) {65 abort("File too large to print\n");66 }67 }68 69 return [size, units[idx]];70 }71 58 72 59 struct { … … 114 101 void fill_cache( const char * path ) { 115 102 int ret; 116 ret = chdir(path);117 if(ret < 0) {118 abort( "chdir error: (%d) %s\n", (int)errno, strerror(errno) );119 }120 121 103 size_t fcount = 0; 122 104 size_t fsize = 16; … … 136 118 raw[idx].file = strdup(fpath+2); 137 119 raw[idx].size = sb->st_size; 138 if( !options.file_cache_list ) { 139 raw[idx].fd = open( fpath, options.open_flags ); 140 if(raw[idx].fd < 0) { 141 abort( "open file error: (%d) %s\n", (int)errno, strerror(errno) ); 142 } 120 raw[idx].fd = open( fpath, options.open_flags ); 121 if(raw[idx].fd < 0) { 122 abort( "open file error: (%d) %s\n", (int)errno, strerror(errno) ); 143 123 } 144 124 return 0; 145 125 } 146 126 147 ret = ftw( ".", walk, 10);127 ret = ftw(path, walk, 10); 148 128 if(ret < 0) { 149 129 abort( "ftw error: (%d) %s\n", (int)errno, strerror(errno) ); … … 152 132 if(fcount == 0) { 153 133 abort("No file found in path %s\n", path); 154 }155 156 if(options.file_cache_list) {157 printf("Listing files and exiting\n");158 for(i; fcount) {159 int s; char u;160 [s, u] = human_size(raw[i].size);161 printf("%4d%c - %s\n", s, u, raw[i].file);162 free(raw[i].file);163 }164 free(raw);165 exit(0);166 134 } 167 135
Note:
See TracChangeset
for help on using the changeset viewer.