Magellan Linux

Diff of /trunk/mkinitrd-magellan/busybox/debianutils/mktemp.c

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

revision 532 by niro, Sat Sep 1 22:45:15 2007 UTC revision 1125 by niro, Wed Aug 18 22:00:06 2010 UTC
# Line 9  Line 9 
9   * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.   * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
10   */   */
11    
12  #include "busybox.h"  /* Coreutils 6.12 man page says:
13  #include <stdio.h>   *        mktemp [OPTION]... [TEMPLATE]
14  #include <errno.h>   * Create a temporary file or directory, safely, and print its name. If
15  #include <string.h>   * TEMPLATE is not specified, use tmp.XXXXXXXXXX.
16  #include <unistd.h>   * -d, --directory
17  #include <stdlib.h>   *        create a directory, not a file
18     * -q, --quiet
19     *        suppress diagnostics about file/dir-creation failure
20     * -u, --dry-run
21     *        do not create anything; merely print a name (unsafe)
22     * --tmpdir[=DIR]
23     *        interpret TEMPLATE relative to DIR. If DIR is not specified,
24     *        use  $TMPDIR if set, else /tmp.  With this option, TEMPLATE must
25     *        not be an absolute name. Unlike with -t, TEMPLATE may contain
26     *        slashes, but even here, mktemp still creates only the final com-
27     *        ponent.
28     * -p DIR use DIR as a prefix; implies -t [deprecated]
29     * -t     interpret TEMPLATE as a single file name component, relative  to
30     *        a  directory:  $TMPDIR, if set; else the directory specified via
31     *        -p; else /tmp [deprecated]
32     */
33    
34    
35    #include "libbb.h"
36    
37  int mktemp_main(int argc, char **argv)  int mktemp_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
38    int mktemp_main(int argc UNUSED_PARAM, char **argv)
39  {  {
40   unsigned long flags = getopt32(argc, argv, "dqt");   const char *path;
41   char *chp;   char *chp;
42     unsigned opts;
43    
44   if (optind + 1 != argc)   path = getenv("TMPDIR");
45   bb_show_usage();   if (!path || path[0] == '\0')
46     path = "/tmp";
47    
48   chp = argv[optind];   /* -q and -t are ignored */
49     opt_complementary = "?1"; /* 1 argument max */
50     opts = getopt32(argv, "dqtp:", &path);
51    
52   if (flags & 4) {   chp = argv[optind] ? argv[optind] : xstrdup("tmp.XXXXXX");
53   char *dir = getenv("TMPDIR");   if (!strchr(chp, '/') || (opts & 8))
54   if (dir && *dir != '\0')   chp = concat_path_file(path, chp);
  chp = concat_path_file(dir, chp);  
  else  
  chp = concat_path_file("/tmp/", chp);  
  }  
55    
56   if (flags & 1) {   if (opts & 1) { /* -d */
57   if (mkdtemp(chp) == NULL)   if (mkdtemp(chp) == NULL)
58   return EXIT_FAILURE;   return EXIT_FAILURE;
59   } else {   } else {

Legend:
Removed from v.532  
changed lines
  Added in v.1125