summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/devices/grolbp/lbp.h2
-rw-r--r--src/include/lib.h2
-rw-r--r--src/include/posix.h6
-rw-r--r--src/libs/libbib/linear.cc2
-rw-r--r--src/libs/libbib/map.c2
-rw-r--r--src/libs/libbib/search.cc2
-rw-r--r--src/libs/libgroff/Makefile.sub5
-rw-r--r--src/libs/libgroff/fontfile.cc2
-rw-r--r--src/libs/libgroff/mksdir.cc34
-rw-r--r--src/libs/libgroff/mkstemp.cc34
-rw-r--r--src/libs/libgroff/new.cc2
-rw-r--r--src/libs/libgroff/tmpfile.cc16
-rw-r--r--src/libs/libgroff/tmpname.cc107
-rw-r--r--src/preproc/html/pre-html.cc27
-rw-r--r--src/roff/groff/pipeline.c9
-rw-r--r--src/utils/afmtodit/afmtodit.pl2
-rw-r--r--src/utils/indxbib/indxbib.cc14
17 files changed, 198 insertions, 70 deletions
diff --git a/src/devices/grolbp/lbp.h b/src/devices/grolbp/lbp.h
index cacf3eaf..3b8a9410 100644
--- a/src/devices/grolbp/lbp.h
+++ b/src/devices/grolbp/lbp.h
@@ -1,5 +1,5 @@
// -*- C -*-
-/* Copyright (C) 1994, 2000 Free Software Foundation, Inc.
+/* Copyright (C) 1994, 2000, 2001 Free Software Foundation, Inc.
Written by Francisco Andrés Verdú <pandres@dragonet.es>
groff is free software; you can redistribute it and/or modify it under
diff --git a/src/include/lib.h b/src/include/lib.h
index c424b8e8..6eb67952 100644
--- a/src/include/lib.h
+++ b/src/include/lib.h
@@ -43,6 +43,8 @@ int is_prime(unsigned);
#include <strings.h>
#endif
+int mksdir(char *tmpl);
+
FILE *xtmpfile(char **namep = 0,
const char *postfix_long = 0, const char *postfix_short = 0,
int do_unlink = 1);
diff --git a/src/include/posix.h b/src/include/posix.h
index 80f59cad..9a03ecdb 100644
--- a/src/include/posix.h
+++ b/src/include/posix.h
@@ -1,5 +1,5 @@
// -*- C++ -*-
-/* Copyright (C) 1992, 2000 Free Software Foundation, Inc.
+/* Copyright (C) 1992, 2000, 2001 Free Software Foundation, Inc.
Written by James Clark (jjc@jclark.com)
This file is part of groff.
@@ -46,6 +46,10 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#define S_IWUSR 0200
#endif
+#ifndef S_IXUSR
+#define S_IXUSR 0100
+#endif
+
#ifndef S_ISREG
#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
#endif
diff --git a/src/libs/libbib/linear.cc b/src/libs/libbib/linear.cc
index a8c2a553..1b631085 100644
--- a/src/libs/libbib/linear.cc
+++ b/src/libs/libbib/linear.cc
@@ -1,5 +1,5 @@
// -*- C++ -*-
-/* Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
+/* Copyright (C) 1989, 1990, 1991, 1992, 2000 Free Software Foundation, Inc.
Written by James Clark (jjc@jclark.com)
This file is part of groff.
diff --git a/src/libs/libbib/map.c b/src/libs/libbib/map.c
index ee5d0087..531d8670 100644
--- a/src/libs/libbib/map.c
+++ b/src/libs/libbib/map.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
+/* Copyright (C) 1989, 1990, 1991, 1992, 2000 Free Software Foundation, Inc.
Written by James Clark (jjc@jclark.com)
This file is part of groff.
diff --git a/src/libs/libbib/search.cc b/src/libs/libbib/search.cc
index 1e027c60..dde55d57 100644
--- a/src/libs/libbib/search.cc
+++ b/src/libs/libbib/search.cc
@@ -1,5 +1,5 @@
// -*- C++ -*-
-/* Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
+/* Copyright (C) 1989, 1990, 1991, 1992, 2000 Free Software Foundation, Inc.
Written by James Clark (jjc@jclark.com)
This file is part of groff.
diff --git a/src/libs/libgroff/Makefile.sub b/src/libs/libgroff/Makefile.sub
index ff5c655c..007102c7 100644
--- a/src/libs/libgroff/Makefile.sub
+++ b/src/libs/libgroff/Makefile.sub
@@ -19,6 +19,7 @@ OBJS=\
lineno.o \
macropath.o \
maxfilename.o \
+ mksdir.o \
nametoindex.o \
new.o \
prime.o \
@@ -28,6 +29,7 @@ OBJS=\
string.o \
strsave.o \
tmpfile.o \
+ tmpname.o \
iftoa.o \
itoa.o \
matherr.o \
@@ -51,6 +53,8 @@ CCSRCS=\
$(srcdir)/lineno.cc \
$(srcdir)/macropath.cc \
$(srcdir)/maxfilename.cc \
+ $(srcdir)/mksdir.cc \
+ $(srcdir)/mkstemp.cc \
$(srcdir)/nametoindex.cc \
$(srcdir)/new.cc \
$(srcdir)/prime.cc \
@@ -60,6 +64,7 @@ CCSRCS=\
$(srcdir)/string.cc \
$(srcdir)/strsave.cc \
$(srcdir)/tmpfile.cc \
+ $(srcdir)/tmpname.cc \
version.cc
CSRCS=\
$(srcdir)/fmod.c \
diff --git a/src/libs/libgroff/fontfile.cc b/src/libs/libgroff/fontfile.cc
index cc1ad2c4..95cf6551 100644
--- a/src/libs/libgroff/fontfile.cc
+++ b/src/libs/libgroff/fontfile.cc
@@ -1,5 +1,5 @@
// -*- C++ -*-
-/* Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
+/* Copyright (C) 1989, 1990, 1991, 1992, 2000 Free Software Foundation, Inc.
Written by James Clark (jjc@jclark.com)
This file is part of groff.
diff --git a/src/libs/libgroff/mksdir.cc b/src/libs/libgroff/mksdir.cc
new file mode 100644
index 00000000..bf4d300b
--- /dev/null
+++ b/src/libs/libgroff/mksdir.cc
@@ -0,0 +1,34 @@
+/* Copyright (C) 2001 Free Software Foundation, Inc.
+ Written by Werner Lemberg (wl@gnu.org)
+
+This file is part of groff.
+
+groff is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 2, or (at your option) any later
+version.
+
+groff 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 General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License along
+with groff; see the file COPYING. If not, write to the Free Software
+Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+
+/* This file is heavily based on the file mkstemp.c which is part of the
+ fileutils package. */
+
+
+extern int gen_tempname(char *, int = 0);
+
+/* Generate a unique temporary directory name from TEMPLATE.
+ The last six characters of TEMPLATE must be "XXXXXX";
+ they are replaced with a string that makes the filename unique.
+ Then open the directory and return a fd. */
+int mksdir(char *tmpl)
+{
+ return gen_tempname(tmpl, 1);
+}
diff --git a/src/libs/libgroff/mkstemp.cc b/src/libs/libgroff/mkstemp.cc
new file mode 100644
index 00000000..cd2717c3
--- /dev/null
+++ b/src/libs/libgroff/mkstemp.cc
@@ -0,0 +1,34 @@
+/* Copyright (C) 2001 Free Software Foundation, Inc.
+ Written by Werner Lemberg (wl@gnu.org)
+
+This file is part of groff.
+
+groff is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 2, or (at your option) any later
+version.
+
+groff 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 General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License along
+with groff; see the file COPYING. If not, write to the Free Software
+Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+
+/* This file is heavily based on the file mkstemp.c which is part of the
+ fileutils package. */
+
+
+extern int gen_tempname(char *, int);
+
+/* Generate a unique temporary file name from TEMPLATE.
+ The last six characters of TEMPLATE must be "XXXXXX";
+ they are replaced with a string that makes the filename unique.
+ Then open the file and return a fd. */
+int mkstemp(char *tmpl)
+{
+ return gen_tempname(tmpl, 0);
+}
diff --git a/src/libs/libgroff/new.cc b/src/libs/libgroff/new.cc
index 8d98591a..9933cc45 100644
--- a/src/libs/libgroff/new.cc
+++ b/src/libs/libgroff/new.cc
@@ -1,4 +1,4 @@
-/* Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
+/* Copyright (C) 1989, 1990, 1991, 1992, 2001 Free Software Foundation, Inc.
Written by James Clark (jjc@jclark.com)
This file is part of groff.
diff --git a/src/libs/libgroff/tmpfile.cc b/src/libs/libgroff/tmpfile.cc
index 4a53a06b..fdce09ee 100644
--- a/src/libs/libgroff/tmpfile.cc
+++ b/src/libs/libgroff/tmpfile.cc
@@ -30,12 +30,6 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include "error.h"
#include "nonposix.h"
-#ifndef HAVE_MKSTEMP_PROTO
-extern "C" {
- extern int mkstemp (char *);
-}
-#endif
-
// If this is set, create temporary files there
#define GROFF_TMPDIR_ENVVAR "GROFF_TMPDIR"
// otherwise if this is set, create temporary files there
@@ -161,8 +155,6 @@ FILE *xtmpfile(char **namep,
int do_unlink)
{
char *templ = xtmptemplate(postfix_long, postfix_short);
-
-#ifdef HAVE_MKSTEMP
errno = 0;
int fd = mkstemp(templ);
if (fd < 0)
@@ -171,14 +163,6 @@ FILE *xtmpfile(char **namep,
FILE *fp = fdopen(fd, FOPEN_RWB); // many callers of xtmpfile use binary I/O
if (!fp)
fatal("fdopen: %1", strerror(errno));
-#else /* not HAVE_MKSTEMP */
- if (!mktemp(templ) || !templ[0])
- fatal("cannot create file name for temporary file");
- errno = 0;
- FILE *fp = fopen(templ, FOPEN_RWB);
- if (!fp)
- fatal("cannot open `%1': %2", templ, strerror(errno));
-#endif /* not HAVE_MKSTEMP */
if (do_unlink)
add_tmp_file(templ);
if (namep)
diff --git a/src/libs/libgroff/tmpname.cc b/src/libs/libgroff/tmpname.cc
new file mode 100644
index 00000000..bd0e3a07
--- /dev/null
+++ b/src/libs/libgroff/tmpname.cc
@@ -0,0 +1,107 @@
+/* Copyright (C) 2001 Free Software Foundation, Inc.
+ Written by Werner Lemberg (wl@gnu.org)
+
+This file is part of groff.
+
+groff is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 2, or (at your option) any later
+version.
+
+groff 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 General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License along
+with groff; see the file COPYING. If not, write to the Free Software
+Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+
+/* This file is heavily based on the function __gen_tempname() in the
+ file tempname.c which is part of the fileutils package. */
+
+
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <stdio.h>
+
+#include "posix.h"
+#include "nonposix.h"
+
+#ifndef TMP_MAX
+# define TMP_MAX 238328
+#endif
+
+#if HAVE_SYS_TIME_H
+# include <sys/time.h>
+#endif
+
+#if HAVE_STDINT_H
+# include <stdint.h>
+#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";
+
+int gen_tempname(char *tmpl, int dir)
+{
+ static uint64_t value;
+
+ size_t len = strlen(tmpl);
+ if (len < 6 || strcmp(&tmpl[len - 6], "XXXXXX"))
+ return -1; /* EINVAL */
+
+ /* This is where the Xs start. */
+ char *XXXXXX = &tmpl[len - 6];
+
+ /* Get some more or less random data. */
+#if HAVE_GETTIMEOFDAY
+ timeval tv;
+ gettimeofday(&tv, NULL);
+ uint64_t random_time_bits = ((uint64_t)tv.tv_usec << 16) ^ tv.tv_sec;
+#else
+ uint64_t random_time_bits = time(NULL);
+#endif
+ value += random_time_bits ^ getpid();
+
+ for (int 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];
+
+ int fd = dir ? mkdir(tmpl, S_IRUSR | S_IWUSR | S_IXUSR)
+ : open(tmpl, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
+
+ if (fd >= 0)
+ return fd;
+ else if (errno != EEXIST)
+ return -1;
+ }
+
+ /* We got out of the loop because we ran out of combinations to try. */
+ return -1; /* EEXIST */
+}
diff --git a/src/preproc/html/pre-html.cc b/src/preproc/html/pre-html.cc
index 6f2b9789..399345be 100644
--- a/src/preproc/html/pre-html.cc
+++ b/src/preproc/html/pre-html.cc
@@ -62,7 +62,6 @@ extern "C" const char *Version_string;
#define IMAGE_BOARDER_PIXELS 0
#define MAX_WIDTH 8 // inches
#define INLINE_LEADER_CHAR '\\'
-#define MAX_RETRIES 4096 // number of different page directory names to try before giving up
#define TRANSPARENT "-background \"#FFF\" -transparent \"#FFF\""
@@ -838,32 +837,14 @@ static int createAllPages (void)
{
char buffer[4096];
char *s;
- int retries = MAX_RETRIES;
imagePageStem = xtmptemplate(PAGE_TEMPLATE_LONG, PAGE_TEMPLATE_SHORT);
strcpy(buffer, imagePageStem);
- do {
- if (mktemp(imagePageStem) == NULL) {
- sys_fatal("mktemp");
- return -1;
- }
- if (mkdir(imagePageStem, 0700) == 0) break;
- if (errno == EEXIST) {
- // directory already exists, try another name
- retries--;
- if (retries == 0) {
- // time to give up
- sys_fatal("mkdir");
- return -1;
- }
- } else {
- // another error, quit
- sys_fatal("mkdir");
- return -1;
- }
- strcpy(imagePageStem, buffer);
- } while (1);
+ if (mksdir(imagePageStem) < 0) {
+ sys_fatal("mksdir");
+ return -1;
+ }
s = make_message("echo showpage | "
"gs%s -q -dSAFER -sDEVICE=%s -r%d "
diff --git a/src/roff/groff/pipeline.c b/src/roff/groff/pipeline.c
index f26608ff..977e7039 100644
--- a/src/roff/groff/pipeline.c
+++ b/src/roff/groff/pipeline.c
@@ -18,15 +18,6 @@ You should have received a copy of the GNU General Public License along
with groff; see the file COPYING. If not, write to the Free Software
Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
-/*
-Compile options are:
-
--DWCOREFLAG=0200 (or whatever)
--DHAVE_SYS_SIGLIST
--DSYS_SIGLIST_DECLARED
--DHAVE_UNISTD_H
-*/
-
#include <stdio.h>
#include <signal.h>
#include <errno.h>
diff --git a/src/utils/afmtodit/afmtodit.pl b/src/utils/afmtodit/afmtodit.pl
index bfc058a4..04bfe78e 100644
--- a/src/utils/afmtodit/afmtodit.pl
+++ b/src/utils/afmtodit/afmtodit.pl
@@ -1,6 +1,6 @@
#! /usr/bin/perl -P-
# -*- Perl -*-
-# Copyright (C) 1989-2000 Free Software Foundation, Inc.
+# Copyright (C) 1989-2000, 2001 Free Software Foundation, Inc.
# Written by James Clark (jjc@jclark.com)
#
# This file is part of groff.
diff --git a/src/utils/indxbib/indxbib.cc b/src/utils/indxbib/indxbib.cc
index db3e9a40..635d99df 100644
--- a/src/utils/indxbib/indxbib.cc
+++ b/src/utils/indxbib/indxbib.cc
@@ -39,12 +39,6 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
extern "C" const char *Version_string;
-#ifndef HAVE_MKSTEMP_PROTO
-extern "C" {
- extern int mkstemp(char *);
-}
-#endif
-
#define DEFAULT_HASH_TABLE_SIZE 997
#define TEMP_INDEX_TEMPLATE "indxbibXXXXXX"
@@ -240,16 +234,8 @@ int main(int argc, char **argv)
else {
temp_index_file = strsave(TEMP_INDEX_TEMPLATE);
}
-#ifndef HAVE_MKSTEMP
- if (!mktemp(temp_index_file) || !temp_index_file[0])
- fatal("cannot create file name for temporary file");
-#endif
catch_fatal_signals();
-#ifdef HAVE_MKSTEMP
int fd = mkstemp(temp_index_file);
-#else
- int fd = creat(temp_index_file, S_IRUSR|S_IRGRP|S_IROTH);
-#endif
if (fd < 0)
fatal("can't create temporary index file: %1", strerror(errno));
indxfp = fdopen(fd, FOPEN_WB);