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

Subversion Repositories or1k

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

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
 
6
int mkstemp(template)
7
char * template;
8
{
9
        int i;
10
        int num; /* UNINITIALIZED */
11
        int n2;
12
        int l = strlen(template);
13
 
14
        if (l<6) {
15
                errno = EINVAL;
16
                return -1;
17
        }
18
 
19
        for(i=l-6;i<l;i++)
20
                if (template[i] != 'X') {
21
                        errno = EINVAL;
22
                        return -1;
23
                }
24
 
25
again:
26
        n2 = num;
27
        for(i=l-1;i>=l-6;i--) {
28
                template[i] = '0' + n2 % 10;
29
                n2 /= 10;
30
        }
31
 
32
        i = open(template, O_RDWR|O_EXCL|O_CREAT, 0666);
33
 
34
        if (i==-1) {
35
                if (errno == EEXIST) {
36
                        num++;
37
                        goto again;
38
                } else
39
                        return -1;
40
        }
41
 
42
        return i;
43
}

powered by: WebSVN 2.1.0

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