/[hydra]/hydra/src/util.c
ViewVC logotype

Diff of /hydra/src/util.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.7 by nmav, Sat Sep 28 16:32:37 2002 UTC revision 1.8 by nmav, Sat Sep 28 17:49:13 2002 UTC
# Line 451  long boa_atol(const char *s) Line 451  long boa_atol(const char *s)
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();
# Line 469  int create_temporary_file(short want_unl Line 481  int create_temporary_file(short want_unl
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;

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.8

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26