~clint-fewbar/ubuntu/precise/squid3/ignore-sighup-early

« back to all changes in this revision

Viewing changes to lib/tempnam.c

  • Committer: Bazaar Package Importer
  • Author(s): Luigi Gangitano
  • Date: 2010-05-04 11:15:49 UTC
  • mfrom: (1.3.1 upstream)
  • mto: (20.3.1 squeeze) (21.2.1 sid)
  • mto: This revision was merged to the branch mainline in revision 21.
  • Revision ID: james.westby@ubuntu.com-20100504111549-1apjh2g5sndki4te
Tags: upstream-3.1.3
ImportĀ upstreamĀ versionĀ 3.1.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * $Id: tempnam.c,v 1.11 2003/01/23 00:37:02 robertc Exp $
 
2
 * $Id$
3
3
 */
4
4
 
5
5
/* A reasonably functional tmpnam. */
61
61
{
62
62
    static const char digits[] =
63
63
#if (L_tmpnam >= L_tmpmin + LONG_BIT / 4)
64
 
    "0123456789abcdef";
 
64
        "0123456789abcdef";
65
65
#define TMP_BASE        16
66
66
#else
67
 
    "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-";
 
67
        "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-";
68
68
#define TMP_BASE        64
69
69
#endif
70
70
    static unsigned long lastcount = 0;
74
74
    pid_t pid = getpid();
75
75
 
76
76
    if (sizeof(_tmp) - 1 != lengthof_tmp)
77
 
        abort();                /* Consistency error. */
 
77
        abort();                /* Consistency error. */
78
78
 
79
79
    for (;;) {
80
 
        register int i = L_tmpnam;
81
 
        register unsigned long c;
82
 
        register unsigned int p;
83
 
 
84
 
        /* Build filename. (the hard way) */
85
 
        s += i;
86
 
        *s = '\0';
87
 
 
88
 
        c = (count == TMP_MAX) ? 0 : ++count;
89
 
        do {
90
 
            *--s = digits[c % TMP_BASE];
91
 
            c /= TMP_BASE;
92
 
        } while (--i > L_tmpmin);
93
 
 
94
 
        p = (unsigned int) pid;
95
 
        do {
96
 
            *--s = digits[p % 10];
97
 
            p /= 10;
98
 
        } while (--i > lengthof_tmp);
99
 
 
100
 
        do {
101
 
            *--s = _tmp[--i];
102
 
        } while (i > 0);
103
 
 
104
 
        /* Check that the file doesn't exist. */
105
 
        if (access(s, 0) != 0)
106
 
            break;
107
 
 
108
 
        /* It exists; retry unless we tried them all. */
109
 
        if (count == lastcount) {
110
 
            s = NULL;
111
 
            break;
112
 
        }
 
80
        register int i = L_tmpnam;
 
81
        register unsigned long c;
 
82
        register unsigned int p;
 
83
 
 
84
        /* Build filename. (the hard way) */
 
85
        s += i;
 
86
        *s = '\0';
 
87
 
 
88
        c = (count == TMP_MAX) ? 0 : ++count;
 
89
        do {
 
90
            *--s = digits[c % TMP_BASE];
 
91
            c /= TMP_BASE;
 
92
        } while (--i > L_tmpmin);
 
93
 
 
94
        p = (unsigned int) pid;
 
95
        do {
 
96
            *--s = digits[p % 10];
 
97
            p /= 10;
 
98
        } while (--i > lengthof_tmp);
 
99
 
 
100
        do {
 
101
            *--s = _tmp[--i];
 
102
        } while (i > 0);
 
103
 
 
104
        /* Check that the file doesn't exist. */
 
105
        if (access(s, 0) != 0)
 
106
            break;
 
107
 
 
108
        /* It exists; retry unless we tried them all. */
 
109
        if (count == lastcount) {
 
110
            s = NULL;
 
111
            break;
 
112
        }
113
113
    }
114
114
 
115
115
    lastcount = count;
130
130
    char *t;
131
131
    int n = 0;
132
132
    while ((t = tempnam(NULL, NULL))) {
133
 
        printf("%s\n", t);
134
 
        if (++n == 1000)
135
 
            break;
 
133
        printf("%s\n", t);
 
134
        if (++n == 1000)
 
135
            break;
136
136
    }
137
137
    return 1;
138
138
}