retire BIOS_SEG and umap_bios
[minix3.git] / lib / libc / time / scheck.c
blob3a118da52dd33de97312b941a957e6bf9807ea1f
1 /* $NetBSD: scheck.c,v 1.8 2010/01/02 10:42:49 tsutsui Exp $ */
3 /*
4 ** This file is in the public domain, so clarified as of
5 ** 2006-07-17 by Arthur David Olson.
6 */
8 #if HAVE_NBTOOL_CONFIG_H
9 #include "nbtool_config.h"
10 #endif
12 #include <sys/cdefs.h>
14 #ifndef lint
15 #if 0
16 static char elsieid[] = "@(#)scheck.c 8.19";
17 #else
18 __RCSID("$NetBSD: scheck.c,v 1.8 2010/01/02 10:42:49 tsutsui Exp $");
19 #endif
20 #endif /* !defined lint */
22 /*LINTLIBRARY*/
24 #include "private.h"
26 const char *
27 scheck(string, format)
28 const char * const string;
29 const char * const format;
31 register char * fbuf;
32 register const char * fp;
33 register char * tp;
34 register int c;
35 register const char * result;
36 char dummy;
38 result = "";
39 if (string == NULL || format == NULL)
40 return result;
41 fbuf = imalloc((int) (2 * strlen(format) + 4));
42 if (fbuf == NULL)
43 return result;
44 fp = format;
45 tp = fbuf;
46 while ((*tp++ = c = *fp++) != '\0') {
47 if (c != '%')
48 continue;
49 if (*fp == '%') {
50 *tp++ = *fp++;
51 continue;
53 *tp++ = '*';
54 if (*fp == '*')
55 ++fp;
56 while (is_digit(*fp))
57 *tp++ = *fp++;
58 if (*fp == 'l' || *fp == 'h')
59 *tp++ = *fp++;
60 else if (*fp == '[')
61 do *tp++ = *fp++;
62 while (*fp != '\0' && *fp != ']');
63 if ((*tp++ = *fp++) == '\0')
64 break;
66 *(tp - 1) = '%';
67 *tp++ = 'c';
68 *tp = '\0';
69 if (sscanf(string, fbuf, &dummy) != 1)
70 result = (char *) format;
71 ifree(fbuf);
72 return result;