| 406 | */ |
| 407 | |
| 408 | static int /* O - 0 on success, -1 on error */ |
| 409 | overwrite_data(int fd, /* I - File descriptor */ |
| 410 | const char *buffer, /* I - Buffer to write */ |
| 411 | int bufsize, /* I - Size of buffer */ |
| 412 | int filesize) /* I - Size of file */ |
| 413 | { |
| 414 | int bytes; /* Bytes to write/written */ |
| 415 | |
| 416 | |
| 417 | /* |
| 418 | * Start at the beginning of the file... |
| 419 | */ |
| 420 | |
| 421 | if (lseek(fd, 0, SEEK_SET) < 0) |
| 422 | return (-1); |
| 423 | |
| 424 | /* |
| 425 | * Fill the file with the provided data... |
| 426 | */ |
| 427 | |
| 428 | while (filesize > 0) |
| 429 | { |
| 430 | if (filesize > bufsize) |
| 431 | bytes = bufsize; |
| 432 | else |
| 433 | bytes = filesize; |
| 434 | |
| 435 | if ((bytes = write(fd, buffer, (size_t)bytes)) < 0) |
| 436 | return (-1); |
| 437 | |
| 438 | filesize -= bytes; |
| 439 | } |
| 440 | |
| 441 | /* |
| 442 | * Force the changes to disk... |
| 443 | */ |
| 444 | |
| 445 | return (fsync(fd)); |
| 446 | } |
| 447 | #endif /* HAVE_REMOVEFILE */ |