| 299 | */ |
| 300 | |
| 301 | int /* O - 0 on success, -1 on error */ |
| 302 | cupsdRemoveFile(const char *filename) /* I - File to remove */ |
| 303 | { |
| 304 | #ifdef HAVE_REMOVEFILE |
| 305 | /* |
| 306 | * See if the file exists... |
| 307 | */ |
| 308 | |
| 309 | if (access(filename, 0)) |
| 310 | return (0); |
| 311 | |
| 312 | cupsdLogMessage(CUPSD_LOG_DEBUG, "Securely removing \"%s\".", filename); |
| 313 | |
| 314 | /* |
| 315 | * Remove the file... |
| 316 | */ |
| 317 | |
| 318 | return (removefile(filename, NULL, REMOVEFILE_SECURE_1_PASS)); |
| 319 | |
| 320 | #else |
| 321 | int fd; /* File descriptor */ |
| 322 | struct stat info; /* File information */ |
| 323 | char buffer[512]; /* Data buffer */ |
| 324 | size_t i; /* Looping var */ |
| 325 | |
| 326 | |
| 327 | /* |
| 328 | * See if the file exists... |
| 329 | */ |
| 330 | |
| 331 | if (access(filename, 0)) |
| 332 | return (0); |
| 333 | |
| 334 | cupsdLogMessage(CUPSD_LOG_DEBUG, "Securely removing \"%s\".", filename); |
| 335 | |
| 336 | /* |
| 337 | * First open the file for writing in exclusive mode. |
| 338 | */ |
| 339 | |
| 340 | if ((fd = open(filename, O_WRONLY | O_EXCL)) < 0) |
| 341 | return (-1); |
| 342 | |
| 343 | /* |
| 344 | * Delete the file now - it will still be around as long as the file is |
| 345 | * open... |
| 346 | */ |
| 347 | |
| 348 | if (unlink(filename)) |
| 349 | { |
| 350 | close(fd); |
| 351 | return (-1); |
| 352 | } |
| 353 | |
| 354 | /* |
| 355 | * Then get the file size... |
| 356 | */ |
| 357 | |
| 358 | if (fstat(fd, &info)) |
no test coverage detected