1 /* $OpenBSD: scheck.c,v 1.8 2005/08/08 08:05:38 espie Exp $ */ 2 /* 3 ** This file is in the public domain, so clarified as of 4 ** Feb 14, 2003 by Arthur David Olson (arthur_david_olson@nih.gov). 5 */ 6 7 /*LINTLIBRARY*/ 8 9 #include "private.h" 10 11 char * scheck(string,format)12scheck(string, format) 13 const char * const string; 14 char * const format; 15 { 16 register char * fbuf; 17 register const char * fp; 18 register char * tp; 19 register int c; 20 register char * result; 21 char dummy; 22 static char nada; 23 24 result = &nada; 25 if (string == NULL || format == NULL) 26 return result; 27 fbuf = imalloc((int) (2 * strlen(format) + 4)); 28 if (fbuf == NULL) 29 return result; 30 fp = format; 31 tp = fbuf; 32 while ((*tp++ = c = *fp++) != '\0') { 33 if (c != '%') 34 continue; 35 if (*fp == '%') { 36 *tp++ = *fp++; 37 continue; 38 } 39 *tp++ = '*'; 40 if (*fp == '*') 41 ++fp; 42 while (is_digit(*fp)) 43 *tp++ = *fp++; 44 if (*fp == 'l' || *fp == 'h') 45 *tp++ = *fp++; 46 else if (*fp == '[') 47 do *tp++ = *fp++; 48 while (*fp != '\0' && *fp != ']'); 49 if ((*tp++ = *fp++) == '\0') 50 break; 51 } 52 *(tp - 1) = '%'; 53 *tp++ = 'c'; 54 *tp = '\0'; 55 if (sscanf(string, fbuf, &dummy) != 1) 56 result = (char *) format; 57 ifree(fbuf); 58 return result; 59 } 60