OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [uclinux/] [uC-libc/] [misc/] [mktemp.c] - Blame information for rev 199

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 199 simons
 
2
#include <features.h>
3
#include <unistd.h>
4
#include <fcntl.h>
5
#include <sys/stat.h>
6
 
7
char * mktemp(template)
8
char * template;
9
{
10
        int i;
11
        int num; /* UNINITIALIZED */
12
        int n2;
13
        int l = strlen(template);
14
        struct stat stbuf;
15
 
16
        if (l<6) {
17
                errno = EINVAL;
18
                return 0;
19
        }
20
 
21
        for(i=l-6;i<l;i++)
22
                if (template[i] != 'X') {
23
                        errno = EINVAL;
24
                        return 0;
25
                }
26
 
27
again:
28
        n2 = num;
29
        for(i=l-1;i>=l-6;i--) {
30
                template[i] = '0' + n2 % 10;
31
                n2 /= 10;
32
        }
33
 
34
        if (stat(template, &stbuf) == 0) {
35
                num++;
36
                goto again;
37
        }
38
 
39
        return template;
40
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.