1#!/bin/sh 2 3cat << _EOF > $2 4#include <sys/types.h> 5#include <stdio.h> 6#include <stdarg.h> 7#include <stdint.h> 8#include <string.h> 9 10#include <atf-c.h> 11 12/* Avoid SSP re-definitions */ 13#undef snprintf 14#undef vsnprintf 15#undef sprintf 16#undef vsprintf 17 18#define KPRINTF_BUFSIZE 1024 19#undef putchar 20#define putchar xputchar 21static int putchar(char c, int foo, void *b) 22{ 23 return fputc(c, stderr); 24} 25 26#define TOBUFONLY 1 27static const char HEXDIGITS[] = "0123456789ABCDEF"; 28static const char hexdigits[] = "0123456789abcdef"; 29 30typedef int device_t; 31 32#define device_xname(a) "" 33int kprintf(const char *, int, void *, char *, va_list) __printflike(1, 0); 34void device_printf(device_t, const char *, ...) __printflike(2, 3); 35 36static void 37empty(void) 38{ 39} 40 41static void (*v_flush)(void) = empty; 42 43ATF_TC(snprintf_print); 44ATF_TC_HEAD(snprintf_print, tc) 45{ 46 atf_tc_set_md_var(tc, "descr", "checks snprintf print"); 47} 48 49ATF_TC_BODY(snprintf_print, tc) 50{ 51 char buf[10]; 52 int i; 53 54 memset(buf, 'x', sizeof(buf)); 55 i = snprintf(buf, sizeof(buf), "number %d", 10); 56 ATF_CHECK_EQ(i, 9); 57 ATF_CHECK_STREQ(buf, "number 10"); 58} 59 60ATF_TC(snprintf_print_overflow); 61ATF_TC_HEAD(snprintf_print_overflow, tc) 62{ 63 atf_tc_set_md_var(tc, "descr", "checks snprintf print with overflow"); 64} 65 66ATF_TC_BODY(snprintf_print_overflow, tc) 67{ 68 char buf[10]; 69 int i; 70 71 memset(buf, 'x', sizeof(buf)); 72 i = snprintf(buf, sizeof(buf), "fjsdfsdjfsdf %d\n", 10); 73 ATF_CHECK_EQ(i, 16); 74 ATF_CHECK_STREQ(buf, "fjsdfsdjf"); 75} 76 77ATF_TC(snprintf_count); 78ATF_TC_HEAD(snprintf_count, tc) 79{ 80 atf_tc_set_md_var(tc, "descr", "checks snprintf count"); 81} 82 83ATF_TC_BODY(snprintf_count, tc) 84{ 85 int i; 86 87 i = snprintf(NULL, 20, "number %d", 10); 88 ATF_CHECK_EQ(i, 9); 89} 90 91ATF_TC(snprintf_count_overflow); 92ATF_TC_HEAD(snprintf_count_overflow, tc) 93{ 94 atf_tc_set_md_var(tc, "descr", "checks snprintf count with overflow"); 95} 96 97ATF_TC_BODY(snprintf_count_overflow, tc) 98{ 99 int i; 100 101 i = snprintf(NULL, 10, "fjsdfsdjfsdf %d\n", 10); 102 ATF_CHECK_EQ(i, 16); 103} 104 105ATF_TP_ADD_TCS(tp) 106{ 107 ATF_TP_ADD_TC(tp, snprintf_print); 108 ATF_TP_ADD_TC(tp, snprintf_print_overflow); 109 ATF_TP_ADD_TC(tp, snprintf_count); 110 ATF_TP_ADD_TC(tp, snprintf_count_overflow); 111 112 return atf_no_error(); 113} 114_EOF 115 116awk ' 117/^snprintf\(/ { 118 print prevline 119 out = 1 120} 121{ 122 if (out) print 123 else prevline = $0 124}' $1 >>$2 125