mktemp.c 717 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * Mini mktemp implementation for busybox
  4. *
  5. *
  6. * Copyright (C) 2000 by Daniel Jacobowitz
  7. * Written by Daniel Jacobowitz <dan@debian.org>
  8. *
  9. * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
  10. */
  11. #include <stdio.h>
  12. #include <errno.h>
  13. #include <string.h>
  14. #include <unistd.h>
  15. #include <stdlib.h>
  16. #include "busybox.h"
  17. int mktemp_main(int argc, char **argv)
  18. {
  19. unsigned long flags = bb_getopt_ulflags(argc, argv, "dq");
  20. if (optind + 1 != argc)
  21. bb_show_usage();
  22. if (flags & 1) {
  23. if (mkdtemp(argv[optind]) == NULL)
  24. return EXIT_FAILURE;
  25. }
  26. else {
  27. if (mkstemp(argv[optind]) < 0)
  28. return EXIT_FAILURE;
  29. }
  30. puts(argv[optind]);
  31. return EXIT_SUCCESS;
  32. }