summaryrefslogtreecommitdiffstats
path: root/tcl8.6/compat/mkstemp.c
diff options
context:
space:
mode:
authorWilliam Joye <wjoye@cfa.harvard.edu>2018-01-02 20:34:49 (GMT)
committerWilliam Joye <wjoye@cfa.harvard.edu>2018-01-02 20:34:49 (GMT)
commit89c1ac99d375fbd73892aa659f06ef5e2c5ea56e (patch)
treee76ce80d68d11f1ea137bc33a42f71a1d1f32028 /tcl8.6/compat/mkstemp.c
parent01e4cd2ef2ff59418766b2259fbc99771646aba6 (diff)
downloadblt-89c1ac99d375fbd73892aa659f06ef5e2c5ea56e.zip
blt-89c1ac99d375fbd73892aa659f06ef5e2c5ea56e.tar.gz
blt-89c1ac99d375fbd73892aa659f06ef5e2c5ea56e.tar.bz2
upgrade to tcl/tk 8.6.8
Diffstat (limited to 'tcl8.6/compat/mkstemp.c')
-rw-r--r--tcl8.6/compat/mkstemp.c78
1 files changed, 0 insertions, 78 deletions
diff --git a/tcl8.6/compat/mkstemp.c b/tcl8.6/compat/mkstemp.c
deleted file mode 100644
index 1a44dfa..0000000
--- a/tcl8.6/compat/mkstemp.c
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * mkstemp.c --
- *
- * Source code for the "mkstemp" library routine.
- *
- * Copyright (c) 2009 Donal K. Fellows
- *
- * See the file "license.terms" for information on usage and redistribution of
- * this file, and for a DISCLAIMER OF ALL WARRANTIES.
- */
-
-#include <errno.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <unistd.h>
-
-/*
- *----------------------------------------------------------------------
- *
- * mkstemp --
- *
- * Create an open temporary file from a template.
- *
- * Results:
- * A file descriptor, or -1 (with errno set) in the case of an error.
- *
- * Side effects:
- * The template is updated to contain the real filename.
- *
- *----------------------------------------------------------------------
- */
-
-int
-mkstemp(
- char *template) /* Template for filename. */
-{
- static const char alphanumerics[] =
- "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
- register char *a, *b;
- int fd, count, alphanumericsLen = strlen(alphanumerics); /* == 62 */
-
- a = template + strlen(template);
- while (a > template && *(a-1) == 'X') {
- a--;
- }
-
- if (a == template) {
- errno = ENOENT;
- return -1;
- }
-
- /*
- * We'll only try up to 10 times; after that, we're suffering from enemy
- * action and should let the caller know.
- */
-
- count = 10;
- do {
- /*
- * Replace the X's in the original template with random alphanumeric
- * digits.
- */
-
- for (b=a ; *b ; b++) {
- float r = rand() / ((float) RAND_MAX);
-
- *b = alphanumerics[(int)(r * alphanumericsLen)];
- }
-
- /*
- * Template is now realized; try to open (with correct options).
- */
-
- fd = open(template, O_RDWR|O_CREAT|O_EXCL, 0600);
- } while (fd == -1 && errno == EEXIST && --count > 0);
-
- return fd;
-}