View | Details | Raw Unified | Return to bug 4417 | Differences between
and this patch

Collapse All | Expand All

(-)glibc-2.5.orig/sysdeps/posix/tempname.c (-59 / +6 lines)
Lines 52-61 Link Here
52
# include <fcntl.h>
52
# include <fcntl.h>
53
#endif
53
#endif
54
54
55
#if HAVE_SYS_TIME_H || _LIBC
56
# include <sys/time.h>
57
#endif
58
59
#if HAVE_STDINT_H || _LIBC
55
#if HAVE_STDINT_H || _LIBC
60
# include <stdint.h>
56
# include <stdint.h>
61
#endif
57
#endif
Lines 94-101 Link Here
94
# define struct_stat64 struct stat64
90
# define struct_stat64 struct stat64
95
#else
91
#else
96
# define struct_stat64 struct stat
92
# define struct_stat64 struct stat
97
# define __getpid getpid
98
# define __gettimeofday gettimeofday
99
# define __mkdir mkdir
93
# define __mkdir mkdir
100
# define __open open
94
# define __open open
101
# define __open64 open
95
# define __open64 open
Lines 107-131 Link Here
107
# define __secure_getenv getenv
101
# define __secure_getenv getenv
108
#endif
102
#endif
109
103
110
#ifdef _LIBC
111
# include <hp-timing.h>
112
# if HP_TIMING_AVAIL
113
#  define RANDOM_BITS(Var) \
114
  if (__builtin_expect (value == UINT64_C (0), 0))			      \
115
    {									      \
116
      /* If this is the first time this function is used initialize	      \
117
	 the variable we accumulate the value in to some somewhat	      \
118
	 random value.  If we'd not do this programs at startup time	      \
119
	 might have a reduced set of possible names, at least on slow	      \
120
	 machines.  */							      \
121
      struct timeval tv;						      \
122
      __gettimeofday (&tv, NULL);					      \
123
      value = ((uint64_t) tv.tv_usec << 16) ^ tv.tv_sec;		      \
124
    }									      \
125
  HP_TIMING_NOW (Var)
126
# endif
127
#endif
128
129
/* Use the widest available unsigned type if uint64_t is not
104
/* Use the widest available unsigned type if uint64_t is not
130
   available.  The algorithm below extracts a number less than 62**6
105
   available.  The algorithm below extracts a number less than 62**6
131
   (approximately 2**35.725) from uint64_t, so ancient hosts where
106
   (approximately 2**35.725) from uint64_t, so ancient hosts where
Lines 229-238 Link Here
229
{
204
{
230
  int len;
205
  int len;
231
  char *XXXXXX;
206
  char *XXXXXX;
232
  static uint64_t value;
233
  uint64_t random_time_bits;
234
  unsigned int count;
235
  int fd = -1;
207
  int fd = -1;
208
  unsigned int i;
236
  int save_errno = errno;
209
  int save_errno = errno;
237
  struct_stat64 st;
210
  struct_stat64 st;
238
211
Lines 262-300 Link Here
262
  /* This is where the Xs start.  */
235
  /* This is where the Xs start.  */
263
  XXXXXX = &tmpl[len - 6];
236
  XXXXXX = &tmpl[len - 6];
264
237
265
  /* Get some more or less random data.  */
238
  for (i = 0; i < 6 ; ++i)
266
#ifdef RANDOM_BITS
267
  RANDOM_BITS (random_time_bits);
268
#else
269
# if HAVE_GETTIMEOFDAY || _LIBC
270
  {
271
    struct timeval tv;
272
    __gettimeofday (&tv, NULL);
273
    random_time_bits = ((uint64_t) tv.tv_usec << 16) ^ tv.tv_sec;
274
  }
275
# else
276
  random_time_bits = time (NULL);
277
# endif
278
#endif
279
  value += random_time_bits ^ __getpid ();
280
281
  for (count = 0; count < attempts; value += 7777, ++count)
282
    {
239
    {
283
      uint64_t v = value;
240
      XXXXXX[i] = letters[(arc4random() % 62)];
284
241
    }
285
      /* Fill in the random bits.  */
286
      XXXXXX[0] = letters[v % 62];
287
      v /= 62;
288
      XXXXXX[1] = letters[v % 62];
289
      v /= 62;
290
      XXXXXX[2] = letters[v % 62];
291
      v /= 62;
292
      XXXXXX[3] = letters[v % 62];
293
      v /= 62;
294
      XXXXXX[4] = letters[v % 62];
295
      v /= 62;
296
      XXXXXX[5] = letters[v % 62];
297
242
243
  for (i = 0; i < attempts; ++i)
244
    {
298
      switch (kind)
245
      switch (kind)
299
	{
246
	{
300
	case __GT_FILE:
247
	case __GT_FILE:

Return to bug 4417