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