tools/llvm: Do not build with symbols
[minix3.git] / lib / libc / time / scheck.c
bloba02e7b37791015a770b3168442f9c9f74c8d9dea
1 /* $NetBSD: scheck.c,v 1.11 2013/07/17 23:09:26 christos 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.11 2013/07/17 23:09:26 christos Exp $");
19 #endif
20 #endif /* !defined lint */
22 /*LINTLIBRARY*/
24 #include "private.h"
26 const char *
27 scheck(const char *const string, const char *const format)
29 char * fbuf;
30 const char * fp;
31 char * tp;
32 int c;
33 const char * result;
34 char dummy;
36 result = "";
37 if (string == NULL || format == NULL)
38 return result;
39 fbuf = malloc(2 * strlen(format) + 4);
40 if (fbuf == NULL)
41 return result;
42 fp = format;
43 tp = fbuf;
46 ** Copy directives, suppressing each conversion that is not
47 ** already suppressed. Scansets containing '%' are not
48 ** supported; e.g., the conversion specification "%[%]" is not
49 ** supported. Also, multibyte characters containing a
50 ** non-leading '%' byte are not supported.
52 while ((*tp++ = c = *fp++) != '\0') {
53 if (c != '%')
54 continue;
55 if (is_digit(*fp)) {
56 char const *f = fp;
57 char *t = tp;
58 do {
59 *t++ = c = *f++;
60 } while (is_digit(c));
61 if (c == '$') {
62 fp = f;
63 tp = t;
66 *tp++ = '*';
67 if (*fp == '*')
68 ++fp;
69 if ((*tp++ = *fp++) == '\0')
70 break;
73 *(tp - 1) = '%';
74 *tp++ = 'c';
75 *tp = '\0';
76 if (sscanf(string, fbuf, &dummy) != 1)
77 result = format;
78 free(fbuf);
79 return result;