| File: | pr/Linux6.7_x86_64_gcc_glibc_PTH_64_DBG.OBJ/pr/tests/../../../pr/tests/bigfile.c |
| Warning: | line 146, column 17 Value stored to 'keep' is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
| 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
| 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 5 | |
| 6 | #include "prio.h" |
| 7 | #include "prmem.h" |
| 8 | #include "prprf.h" |
| 9 | #include "prinit.h" |
| 10 | #include "prerror.h" |
| 11 | #include "prthread.h" |
| 12 | |
| 13 | #include "plerror.h" |
| 14 | #include "plgetopt.h" |
| 15 | |
| 16 | #define DEFAULT_COUNT10 10 |
| 17 | #define DEFAULT_FILESIZE1 1 |
| 18 | #define BUFFER_SIZE1000000 1000000 |
| 19 | |
| 20 | typedef enum {v_silent, v_whisper, v_shout} Verbosity; |
| 21 | static void Verbose(Verbosity, const char*, const char*, PRIntn); |
| 22 | |
| 23 | #define VERBOSE(_l, _m)Verbose(_l, _m, "../../../pr/tests/bigfile.c", 23) Verbose(_l, _m, __FILE__"../../../pr/tests/bigfile.c", __LINE__23) |
| 24 | |
| 25 | static PRIntn test_result = 2; |
| 26 | static PRFileDesc *output = NULL((void*)0); |
| 27 | static PRIntn verbose = v_silent; |
| 28 | static PRIntn filesize = DEFAULT_FILESIZE1; |
| 29 | |
| 30 | static PRIntn Usage(void) |
| 31 | { |
| 32 | PR_fprintf(output, "Bigfile test usage:\n"); |
| 33 | PR_fprintf(output, ">bigfile [-G] [-d] [-v[*v]] [-s <n>] <filename>\n"); |
| 34 | PR_fprintf(output, "\td\tdebug mode (equivalent to -vvv)\t(false)\n"); |
| 35 | PR_fprintf(output, "\tv\tAdditional levels of output\t(none)\n"); |
| 36 | PR_fprintf(output, "\tk\tKeep data file after exit\t(false)\n"); |
| 37 | PR_fprintf(output, "\ts <n>\tFile size in megabytes\t\t(1 megabyte)\n"); |
| 38 | PR_fprintf(output, "\t<filename>\tName of test file\t(none)\n"); |
| 39 | return 2; /* nothing happened */ |
| 40 | } /* Usage */ |
| 41 | |
| 42 | static PRStatus DeleteIfFound(const char *filename) |
| 43 | { |
| 44 | PRStatus rv; |
| 45 | VERBOSE(v_shout, "Checking for existing file")Verbose(v_shout, "Checking for existing file", "../../../pr/tests/bigfile.c" , 45); |
| 46 | rv = PR_Access(filename, PR_ACCESS_WRITE_OK); |
| 47 | if (PR_SUCCESS == rv) |
| 48 | { |
| 49 | VERBOSE(v_shout, "Deleting existing file")Verbose(v_shout, "Deleting existing file", "../../../pr/tests/bigfile.c" , 49); |
| 50 | rv = PR_Delete(filename); |
| 51 | if (PR_FAILURE == rv) { |
| 52 | VERBOSE(v_shout, "Cannot delete big file")Verbose(v_shout, "Cannot delete big file", "../../../pr/tests/bigfile.c" , 52); |
| 53 | } |
| 54 | } |
| 55 | else if (PR_FILE_NOT_FOUND_ERROR(-5950L) != PR_GetError()) { |
| 56 | VERBOSE(v_shout, "Cannot access big file")Verbose(v_shout, "Cannot access big file", "../../../pr/tests/bigfile.c" , 56); |
| 57 | } |
| 58 | else { |
| 59 | rv = PR_SUCCESS; |
| 60 | } |
| 61 | return rv; |
| 62 | } /* DeleteIfFound */ |
| 63 | |
| 64 | static PRIntn Error(const char *msg, const char *filename) |
| 65 | { |
| 66 | PRInt32 error = PR_GetError(); |
| 67 | if (NULL((void*)0) != msg) |
| 68 | { |
| 69 | if (0 == error) { |
| 70 | PR_fprintf(output, msg); |
| 71 | } |
| 72 | else { |
| 73 | PL_FPrintError(output, msg); |
| 74 | } |
| 75 | } |
| 76 | (void)DeleteIfFound(filename); |
| 77 | if (v_shout == verbose) { |
| 78 | PR_Abort(); |
| 79 | } |
| 80 | return 1; |
| 81 | } /* Error */ |
| 82 | |
| 83 | static void Verbose( |
| 84 | Verbosity level, const char *msg, const char *file, PRIntn line) |
| 85 | { |
| 86 | if (level <= verbose) { |
| 87 | PR_fprintf(output, "[%s : %d]: %s\n", file, line, msg); |
| 88 | } |
| 89 | } /* Verbose */ |
| 90 | |
| 91 | static void PrintInfo(PRFileInfo64 *info, const char *filename) |
| 92 | { |
| 93 | PRExplodedTime tm; |
| 94 | char ctime[40], mtime[40]; |
| 95 | static const char *types[] = {"FILE", "DIRECTORY", "OTHER"}; |
| 96 | PR_fprintf( |
| 97 | output, "[%s : %d]: File info for %s\n", |
| 98 | __FILE__"../../../pr/tests/bigfile.c", __LINE__98, filename); |
| 99 | PR_fprintf( |
| 100 | output, " type: %s, size: %llu bytes,\n", |
| 101 | types[info->type - 1], info->size); |
| 102 | |
| 103 | PR_ExplodeTime(info->creationTime, PR_GMTParameters, &tm); |
| 104 | (void)PR_FormatTime(ctime, sizeof(ctime), "%c GMT", &tm); |
| 105 | PR_ExplodeTime(info->modifyTime, PR_GMTParameters, &tm); |
| 106 | (void)PR_FormatTime(mtime, sizeof(mtime), "%c GMT", &tm); |
| 107 | |
| 108 | PR_fprintf( |
| 109 | output, " creation: %s,\n modify: %s\n", ctime, mtime); |
| 110 | } /* PrintInfo */ |
| 111 | |
| 112 | int main(int argc, char **argv) |
| 113 | { |
| 114 | PRStatus rv; |
| 115 | char *buffer; |
| 116 | PLOptStatus os; |
| 117 | PRInt32 loop, bytes; |
| 118 | PRFileInfo small_info; |
| 119 | PRFileInfo64 big_info; |
| 120 | PRBool keep = PR_FALSE0; |
| 121 | PRFileDesc *file = NULL((void*)0); |
| 122 | const char *filename = NULL((void*)0); |
| 123 | PRIntn count = DEFAULT_COUNT10; |
| 124 | PRInt64 filesize64, big_answer, big_size, one_meg, zero_meg, big_fragment; |
| 125 | PRInt64 sevenFox = LL_INIT(0,0x7fffffff)((0L << 32) + 0x7fffffffL); |
| 126 | |
| 127 | PLOptState *opt = PL_CreateOptState(argc, argv, "dtvhs:"); |
| 128 | |
| 129 | output = PR_GetSpecialFD(PR_StandardError); |
| 130 | PR_STDIO_INIT(); |
| 131 | |
| 132 | while (PL_OPT_EOL != (os = PL_GetNextOpt(opt))) |
| 133 | { |
| 134 | if (PL_OPT_BAD == os) { |
| 135 | continue; |
| 136 | } |
| 137 | switch (opt->option) |
| 138 | { |
| 139 | case 0: |
| 140 | filename = opt->value; |
| 141 | break; |
| 142 | case 'd': /* debug mode */ |
| 143 | verbose = v_shout; |
| 144 | break; |
| 145 | case 'k': /* keep file */ |
| 146 | keep = PR_TRUE1; |
Value stored to 'keep' is never read | |
| 147 | break; |
| 148 | case 'v': /* verbosity */ |
| 149 | if (v_shout > verbose) { |
| 150 | verbose += 1; |
| 151 | } |
| 152 | break; |
| 153 | case 'c': /* loop counter */ |
| 154 | count = atoi(opt->value); |
| 155 | break; |
| 156 | case 's': /* filesize */ |
| 157 | filesize = atoi(opt->value); |
| 158 | break; |
| 159 | case 'h': /* confused */ |
| 160 | default: |
| 161 | return Usage(); |
| 162 | } |
| 163 | } |
| 164 | PL_DestroyOptState(opt); |
| 165 | |
| 166 | if (0 == count) { |
| 167 | count = DEFAULT_COUNT10; |
| 168 | } |
| 169 | if (0 == filesize) { |
| 170 | filesize = DEFAULT_FILESIZE1; |
| 171 | } |
| 172 | if (NULL((void*)0) == filename) |
| 173 | { |
| 174 | #define FILE_NAME"bigfile.dat" "bigfile.dat" |
| 175 | if (DEFAULT_FILESIZE1 != filesize) { |
| 176 | return Usage(); |
| 177 | } |
| 178 | else { |
| 179 | filename = FILE_NAME"bigfile.dat"; |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | if (PR_FAILURE == DeleteIfFound(filename)) { |
| 184 | return 1; |
| 185 | } |
| 186 | |
| 187 | test_result = 0; |
| 188 | |
| 189 | LL_I2L(zero_meg, 0)((zero_meg) = (PRInt64)(0)); |
| 190 | LL_I2L(one_meg, 1000000)((one_meg) = (PRInt64)(1000000)); |
| 191 | LL_I2L(filesize64, filesize)((filesize64) = (PRInt64)(filesize)); |
| 192 | buffer = (char*)PR_MALLOC(BUFFER_SIZE)(PR_Malloc((1000000))); |
| 193 | LL_I2L(big_fragment, BUFFER_SIZE)((big_fragment) = (PRInt64)(1000000)); |
| 194 | LL_MUL(filesize64, filesize64, one_meg)((filesize64) = (filesize64) * (one_meg)); |
| 195 | |
| 196 | for (loop = 0; loop < BUFFER_SIZE1000000; ++loop) { |
| 197 | buffer[loop] = (char)loop; |
| 198 | } |
| 199 | |
| 200 | VERBOSE(v_whisper, "Creating big file")Verbose(v_whisper, "Creating big file", "../../../pr/tests/bigfile.c" , 200); |
| 201 | file = PR_Open(filename, PR_CREATE_FILE0x08 | PR_WRONLY0x02, 0666); |
| 202 | if (NULL((void*)0) == file) { |
| 203 | return Error("PR_Open()", filename); |
| 204 | } |
| 205 | |
| 206 | VERBOSE(v_whisper, "Testing available space in empty file")Verbose(v_whisper, "Testing available space in empty file", "../../../pr/tests/bigfile.c" , 206); |
| 207 | big_answer = file->methods->available64(file); |
| 208 | if (!LL_IS_ZERO(big_answer)((big_answer) == 0)) { |
| 209 | return Error("empty available64()", filename); |
| 210 | } |
| 211 | |
| 212 | LL_SUB(big_size, filesize64, one_meg)((big_size) = (filesize64) - (one_meg)); |
| 213 | VERBOSE(v_whisper, "Creating sparse big file by seeking to end")Verbose(v_whisper, "Creating sparse big file by seeking to end" , "../../../pr/tests/bigfile.c", 213); |
| 214 | big_answer = file->methods->seek64(file, big_size, PR_SEEK_SET); |
| 215 | if (!LL_EQ(big_answer, big_size)((big_answer) == (big_size))) { |
| 216 | return Error("seek", filename); |
| 217 | } |
| 218 | |
| 219 | VERBOSE(v_whisper, "Writing block at end of sparse file")Verbose(v_whisper, "Writing block at end of sparse file", "../../../pr/tests/bigfile.c" , 219); |
| 220 | bytes = file->methods->write(file, buffer, BUFFER_SIZE1000000); |
| 221 | if (bytes != BUFFER_SIZE1000000) { |
| 222 | return Error("write", filename); |
| 223 | } |
| 224 | |
| 225 | VERBOSE(v_whisper, "Testing available space at end of sparse file")Verbose(v_whisper, "Testing available space at end of sparse file" , "../../../pr/tests/bigfile.c", 225); |
| 226 | big_answer = file->methods->available64(file); |
| 227 | if (!LL_IS_ZERO(big_answer)((big_answer) == 0)) { |
| 228 | return Error("eof available64()", filename); |
| 229 | } |
| 230 | |
| 231 | VERBOSE(v_whisper, "Getting big info on sparse big file")Verbose(v_whisper, "Getting big info on sparse big file", "../../../pr/tests/bigfile.c" , 231); |
| 232 | rv = file->methods->fileInfo64(file, &big_info); |
| 233 | if (PR_FAILURE == rv) { |
| 234 | return Error("fileInfo64()", filename); |
| 235 | } |
| 236 | if (v_shout <= verbose) { |
| 237 | PrintInfo(&big_info, filename); |
| 238 | } |
| 239 | |
| 240 | VERBOSE(v_whisper, "Getting small info on sparse big file")Verbose(v_whisper, "Getting small info on sparse big file", "../../../pr/tests/bigfile.c" , 240); |
| 241 | rv = file->methods->fileInfo(file, &small_info); |
| 242 | if (LL_CMP(sevenFox, <, filesize64)((PRInt64)(sevenFox) < (PRInt64)(filesize64)) && (PR_SUCCESS == rv)) |
| 243 | { |
| 244 | VERBOSE(v_whisper, "Should have failed and didn't")Verbose(v_whisper, "Should have failed and didn't", "../../../pr/tests/bigfile.c" , 244); |
| 245 | return Error("fileInfo()", filename); |
| 246 | } |
| 247 | else if (LL_CMP(sevenFox, >, filesize64)((PRInt64)(sevenFox) > (PRInt64)(filesize64)) && (PR_FAILURE == rv)) |
| 248 | { |
| 249 | VERBOSE(v_whisper, "Should have succeeded and didn't")Verbose(v_whisper, "Should have succeeded and didn't", "../../../pr/tests/bigfile.c" , 249); |
| 250 | return Error("fileInfo()", filename); |
| 251 | } |
| 252 | |
| 253 | VERBOSE(v_whisper, "Rewinding big file")Verbose(v_whisper, "Rewinding big file", "../../../pr/tests/bigfile.c" , 253); |
| 254 | big_answer = file->methods->seek64(file, zero_meg, PR_SEEK_SET); |
| 255 | if (!LL_IS_ZERO(big_answer)((big_answer) == 0)) { |
| 256 | return Error("rewind seek64()", filename); |
| 257 | } |
| 258 | |
| 259 | VERBOSE(v_whisper, "Establishing available space in rewound file")Verbose(v_whisper, "Establishing available space in rewound file" , "../../../pr/tests/bigfile.c", 259); |
| 260 | big_answer = file->methods->available64(file); |
| 261 | if (LL_NE(filesize64, big_answer)((filesize64) != (big_answer))) { |
| 262 | return Error("bof available64()", filename); |
| 263 | } |
| 264 | |
| 265 | VERBOSE(v_whisper, "Closing big file")Verbose(v_whisper, "Closing big file", "../../../pr/tests/bigfile.c" , 265); |
| 266 | rv = file->methods->close(file); |
| 267 | if (PR_FAILURE == rv) { |
| 268 | return Error("close()", filename); |
| 269 | } |
| 270 | |
| 271 | VERBOSE(v_whisper, "Reopening big file")Verbose(v_whisper, "Reopening big file", "../../../pr/tests/bigfile.c" , 271); |
| 272 | file = PR_Open(filename, PR_RDWR0x04, 0666); |
| 273 | if (NULL((void*)0) == file) { |
| 274 | return Error("open failed", filename); |
| 275 | } |
| 276 | |
| 277 | VERBOSE(v_whisper, "Checking available data in reopened file")Verbose(v_whisper, "Checking available data in reopened file" , "../../../pr/tests/bigfile.c", 277); |
| 278 | big_answer = file->methods->available64(file); |
| 279 | if (LL_NE(filesize64, big_answer)((filesize64) != (big_answer))) { |
| 280 | return Error("reopened available64()", filename); |
| 281 | } |
| 282 | |
| 283 | big_answer = zero_meg; |
| 284 | VERBOSE(v_whisper, "Rewriting every byte of big file data")Verbose(v_whisper, "Rewriting every byte of big file data", "../../../pr/tests/bigfile.c" , 284); |
| 285 | do |
| 286 | { |
| 287 | bytes = file->methods->write(file, buffer, BUFFER_SIZE1000000); |
| 288 | if (bytes != BUFFER_SIZE1000000) { |
| 289 | return Error("write", filename); |
| 290 | } |
| 291 | LL_ADD(big_answer, big_answer, big_fragment)((big_answer) = (big_answer) + (big_fragment)); |
| 292 | } while (LL_CMP(big_answer, <, filesize64)((PRInt64)(big_answer) < (PRInt64)(filesize64))); |
| 293 | |
| 294 | VERBOSE(v_whisper, "Checking position at eof")Verbose(v_whisper, "Checking position at eof", "../../../pr/tests/bigfile.c" , 294); |
| 295 | big_answer = file->methods->seek64(file, zero_meg, PR_SEEK_CUR); |
| 296 | if (LL_NE(big_answer, filesize64)((big_answer) != (filesize64))) { |
| 297 | return Error("file size error", filename); |
| 298 | } |
| 299 | |
| 300 | VERBOSE(v_whisper, "Testing available space at eof")Verbose(v_whisper, "Testing available space at eof", "../../../pr/tests/bigfile.c" , 300); |
| 301 | big_answer = file->methods->available64(file); |
| 302 | if (!LL_IS_ZERO(big_answer)((big_answer) == 0)) { |
| 303 | return Error("eof available64()", filename); |
| 304 | } |
| 305 | |
| 306 | VERBOSE(v_whisper, "Rewinding full file")Verbose(v_whisper, "Rewinding full file", "../../../pr/tests/bigfile.c" , 306); |
| 307 | big_answer = file->methods->seek64(file, zero_meg, PR_SEEK_SET); |
| 308 | if (!LL_IS_ZERO(big_answer)((big_answer) == 0)) { |
| 309 | return Error("bof seek64()", filename); |
| 310 | } |
| 311 | |
| 312 | VERBOSE(v_whisper, "Testing available space in rewound file")Verbose(v_whisper, "Testing available space in rewound file", "../../../pr/tests/bigfile.c", 312); |
| 313 | big_answer = file->methods->available64(file); |
| 314 | if (LL_NE(big_answer, filesize64)((big_answer) != (filesize64))) { |
| 315 | return Error("bof available64()", filename); |
| 316 | } |
| 317 | |
| 318 | VERBOSE(v_whisper, "Seeking to end of big file")Verbose(v_whisper, "Seeking to end of big file", "../../../pr/tests/bigfile.c" , 318); |
| 319 | big_answer = file->methods->seek64(file, filesize64, PR_SEEK_SET); |
| 320 | if (LL_NE(big_answer, filesize64)((big_answer) != (filesize64))) { |
| 321 | return Error("eof seek64()", filename); |
| 322 | } |
| 323 | |
| 324 | VERBOSE(v_whisper, "Getting info on big file while it's open")Verbose(v_whisper, "Getting info on big file while it's open" , "../../../pr/tests/bigfile.c", 324); |
| 325 | rv = file->methods->fileInfo64(file, &big_info); |
| 326 | if (PR_FAILURE == rv) { |
| 327 | return Error("fileInfo64()", filename); |
| 328 | } |
| 329 | if (v_shout <= verbose) { |
| 330 | PrintInfo(&big_info, filename); |
| 331 | } |
| 332 | |
| 333 | VERBOSE(v_whisper, "Closing big file")Verbose(v_whisper, "Closing big file", "../../../pr/tests/bigfile.c" , 333); |
| 334 | rv = file->methods->close(file); |
| 335 | if (PR_FAILURE == rv) { |
| 336 | return Error("close()", filename); |
| 337 | } |
| 338 | |
| 339 | VERBOSE(v_whisper, "Getting info on big file after it's closed")Verbose(v_whisper, "Getting info on big file after it's closed" , "../../../pr/tests/bigfile.c", 339); |
| 340 | rv = PR_GetFileInfo64(filename, &big_info); |
| 341 | if (PR_FAILURE == rv) { |
| 342 | return Error("fileInfo64()", filename); |
| 343 | } |
| 344 | if (v_shout <= verbose) { |
| 345 | PrintInfo(&big_info, filename); |
| 346 | } |
| 347 | |
| 348 | VERBOSE(v_whisper, "Deleting big file")Verbose(v_whisper, "Deleting big file", "../../../pr/tests/bigfile.c" , 348); |
| 349 | rv = PR_Delete(filename); |
| 350 | if (PR_FAILURE == rv) { |
| 351 | return Error("PR_Delete()", filename); |
| 352 | } |
| 353 | |
| 354 | PR_DELETE(buffer){ PR_Free(buffer); (buffer) = ((void*)0); }; |
| 355 | return test_result; |
| 356 | } /* main */ |
| 357 | |
| 358 | /* bigfile.c */ |