From 25482f875e3f098a302f439a1298003cee641045 Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Fri, 6 Feb 2015 16:21:19 +0100 Subject: [PATCH] Remove mktemp(3). --- doc/obsolete-stuff | 9 +++++++++ libc/Makefile | 1 - libc/include/stdlib.h | 4 ---- libc/stdlib/mktemp.cpp | 37 ------------------------------------- 4 files changed, 9 insertions(+), 42 deletions(-) delete mode 100644 libc/stdlib/mktemp.cpp diff --git a/doc/obsolete-stuff b/doc/obsolete-stuff index 37661a6c..028fdbe7 100644 --- a/doc/obsolete-stuff +++ b/doc/obsolete-stuff @@ -145,6 +145,15 @@ F_SETLKW) do and should be avoided for the same reasons (see above). Use the flock (not to be confused with lockf) call instead as it works at a file descriptor level. +mktemp +------ + +mktemp(3) (not the mktemp(1) utility) creates a unique path name, but creates no +file, and thus offers no guarantee that is unique with respect to other threads +and system processes. The function is racy and dangerous. + +Use mkstemp(3) (or for directories mkdtemp(3)) instead. + PATH_MAX -------- diff --git a/libc/Makefile b/libc/Makefile index 5862f749..9b76436a 100644 --- a/libc/Makefile +++ b/libc/Makefile @@ -455,7 +455,6 @@ stdlib/mkostemp.o \ stdlib/mkostemps.o \ stdlib/mkstemp.o \ stdlib/mkstemps.o \ -stdlib/mktemp.o \ stdlib/on_exit.o \ stdlib/rand.o \ stdlib/realpath.o \ diff --git a/libc/include/stdlib.h b/libc/include/stdlib.h index 183ce1c8..4cde309f 100644 --- a/libc/include/stdlib.h +++ b/libc/include/stdlib.h @@ -110,10 +110,6 @@ int mkostemp(char*, int); int mkostemps(char*, int, int); int mkstemp(char*); int mkstemps(char*, int); -#if !defined(__is_sortix_libc) /* not a warning inside libc */ -__attribute__((__warning__("mktemp() is racy, use mkstemp()"))) -#endif -char* mktemp(char* templ); int on_exit(void (*function)(int, void*), void* arg); void qsort(void*, size_t, size_t, int (*)(const void*, const void*)); void qsort_r(void*, size_t, size_t, int (*)(const void*, const void*, void*), void*); diff --git a/libc/stdlib/mktemp.cpp b/libc/stdlib/mktemp.cpp deleted file mode 100644 index 6b5b4d62..00000000 --- a/libc/stdlib/mktemp.cpp +++ /dev/null @@ -1,37 +0,0 @@ -/******************************************************************************* - - Copyright(C) Jonas 'Sortie' Termansen 2011, 2012. - - This file is part of the Sortix C Library. - - The Sortix C Library is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or (at your - option) any later version. - - The Sortix C Library is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with the Sortix C Library. If not, see . - - stdlib/mktemp.cpp - Make a unique temporary filename. - -*******************************************************************************/ - -#include -#include - -// TODO: This is a hacky implementation of a stupid function. -extern "C" char* mktemp(char* templ) -{ - size_t templlen = strlen(templ); - for ( size_t i = templlen-6UL; i < templlen; i++ ) - { - templ[i] = '0' + rand() % 10; - } - return templ; -}