gen_t_subr_prf revision 1.5
11.1Schristos#!/bin/sh 21.1Schristos 31.1Schristoscat << _EOF > $2 41.1Schristos#include <sys/types.h> 51.4Stls#include <sys/time.h> 61.1Schristos#include <stdio.h> 71.1Schristos#include <stdarg.h> 81.1Schristos#include <stdint.h> 91.1Schristos#include <string.h> 101.4Stls#include <sha2.h> 111.1Schristos 121.1Schristos#include <atf-c.h> 131.1Schristos 141.3Schristos/* Avoid SSP re-definitions */ 151.3Schristos#undef snprintf 161.3Schristos#undef vsnprintf 171.3Schristos#undef sprintf 181.3Schristos#undef vsprintf 191.3Schristos 201.1Schristos#define KPRINTF_BUFSIZE 1024 211.1Schristos#undef putchar 221.1Schristos#define putchar xputchar 231.4Stls 241.1Schristosstatic int putchar(char c, int foo, void *b) 251.1Schristos{ 261.1Schristos return fputc(c, stderr); 271.1Schristos} 281.1Schristos 291.1Schristos#define TOBUFONLY 1 301.1Schristosstatic const char HEXDIGITS[] = "0123456789ABCDEF"; 311.1Schristosstatic const char hexdigits[] = "0123456789abcdef"; 321.1Schristos 331.1Schristostypedef int device_t; 341.1Schristos 351.4Stls#if 0 361.4Stlsstatic SHA512_CTX kprnd_sha; 371.4Stls#endif 381.4Stls 391.4Stls#define timespec timeval 401.4Stls#define nanotime(ts) gettimeofday(ts, NULL) 411.4Stls 421.1Schristos#define device_xname(a) "" 431.2Sjoergint kprintf(const char *, int, void *, char *, va_list) __printflike(1, 0); 441.2Sjoergvoid device_printf(device_t, const char *, ...) __printflike(2, 3); 451.1Schristos 461.1Schristosstatic void 471.1Schristosempty(void) 481.1Schristos{ 491.1Schristos} 501.1Schristos 511.1Schristosstatic void (*v_flush)(void) = empty; 521.1Schristos 531.1SchristosATF_TC(snprintf_print); 541.1SchristosATF_TC_HEAD(snprintf_print, tc) 551.1Schristos{ 561.1Schristos atf_tc_set_md_var(tc, "descr", "checks snprintf print"); 571.1Schristos} 581.1Schristos 591.1SchristosATF_TC_BODY(snprintf_print, tc) 601.1Schristos{ 611.5Smrg char buf[13]; 621.1Schristos int i; 631.1Schristos 641.1Schristos memset(buf, 'x', sizeof(buf)); 651.1Schristos i = snprintf(buf, sizeof(buf), "number %d", 10); 661.1Schristos ATF_CHECK_EQ(i, 9); 671.1Schristos ATF_CHECK_STREQ(buf, "number 10"); 681.1Schristos} 691.1Schristos 701.1SchristosATF_TC(snprintf_print_overflow); 711.1SchristosATF_TC_HEAD(snprintf_print_overflow, tc) 721.1Schristos{ 731.1Schristos atf_tc_set_md_var(tc, "descr", "checks snprintf print with overflow"); 741.1Schristos} 751.1Schristos 761.1SchristosATF_TC_BODY(snprintf_print_overflow, tc) 771.1Schristos{ 781.1Schristos char buf[10]; 791.1Schristos int i; 801.1Schristos 811.1Schristos memset(buf, 'x', sizeof(buf)); 821.1Schristos i = snprintf(buf, sizeof(buf), "fjsdfsdjfsdf %d\n", 10); 831.1Schristos ATF_CHECK_EQ(i, 16); 841.1Schristos ATF_CHECK_STREQ(buf, "fjsdfsdjf"); 851.1Schristos} 861.1Schristos 871.1SchristosATF_TC(snprintf_count); 881.1SchristosATF_TC_HEAD(snprintf_count, tc) 891.1Schristos{ 901.1Schristos atf_tc_set_md_var(tc, "descr", "checks snprintf count"); 911.1Schristos} 921.1Schristos 931.1SchristosATF_TC_BODY(snprintf_count, tc) 941.1Schristos{ 951.1Schristos int i; 961.1Schristos 971.1Schristos i = snprintf(NULL, 20, "number %d", 10); 981.1Schristos ATF_CHECK_EQ(i, 9); 991.1Schristos} 1001.1Schristos 1011.1SchristosATF_TC(snprintf_count_overflow); 1021.1SchristosATF_TC_HEAD(snprintf_count_overflow, tc) 1031.1Schristos{ 1041.1Schristos atf_tc_set_md_var(tc, "descr", "checks snprintf count with overflow"); 1051.1Schristos} 1061.1Schristos 1071.1SchristosATF_TC_BODY(snprintf_count_overflow, tc) 1081.1Schristos{ 1091.1Schristos int i; 1101.1Schristos 1111.1Schristos i = snprintf(NULL, 10, "fjsdfsdjfsdf %d\n", 10); 1121.1Schristos ATF_CHECK_EQ(i, 16); 1131.1Schristos} 1141.1Schristos 1151.1SchristosATF_TP_ADD_TCS(tp) 1161.1Schristos{ 1171.1Schristos ATF_TP_ADD_TC(tp, snprintf_print); 1181.1Schristos ATF_TP_ADD_TC(tp, snprintf_print_overflow); 1191.1Schristos ATF_TP_ADD_TC(tp, snprintf_count); 1201.1Schristos ATF_TP_ADD_TC(tp, snprintf_count_overflow); 1211.1Schristos 1221.1Schristos return atf_no_error(); 1231.1Schristos} 1241.1Schristos_EOF 1251.1Schristos 1261.1Schristosawk ' 1271.1Schristos/^snprintf\(/ { 1281.1Schristos print prevline 1291.1Schristos out = 1 1301.1Schristos} 1311.1Schristos{ 1321.1Schristos if (out) print 1331.1Schristos else prevline = $0 1341.1Schristos}' $1 >>$2 135