1 /***********************************************************************
2  *                                                                      *
3  *               This software is part of the ast package               *
4  *          Copyright (c) 1999-2011 AT&T Intellectual Property          *
5  *                      and is licensed under the                       *
6  *                 Eclipse Public License, Version 1.0                  *
7  *                    by AT&T Intellectual Property                     *
8  *                                                                      *
9  *                A copy of the License is available at                 *
10  *          http://www.eclipse.org/org/documents/epl-v10.html           *
11  *         (with md5 checksum b35adb5213ca9657e911e9befb180842)         *
12  *                                                                      *
13  *              Information and Software Systems Research               *
14  *                            AT&T Research                             *
15  *                           Florham Park NJ                            *
16  *                                                                      *
17  *               Glenn Fowler <glenn.s.fowler@gmail.com>                *
18  *                                                                      *
19  ***********************************************************************/
20 #include "config_ast.h"  // IWYU pragma: keep
21 
22 #include <signal.h>
23 #include <stdarg.h>
24 #include <stddef.h>
25 
26 #include "sfhdr.h"  // IWYU pragma: keep
27 #include "sfio.h"
28 #include "terror.h"
29 
30 int Code_line = 42; /* line number of CALL(sfclose(0)) */
31 
32 #if defined(__LINE__)
33 #define CALL(x) ((Code_line = __LINE__), (x))
34 #else
35 #define CALL(x) ((Code_line += 1), (x))
36 #endif
37 
handler(int sig)38 void handler(int sig) {
39     UNUSED(sig);
40 
41     terror("Bad argument handling on code line %d", Code_line);
42 }
43 
main_varargs(int argc,char ** argv,...)44 void main_varargs(int argc, char **argv, ...) {
45     UNUSED(argc);
46     UNUSED(argv);
47     va_list args;
48 
49     signal(SIGILL, handler);
50     signal(SIGBUS, handler);
51     signal(SIGSEGV, handler);
52 
53     CALL(sfclose(NULL));
54     CALL(sfclrlock(NULL));
55     CALL(sfopen(NULL, NULL, NULL));
56     CALL(sfdisc(NULL, NULL));
57     CALL(_sffilbuf(0, 0));
58     CALL(_sfflsbuf(0, 0));
59     CALL(sfgetd(NULL));
60     CALL(sfgetl(NULL));
61     CALL(sfgetm(NULL, 0));
62     CALL(sfgetr(NULL, 0, 0));
63     CALL(sfgetu(NULL));
64     CALL(sfmove(NULL, NULL, 0, 0));
65     CALL(sfmutex(NULL, 0));
66     CALL(sfnew(NULL, NULL, 0, 0, 0));
67     CALL(sfnputc(NULL, 0, 0));
68     CALL(sfopen(NULL, NULL, NULL));
69     CALL(sfpool(NULL, NULL, 0));
70     CALL(sfpopen(NULL, NULL, NULL));
71     CALL(sfprintf(NULL, NULL));
72     CALL(sfsprintf(NULL, 0, NULL));
73     CALL(sfprints(NULL));
74     CALL(sfpurge(NULL));
75     CALL(sfputd(NULL, 0));
76     CALL(sfputl(NULL, 0));
77     CALL(sfputm(NULL, 0, 0));
78     CALL(sfputr(NULL, NULL, 0));
79     CALL(sfputu(NULL, 0));
80     CALL(sfraise(NULL, 0, NULL));
81     CALL(sfrd(NULL, NULL, 0, NULL));
82     CALL(sfread(NULL, NULL, 0));
83     CALL(sfreserve(NULL, 0, 0));
84     CALL(sfresize(NULL, 0));
85     CALL(sfscanf(NULL, NULL));
86     CALL(sfsscanf(NULL, NULL));
87     CALL(sfseek(NULL, 0, 0));
88     CALL(sfset(NULL, 0, 0));
89     CALL(sfsetbuf(NULL, NULL, 0));
90     CALL(sfsetfd(NULL, 0));
91     CALL(sfsize(NULL));
92     CALL(sfsk(NULL, 0, 0, NULL));
93     CALL(sfstack(NULL, NULL));
94     CALL(sfswap(NULL, NULL));
95     CALL(sfsync(NULL));
96     CALL(sftell(NULL));
97     CALL(sftmp(0));
98     CALL(sfungetc(NULL, 0));
99     CALL(sfwr(NULL, NULL, 0, NULL));
100     CALL(sfwrite(NULL, NULL, 0));
101 
102     va_start(args, argv);
103     CALL(sfvprintf(NULL, NULL, args));
104     CALL(sfvscanf(NULL, NULL, args));
105     CALL(sfvsprintf(NULL, 0, NULL, args));
106     CALL(sfvsscanf(NULL, NULL, args));
107     va_end(args);
108 }
109 
tmain()110 tmain() {
111     main_varargs(argc, argv);
112     texit(0);
113 }
114