/programs/develop/libraries/menuetlibc/src/libc/compat/stdio/Makefile |
---|
0,0 → 1,3 |
THIS_SRCS = mkstemp.c mktemp.c tempnam.c vscanf.c vsscanf.c |
include $(MENUET_LIBC_TOPDIR)/Make.rules |
/programs/develop/libraries/menuetlibc/src/libc/compat/stdio/mkstemp.c |
---|
0,0 → 1,15 |
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ |
#include <stdio.h> |
#include <fcntl.h> |
#include <errno.h> |
int |
mkstemp (char *_template) |
{ |
if (mktemp (_template)) |
return creat (_template, 0666); |
else { |
errno = ENOENT; |
return -1; |
} |
} |
/programs/develop/libraries/menuetlibc/src/libc/compat/stdio/mktemp.c |
---|
0,0 → 1,69 |
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */ |
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ |
#include <libc/stubs.h> |
#include <libc/bss.h> |
#include <unistd.h> |
#include <stdio.h> |
#include <string.h> |
static int mktemp_count = -1; |
char * |
mktemp (char *_template) |
{ |
static int count = 0; |
char *cp, *dp; |
int i, len, xcount, loopcnt; |
/* Reinitialize counter if we were restarted (emacs). */ |
if (__bss_count != mktemp_count) |
{ |
mktemp_count = __bss_count; |
count = 0; |
} |
len = strlen (_template); |
cp = _template + len; |
xcount = 0; |
while (xcount < 6 && cp > _template && cp[-1] == 'X') |
xcount++, cp--; |
if (xcount) { |
dp = cp; |
while (dp > _template && dp[-1] != '/' && dp[-1] != '\\' && dp[-1] != ':') |
dp--; |
/* Keep the first characters of the template, but turn the rest into |
Xs. */ |
while (cp > dp + 8 - xcount) { |
*--cp = 'X'; |
xcount = (xcount >= 6) ? 6 : 1 + xcount; |
} |
/* If dots occur too early -- squash them. */ |
while (dp < cp) { |
if (*dp == '.') *dp = 'a'; |
dp++; |
} |
/* Try to add ".tmp" to the filename. Truncate unused Xs. */ |
if (cp + xcount + 3 < _template + len) |
strcpy (cp + xcount, ".tmp"); |
else |
cp[xcount] = 0; |
/* This loop can run up to 2<<(5*6) times, or about 10^9 times. */ |
for (loopcnt = 0; loopcnt < (1 << (5 * xcount)); loopcnt++) { |
int c = count++; |
for (i = 0; i < xcount; i++, c >>= 5) |
cp[i] = "abcdefghijklmnopqrstuvwxyz012345"[c & 0x1f]; |
if (!__file_exists(_template)) |
return _template; |
} |
} |
/* Failure: truncate the template and return NULL. */ |
*_template = 0; |
return 0; |
} |
/programs/develop/libraries/menuetlibc/src/libc/compat/stdio/tempnam.c |
---|
0,0 → 1,8 |
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ |
#include <stdio.h> |
#include <stdlib.h> |
char * tempnam(const char *_dir, const char *_prefix) |
{ |
return tmpnam(0); |
} |
/programs/develop/libraries/menuetlibc/src/libc/compat/stdio/vscanf.c |
---|
0,0 → 1,9 |
/* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */ |
#include <stdio.h> |
#include <stdarg.h> |
int |
vscanf(const char *fmt, va_list ap) |
{ |
return _doscan(stdin, fmt, ap); |
} |
/programs/develop/libraries/menuetlibc/src/libc/compat/stdio/vsscanf.c |
---|
0,0 → 1,20 |
/* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */ |
/* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */ |
#include <stdio.h> |
#include <stdarg.h> |
#include <libc/file.h> |
#include <libc/unconst.h> |
int |
vsscanf(const char *str, const char *fmt, va_list ap) |
{ |
FILE _strbuf; |
_strbuf._flag = _IOREAD|_IOSTRG|_IONTERM; |
_strbuf._ptr = _strbuf._base = unconst(str, char *); |
_strbuf._cnt = 0; |
while (*str++) |
_strbuf._cnt++; |
_strbuf._bufsiz = _strbuf._cnt; |
return _doscan(&_strbuf, fmt, ap); |
} |