summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStef Walter <stefw@gnome.org>2014-03-06 11:02:24 +0100
committerStef Walter <stefw@gnome.org>2014-03-06 16:46:20 +0100
commitc7fc0421ece00e684f5932a6285c122a917bf610 (patch)
tree7f57c6894660b5d67a957df4204022653b11e317
parent6a603979122abd1279e5e6b930a2f61b28f806e8 (diff)
egg: Remove egg_mkdtemp() functions and use g_mkdtemp() instead
-rw-r--r--configure.ac2
-rw-r--r--daemon/gkd-util.c3
-rw-r--r--egg/Makefile.am2
-rw-r--r--egg/egg-mkdtemp.c196
-rw-r--r--egg/egg-mkdtemp.h27
-rw-r--r--egg/egg-testing.c3
-rw-r--r--egg/egg-timegm.c2
-rw-r--r--egg/egg-timegm.h2
8 files changed, 2 insertions, 235 deletions
diff --git a/configure.ac b/configure.ac
index ff6370c5..f58f51d5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -152,8 +152,6 @@ AC_CHECK_FUNCS(flock, AC_DEFINE(HAVE_FLOCK,1,[Have flock]))
AC_CHECK_FUNCS(timegm, AC_DEFINE(HAVE_TIMEGM,1,[Have timegm]))
-dnl mkdtemp replacement from gettext
-AC_REPLACE_FUNCS(mkdtemp)
AC_STAT_MACROS_BROKEN
AC_CACHE_CHECK([for inttypes.h], jm_ac_cv_header_inttypes_h,
[AC_TRY_COMPILE(
diff --git a/daemon/gkd-util.c b/daemon/gkd-util.c
index 83c442de..3ba2d0ca 100644
--- a/daemon/gkd-util.c
+++ b/daemon/gkd-util.c
@@ -25,7 +25,6 @@
#include "gkd-util.h"
#include "egg/egg-cleanup.h"
-#include "egg/egg-mkdtemp.h"
#include "egg/egg-unix-credentials.h"
#include <glib.h>
@@ -113,7 +112,7 @@ gkd_util_init_master_directory (const gchar *replace)
/* Generate a new directory */
if (!valid) {
master_directory = g_build_filename (g_get_user_runtime_dir (), "keyring-XXXXXX", NULL);
- if (egg_mkdtemp (master_directory) == NULL)
+ if (g_mkdtemp (master_directory) == NULL)
g_warning ("couldn't create socket directory: %s", g_strerror (errno));
/* A directory was supplied, but doesn't exist yet */
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,
- <http://www.gnu.org/licenses/>.
-*/
-
-/* Extracted from misc/mkdtemp.c and sysdeps/posix/tempname.c. */
-
-#include "egg-mkdtemp.h"
-
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include <errno.h>
-#ifndef __set_errno
-# define __set_errno(Val) errno = (Val)
-#endif
-
-#include <stddef.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdint.h>
-
-#include <stdio.h>
-#ifndef TMP_MAX
-# define TMP_MAX 238328
-#endif
-
-#if HAVE_INTTYPES_H_WITH_UINTMAX || _LIBC
-# include <inttypes.h>
-#endif
-
-#if HAVE_UNISTD_H || _LIBC
-# include <unistd.h>
-#endif
-
-#if HAVE_GETTIMEOFDAY || _LIBC
-# if HAVE_SYS_TIME_H || _LIBC
-# include <sys/time.h>
-# endif
-#else
-# if HAVE_TIME_H || _LIBC
-# include <time.h>
-# endif
-#endif
-
-#include <sys/stat.h>
-#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,
- <http://www.gnu.org/licenses/>.
-*/
-
-/* 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 <glib/gstdio.h>
@@ -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 @@
<http://www.gnu.org/licenses/>.
*/
-/* 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 @@
<http://www.gnu.org/licenses/>.
*/
-/* Extracted from misc/mkdtemp.c and sysdeps/posix/tempname.c. */
-
#ifndef EGG_TIMEGM_H_
#define EGG_TIMEGM_H_