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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [uclinux/] [uC-libc/] [misc/] [mkstemp.c] - Rev 1765

Compare with Previous | Blame | View Log

 
#include <features.h>
#include <unistd.h>
#include <fcntl.h>
 
int mkstemp(template)
char * template;
{
	int i;
	int num; /* UNINITIALIZED */
	int n2;
	int l = strlen(template);
 
	if (l<6) {
		errno = EINVAL;
		return -1;
	}
 
	for(i=l-6;i<l;i++)
		if (template[i] != 'X') {
			errno = EINVAL;
			return -1;
		}
 
again:	
	n2 = num;
	for(i=l-1;i>=l-6;i--) {
		template[i] = '0' + n2 % 10;
		n2 /= 10;
	}
 
	i = open(template, O_RDWR|O_EXCL|O_CREAT, 0666);
 
	if (i==-1) {
		if (errno == EEXIST) {
			num++;
			goto again;
		} else
			return -1;
	}
 
	return i;
}
 

Compare with Previous | Blame | View Log

powered by: WebSVN 2.1.0

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