summaryrefslogtreecommitdiff
path: root/libc/misc/internals/tempname.c
diff options
context:
space:
mode:
authorManuel Novoa III <mjn3@codepoet.org>2002-03-12 01:18:50 +0000
committerManuel Novoa III <mjn3@codepoet.org>2002-03-12 01:18:50 +0000
commit03e039820dc5092e27e81f3671652f25da7f25f1 (patch)
tree37bddad6951b8a6aa5d75184353705f672217812 /libc/misc/internals/tempname.c
parentff3e48d94097ed02480bb0df538620b221ccd72f (diff)
Swap in the new stdio code.
Diffstat (limited to 'libc/misc/internals/tempname.c')
-rw-r--r--libc/misc/internals/tempname.c37
1 files changed, 23 insertions, 14 deletions
diff --git a/libc/misc/internals/tempname.c b/libc/misc/internals/tempname.c
index 3c43f9b85..41325d998 100644
--- a/libc/misc/internals/tempname.c
+++ b/libc/misc/internals/tempname.c
@@ -16,6 +16,11 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
+/* March 11, 2002 Manuel Novoa III
+ *
+ * Modify code to remove dependency on libgcc long long arith support funcs.
+ */
+
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
@@ -117,8 +122,11 @@ int __gen_tempname (char *tmpl, int openit)
char *XXXXXX;
static uint64_t value;
struct timeval tv;
+ uint32_t high, low, rh;
+ unsigned int k;
int count, fd;
int save_errno = errno;
+ int i;
len = strlen (tmpl);
if (len < 6 || strcmp (&tmpl[len - 6], "XXXXXX"))
@@ -136,20 +144,21 @@ int __gen_tempname (char *tmpl, int openit)
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];
+ low = value & UINT32_MAX;
+ high = value >> 32;
+
+ for (i = 0 ; i < 6 ; i++) {
+ rh = high % 62;
+ high /= 62;
+#define L ((UINT32_MAX % 62 + 1) % 62)
+ k = (low % 62) + (L * rh);
+#undef L
+#define H ((UINT32_MAX / 62) + ((UINT32_MAX % 62 + 1) / 62))
+ low = (low / 62) + (H * rh) + (k / 62);
+#undef H
+ k %= 62;
+ XXXXXX[i] = letters[k];
+ }
if (openit)
{