[BACK]Return to mktemp.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / mktemp

Diff for /src/usr.bin/mktemp/mktemp.c between version 1.5 and 1.6

version 1.5, 1998/06/21 22:14:00 version 1.6, 2001/10/01 17:08:30
Line 1 
Line 1 
 /*      $OpenBSD$       */  /*      $OpenBSD$       */
   
 /*  /*
  * Copyright (c) 1996 Todd C. Miller <Todd.Miller@courtesan.com>   * Copyright (c) 1996, 1997, 2001 Todd C. Miller <Todd.Miller@courtesan.com>
  * All rights reserved.   * All rights reserved.
  *   *
  * Redistribution and use in source and binary forms, with or without   * Redistribution and use in source and binary forms, with or without
Line 28 
Line 28 
  */   */
   
 #ifndef lint  #ifndef lint
 static char rcsid[] = "$OpenBSD$";  static const char rcsid[] = "$OpenBSD$";
 #endif /* not lint */  #endif /* not lint */
   
   #include <paths.h>
 #include <stdio.h>  #include <stdio.h>
 #include <stdlib.h>  #include <stdlib.h>
 #include <string.h>  #include <string.h>
 #include <unistd.h>  #include <unistd.h>
 #include <err.h>  #include <err.h>
   
 extern char *__progname;  
   
 void  void
 usage()  usage()
 {  {
         (void) fprintf(stderr, "Usage: %s [-d] [-q] [-u] template\n",          extern char *__progname;
             __progname);  
           (void) fprintf(stderr,
               "Usage: %s [-dqtu] [-p prefix] template\n", __progname);
         exit(1);          exit(1);
 }  }
   
Line 52 
Line 53 
         int argc;          int argc;
         char **argv;          char **argv;
 {  {
         char *template;          int ch, uflag = 0, qflag = 0, tflag = 0, makedir = 0;
         int c, uflag = 0, qflag = 0, makedir = 0;          char *cp, *template, *prefix = _PATH_TMP;
           size_t plen;
   
         while ((c = getopt(argc, argv, "dqu")) != -1)          while ((ch = getopt(argc, argv, "dp:qtu")) != -1)
                 switch(c) {                  switch(ch) {
                 case 'd':                  case 'd':
                         makedir = 1;                          makedir = 1;
                         break;                          break;
                   case 'p':
                           prefix = optarg;
                           tflag = 1;
                           break;
                 case 'q':                  case 'q':
                         qflag = 1;                          qflag = 1;
                         break;                          break;
                   case 't':
                           tflag = 1;
                           break;
                 case 'u':                  case 'u':
                         uflag = 1;                          uflag = 1;
                         break;                          break;
                 case '?':  
                 default:                  default:
                         usage();                          usage();
         }          }
Line 74 
Line 82 
         if (argc - optind != 1)          if (argc - optind != 1)
                 usage();                  usage();
   
         if ((template = strdup(argv[optind])) == NULL) {          if (tflag) {
                 if (qflag)                  if (strchr(argv[optind], '/')) {
                         exit(1);                          if (qflag)
                 else                                  exit(1);
                         errx(1, "Cannot allocate memory");                          else
                                   errx(1, "template must not contain directory separators in -t mode");
                   }
   
                   cp = getenv("TMPDIR");
                   if (cp != NULL && *cp != '\0')
                           prefix = cp;
                   plen = strlen(prefix);
                   while (plen != 0 && prefix[plen - 1] == '/')
                           plen--;
   
                   template = (char *)malloc(plen + 1 + strlen(argv[optind]) + 1);
                   if (template == NULL) {
                           if (qflag)
                                   exit(1);
                           else
                                   errx(1, "Cannot allocate memory");
                   }
                   memcpy(template, prefix, plen);
                   template[plen] = '/';
                   strcpy(template + plen + 1, argv[optind]);      /* SAFE */
           } else {
                   if ((template = strdup(argv[optind])) == NULL) {
                           if (qflag)
                                   exit(1);
                           else
                                   errx(1, "Cannot allocate memory");
                   }
         }          }
   
         if (makedir) {          if (makedir) {

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6