Cleanup in elf.c with .bss section clean; adm command mounts cdrom instead of floppy...
[ZeXOS.git] / libc / stdlib / mkstemp.c
blob2389f794d170a0b4de1fbc401facc5d9547c6b9f
1 /*
2 * ZeX/OS
3 * Copyright (C) 2009 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include <time.h>
21 #include <fcntl.h>
22 #include <errno.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
27 int mkstemp (char *tmplate)
29 static const char letters[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
30 int len, r;
31 char *c;
33 errno = 0;
35 len = strlen (tmplate);
37 if (len >= 6) {
38 c = tmplate + len - 6;
39 srand((unsigned int) time (0));
41 if (strncmp (c, "XXXXXX", 6) == 0) {
42 int iChr;
43 for (iChr = 0; iChr < 6; iChr ++) {
44 r = rand() / 528.5;
45 *(c ++) = letters[r > 0 ? r - 1 : 0];
47 } else {
48 errno = EINVAL;
49 return -1;
51 } else {
52 errno = EINVAL;
53 return -1;
56 return open (tmplate, O_CREAT | O_RDWR);