451 |
return retval; |
return retval; |
452 |
} |
} |
453 |
|
|
454 |
|
#define TEMP_FILE_TEMPLATE "/hydra.temp.XXXXXX" |
455 |
|
#define TEMP_FILE_TEMPLATE_LEN sizeof(TEMP_FILE_TEMPLATE)-1 |
456 |
|
|
457 |
/* returns -1 on error */ |
/* returns -1 on error */ |
458 |
int create_temporary_file(short want_unlink, char *storage, int size) |
int create_temporary_file(short want_unlink, char *storage, int size) |
459 |
{ |
{ |
460 |
char boa_tempfile[MAX_PATH_LENGTH + 1]; |
char boa_tempfile[MAX_PATH_LENGTH + 1]; |
461 |
int fd; |
int fd, total_len; |
462 |
|
|
463 |
|
total_len = tempdir_len + TEMP_FILE_TEMPLATE_LEN; |
464 |
|
if (total_len > MAX_PATH_LENGTH) { |
465 |
|
log_error_time(); |
466 |
|
fprintf(stderr, "Temporary file length (%d) is too long\n", total_len); |
467 |
|
return -1; |
468 |
|
} |
469 |
|
|
470 |
snprintf(boa_tempfile, MAX_PATH_LENGTH, |
memcpy( boa_tempfile, tempdir, tempdir_len); |
471 |
"%s/boa-temp.XXXXXX", tempdir); |
memcpy( &boa_tempfile[tempdir_len], TEMP_FILE_TEMPLATE, TEMP_FILE_TEMPLATE_LEN); |
472 |
|
boa_tempfile[total_len] = 0; /* null terminated */ |
473 |
|
|
474 |
/* open temp file */ |
/* open temp file |
475 |
|
*/ |
476 |
fd = mkstemp(boa_tempfile); |
fd = mkstemp(boa_tempfile); |
477 |
if (fd == -1) { |
if (fd == -1) { |
478 |
log_error_time(); |
log_error_time(); |
481 |
} |
} |
482 |
|
|
483 |
if (storage != NULL) { |
if (storage != NULL) { |
484 |
int len = strlen(boa_tempfile); |
if (total_len < size) { |
485 |
|
memcpy(storage, boa_tempfile, total_len + 1); |
|
if (len < size) { |
|
|
memcpy(storage, boa_tempfile, len + 1); |
|
486 |
} else { |
} else { |
487 |
close(fd); |
close(fd); |
488 |
fd = -1; |
fd = -1; |