2 !!DESCRIPTION!! varargs test
4 !!LICENCE!! public domain
11 void chk0(char *format,...);
12 void chk1(int fd,char *format,...);
15 // old workaround for broken varargs
17 void chk0(char *format,...){
18 __asm__ ("pha"); // save argument size
23 static char string[0x100];
25 // va_start(ap,format);
26 __asm__ ("pla"); // restore argument size
27 __asm__ ("ldx #$00"); // clear hibyte of AX
30 // get value of format
32 _format=*((char**)ap);
34 // vsprintf(string,format,ap);
35 vsprintf(&string[0],_format,ap);
36 printf("format:%s,string:%s\n",_format,string);
42 void chk1(int fd,char *format,...){
43 __asm__ ("pha"); // save argument size
49 static char string[0x100];
51 // va_start(ap,format);
52 __asm__ ("pla"); // restore argument size
53 __asm__ ("ldx #$00"); // clear hibyte of AX
59 // get value of format
61 _format=*((char**)ap);
63 // vsprintf(string,format,ap);
64 vsprintf(&string[0],_format,ap);
65 printf("fd:%d,format:%s,string:%s\n",_fd,_format,string);
73 void chk0(char *format,...){
75 static char string[0x100];
77 vsprintf(string,format,ap);
78 printf("format:%s,string:%s\n",format,string);
82 void chk1(int fd,char *format,...){
84 static char string[0x100];
88 vsprintf(string,format,ap);
89 printf("fd:%d,format:%s,string:%s\n",fd,format,string);
93 int main(int argc,char **argv) {
94 printf("varargs test\n");
96 printf("\nchk0/0:\n");chk0("chk0 %s","arg0");
97 printf("\nchk0/1:\n");chk0("chk0 %s %s","arg0","arg1");
98 printf("\nchk0/2:\n");chk0("chk0 %s %s %s","arg0","arg1","arg2");
100 printf("\nchk1/0:\n");chk1(0xfd,"chk1 %s","arg0");
101 printf("\nchk1/1:\n");chk1(0xfd,"chk1 %s %s","arg0","arg1");
102 printf("\nchk1/2:\n");chk1(0xfd,"chk1 %s %s %s","arg0","arg1","arg2");