From c7fc0421ece00e684f5932a6285c122a917bf610 Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Thu, 6 Mar 2014 11:02:24 +0100 Subject: egg: Remove egg_mkdtemp() functions and use g_mkdtemp() instead --- egg/Makefile.am | 2 - egg/egg-mkdtemp.c | 196 ------------------------------------------------------ egg/egg-mkdtemp.h | 27 -------- egg/egg-testing.c | 3 +- egg/egg-timegm.c | 2 - egg/egg-timegm.h | 2 - 6 files changed, 1 insertion(+), 231 deletions(-) delete mode 100644 egg/egg-mkdtemp.c delete mode 100644 egg/egg-mkdtemp.h (limited to 'egg') diff --git a/egg/Makefile.am b/egg/Makefile.am index 21d9898b..f4893578 100644 --- a/egg/Makefile.am +++ b/egg/Makefile.am @@ -28,7 +28,6 @@ libegg_la_SOURCES = \ egg/egg-hex.c egg/egg-hex.h \ egg/egg-hkdf.c egg/egg-hkdf.h \ egg/egg-libgcrypt.c egg/egg-libgcrypt.h \ - egg/egg-mkdtemp.c egg/egg-mkdtemp.h \ egg/egg-oid.c egg/egg-oid.h \ egg/egg-padding.c egg/egg-padding.h \ egg/egg-openssl.c egg/egg-openssl.h \ @@ -105,7 +104,6 @@ libegg_hex_la_LIBS = \ $(GLIB_LIBS) libegg_test_la_SOURCES = \ - egg/egg-mkdtemp.c egg/egg-mkdtemp.h \ egg/egg-testing.c egg/egg-testing.h libegg_test_la_CFLAGS = \ diff --git a/egg/egg-mkdtemp.c b/egg/egg-mkdtemp.c deleted file mode 100644 index 3aad2480..00000000 --- a/egg/egg-mkdtemp.c +++ /dev/null @@ -1,196 +0,0 @@ -/* Copyright (C) 1999, 2001-2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - . -*/ - -/* Extracted from misc/mkdtemp.c and sysdeps/posix/tempname.c. */ - -#include "egg-mkdtemp.h" - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include -#ifndef __set_errno -# define __set_errno(Val) errno = (Val) -#endif - -#include -#include -#include -#include - -#include -#ifndef TMP_MAX -# define TMP_MAX 238328 -#endif - -#if HAVE_INTTYPES_H_WITH_UINTMAX || _LIBC -# include -#endif - -#if HAVE_UNISTD_H || _LIBC -# include -#endif - -#if HAVE_GETTIMEOFDAY || _LIBC -# if HAVE_SYS_TIME_H || _LIBC -# include -# endif -#else -# if HAVE_TIME_H || _LIBC -# include -# endif -#endif - -#include -#if STAT_MACROS_BROKEN -# undef S_ISDIR -#endif -#if !defined S_ISDIR && defined S_IFDIR -# define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) -#endif -#if !S_IRUSR && S_IREAD -# define S_IRUSR S_IREAD -#endif -#if !S_IRUSR -# define S_IRUSR 00400 -#endif -#if !S_IWUSR && S_IWRITE -# define S_IWUSR S_IWRITE -#endif -#if !S_IWUSR -# define S_IWUSR 00200 -#endif -#if !S_IXUSR && S_IEXEC -# define S_IXUSR S_IEXEC -#endif -#if !S_IXUSR -# define S_IXUSR 00100 -#endif - -#if !_LIBC -# define __getpid getpid -# define __gettimeofday gettimeofday -# define __mkdir mkdir -#endif - -/* Use the widest available unsigned type if uint64_t is not - available. The algorithm below extracts a number less than 62**6 - (approximately 2**35.725) from uint64_t, so ancient hosts where - uintmax_t is only 32 bits lose about 3.725 bits of randomness, - which is better than not having mkstemp at all. */ -#if !defined UINT64_MAX && !defined uint64_t -# define uint64_t uintmax_t -#endif - -/* These are the characters used in temporary filenames. */ -static const char letters[] = -"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; - -/* Generate a temporary file name based on TMPL. TMPL must match the - rules for mk[s]temp (i.e. end in "XXXXXX"). The name constructed - does not exist at the time of the call to __gen_tempname. TMPL is - overwritten with the result. - - KIND is: - __GT_DIR: create a directory, which will be mode 0700. - - We use a clever algorithm to get hard-to-predict names. */ -static int -gen_tempname (tmpl) - char *tmpl; -{ - int len; - char *XXXXXX; - static uint64_t value; - uint64_t random_time_bits; - int count, fd = -1; - int save_errno = errno; - - len = strlen (tmpl); - if (len < 6 || strcmp (&tmpl[len - 6], "XXXXXX")) - { - __set_errno (EINVAL); - return -1; - } - - /* This is where the Xs start. */ - XXXXXX = &tmpl[len - 6]; - - /* Get some more or less random data. */ -#ifdef RANDOM_BITS - RANDOM_BITS (random_time_bits); -#else -# if HAVE_GETTIMEOFDAY || _LIBC - { - struct timeval tv; - __gettimeofday (&tv, NULL); - random_time_bits = ((uint64_t) tv.tv_usec << 16) ^ tv.tv_sec; - } -# else - random_time_bits = time (NULL); -# endif -#endif - value += random_time_bits ^ __getpid (); - - for (count = 0; count < TMP_MAX; value += 7777, ++count) - { - uint64_t v = value; - - /* Fill in the random bits. */ - XXXXXX[0] = letters[v % 62]; - v /= 62; - XXXXXX[1] = letters[v % 62]; - v /= 62; - XXXXXX[2] = letters[v % 62]; - v /= 62; - XXXXXX[3] = letters[v % 62]; - v /= 62; - XXXXXX[4] = letters[v % 62]; - v /= 62; - XXXXXX[5] = letters[v % 62]; - - fd = __mkdir (tmpl, S_IRUSR | S_IWUSR | S_IXUSR); - - if (fd >= 0) - { - __set_errno (save_errno); - return fd; - } - else if (errno != EEXIST) - return -1; - } - - /* We got out of the loop because we ran out of combinations to try. */ - __set_errno (EEXIST); - return -1; -} - -/* Generate a unique temporary directory from TEMPLATE. - The last six characters of TEMPLATE must be "XXXXXX"; - they are replaced with a string that makes the filename unique. - The directory is created, mode 700, and its name is returned. - (This function comes from OpenBSD.) */ -char * -egg_mkdtemp (char *template) -{ - if (gen_tempname (template)) - return NULL; - else - return template; -} diff --git a/egg/egg-mkdtemp.h b/egg/egg-mkdtemp.h deleted file mode 100644 index b1438382..00000000 --- a/egg/egg-mkdtemp.h +++ /dev/null @@ -1,27 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* Copyright (C) 1999, 2001-2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - . -*/ - -/* Extracted from misc/mkdtemp.c and sysdeps/posix/tempname.c. */ - -#ifndef EGGMKDTEMP_H_ -#define EGGMKDTEMP_H_ - -char* egg_mkdtemp (char *template); - -#endif /* EGGMKDTEMP_H_ */ diff --git a/egg/egg-testing.c b/egg/egg-testing.c index 7a6b5dff..adca6030 100644 --- a/egg/egg-testing.c +++ b/egg/egg-testing.c @@ -22,7 +22,6 @@ #include "config.h" -#include "egg-mkdtemp.h" #include "egg-testing.h" #include @@ -268,7 +267,7 @@ egg_tests_create_scratch_directory (const gchar *file_to_copy, directory = g_strdup_printf ("/tmp/scratch-%s.XXXXXX", basename); g_free (basename); - if (!egg_mkdtemp (directory)) + if (!g_mkdtemp (directory)) g_assert_not_reached (); va_start (va, file_to_copy); diff --git a/egg/egg-timegm.c b/egg/egg-timegm.c index c3effdf3..47d6f0d8 100644 --- a/egg/egg-timegm.c +++ b/egg/egg-timegm.c @@ -16,8 +16,6 @@ . */ -/* Extracted from misc/mkdtemp.c and sysdeps/posix/tempname.c. */ - #ifdef HAVE_CONFIG_H # include "config.h" #endif diff --git a/egg/egg-timegm.h b/egg/egg-timegm.h index b24c14c0..a68a1ae7 100644 --- a/egg/egg-timegm.h +++ b/egg/egg-timegm.h @@ -17,8 +17,6 @@ . */ -/* Extracted from misc/mkdtemp.c and sysdeps/posix/tempname.c. */ - #ifndef EGG_TIMEGM_H_ #define EGG_TIMEGM_H_ -- cgit v1.2.1