View | Details | Raw Unified | Return to bug 16929
Collapse All | Expand All

(-)sort.c 2000/02/23 06:45:13 (-5 / +25 lines)
Lines 171-176 Link Here
171
171
172
/* Prefix for temporary file names. */
172
/* Prefix for temporary file names. */
173
static char *temp_file_prefix;
173
static char *temp_file_prefix;
174
/* Temporary dir for temp files, *with* above prefix */
175
static char *temp_dir = NULL;
174
176
175
/* Flag to reverse the order of all comparisons. */
177
/* Flag to reverse the order of all comparisons. */
176
static int reverse;
178
static int reverse;
Lines 288-293 Link Here
288
290
289
  for (node = temphead.next; node; node = node->next)
291
  for (node = temphead.next; node; node = node->next)
290
    unlink (node->name);
292
    unlink (node->name);
293
  if( temp_dir )
294
    rmdir(temp_dir);
295
291
}
296
}
292
297
293
/* Allocate N bytes of memory dynamically, with error checking.  */
298
/* Allocate N bytes of memory dynamically, with error checking.  */
Lines 413-418 Link Here
413
    }
418
    }
414
}
419
}
415
420
421
#define DIR_TEMPLATE    "sortXXXXXXXXXX"
416
/* Return a name for a temporary file. */
422
/* Return a name for a temporary file. */
417
423
418
static char *
424
static char *
Lines 420-434 Link Here
420
{
426
{
421
  static unsigned int seq;
427
  static unsigned int seq;
422
  int len = strlen (temp_file_prefix);
428
  int len = strlen (temp_file_prefix);
423
  char *name = xmalloc (len + 1 + sizeof ("sort") - 1 + 5 + 5 + 1);
429
  char *name=xmalloc(len + 1 + sizeof(DIR_TEMPLATE)-1 + 1 + sizeof("sort")-1 + 5 + 5 + 1);
424
  struct tempnode *node;
430
  struct tempnode *node;
425
431
426
  node = (struct tempnode *) xmalloc (sizeof (struct tempnode));
432
  node = (struct tempnode *) xmalloc (sizeof (struct tempnode));
433
  if( !temp_dir )
434
         {
435
                 temp_dir = xmalloc( len + 1 + sizeof(DIR_TEMPLATE) );
436
                 sprintf(temp_dir,
437
                                 "%s%s%s",
438
                                 temp_file_prefix,
439
                                 (len && temp_file_prefix[len - 1] != '/') ? "/" : "",
440
                                 DIR_TEMPLATE);
441
                 if( mkdtemp(temp_dir) == NULL )
442
                         {
443
                                 error(0, errno, _("can't make temp dir"));
444
                                 exit(2);
445
                         }
446
         }
447
427
  sprintf (name,
448
  sprintf (name,
428
          "%s%ssort%5.5d%5.5d",
449
                  "%s/sort%5.5d%5.5d",
429
          temp_file_prefix,
450
                  temp_dir,
430
          (len && temp_file_prefix[len - 1] != '/') ? "/" : "",
451
                  (unsigned int) getpid () & 0xffff, seq);
431
          (unsigned int) getpid () & 0xffff, seq);
432
452
433
  /* Make sure that SEQ's value fits in 5 digits.  */
453
  /* Make sure that SEQ's value fits in 5 digits.  */
434
  ++seq;
454
  ++seq;

Return to bug 16929