/contrib/cvs/mktemp.sh

https://bitbucket.org/freebsd/freebsd-head/ · Shell · 39 lines · 11 code · 8 blank · 20 comment · 5 complexity · 12b1e4594b24349bd35dda3ffa0f5ac5 MD5 · raw file

  1. # mktemp
  2. # Copyright (c) Derek Price, Ximbiot <http://ximbiot.com>, and the
  3. # Free Software Foundation, Inc. <http://gnu.org>
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 2, or (at your option)
  7. # any later version.
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. # You should have received a copy of the GNU General Public License
  13. # along with this program; if not, write to the Free Software
  14. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  15. # 02111-1307, USA.
  16. # This Bourne Shell scriptlet is intended as a simple replacement for
  17. # the BSD mktemp function for systems that do not support mktemp. It
  18. # currently does not check that the files it is creating did not exist
  19. # previously and it does not verify that it successfully creates the
  20. # files it returns the names of.
  21. mktemp() {
  22. if test x"$1" = x-d; then
  23. tmp=`echo $2 |sed "s/XXXXXX/$$/"`
  24. (umask 077 && exec mkdir $tmp) || return 1
  25. else
  26. tmp=`echo $1 |sed "s/XXXXXX/$$/"`
  27. (umask 077 && touch $tmp) || return 1
  28. fi
  29. echo $tmp
  30. return 0
  31. }