- /* check to see if we've got the disk space */
- n_written = 0;
- while (n_written < file_size) {
- register int n_wrote;
- n_wrote = write(fd, buf, sizeof(buf));
- if (n_wrote == -1) {
- code = errno;
- sprintf(buf, "%s: verifying free disk space for %s (get_file)",
- error_message(code), pathname);
- sms_log_error(buf);
- /* do all we can to free the space */
- (void) unlink(pathname);
- (void) ftruncate(fd, 0);
- (void) close(fd);
- report_error("reporting test-write error (get_file)");
- return(1);
+
+ /* unlink old file */
+ if (!config_lookup("noclobber"))
+ unlink(pathname);
+ /* open file descriptor */
+ fd = open(pathname, O_CREAT|O_EXCL|O_WRONLY, mode);
+ if (fd == -1)
+ {
+ code = errno;
+ com_err(whoami, errno, "creating file %s (get_file)", pathname);
+ send_int(conn, code);
+ if (setuid(0) < 0)
+ {
+ com_err(whoami, errno, "Unable to setuid back to %d\n", 0);
+ exit(1);