~ubuntu-branches/ubuntu/lucid/graphviz/lucid-security

« back to all changes in this revision

Viewing changes to cdt/features/common

  • Committer: Bazaar Package Importer
  • Author(s): Stephen M Moraco
  • Date: 2002-02-05 18:52:12 UTC
  • Revision ID: james.westby@ubuntu.com-20020205185212-8i04c70te00rc40y
Tags: upstream-1.7.16
ImportĀ upstreamĀ versionĀ 1.7.16

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
iff     AST_COMMON
 
2
hdr     pthread
 
3
hdr     stddef
 
4
hdr     types
 
5
sys     types
 
6
typ     size_t,ssize_t
 
7
typ     long.double
 
8
 
 
9
proto   stdc note{ Standard-C prototypes ok }end compile{
 
10
        extern int foo(int, int);
 
11
        bar()
 
12
        {       foo(1, 1);
 
13
        }
 
14
}end
 
15
 
 
16
dll     import note{ Microsoft import/export nonsense }end execute{
 
17
        __declspec(dllimport) int foo;
 
18
        main() { return foo == 5 ? 0 : 1; }
 
19
        int     bar = 5;
 
20
        int*    _imp__foo = &bar;
 
21
}end
 
22
 
 
23
xopen   stdio note{ Stdio fseek/fflush are X/Open-compliant }end execute{
 
24
        #include        <stdio.h>
 
25
        #define Failed(file)    (unlink(file),1)
 
26
        main(int argc, char** argv)
 
27
        {       FILE    *f1, *f2;
 
28
                char    file[1024], buf[1024], *f, *t;
 
29
                int     i, fd;
 
30
 
 
31
                /* create file */
 
32
                for(f = argv[0], t = file; (*t = *f++) != 0; )
 
33
                        t++;
 
34
                *t++ = '.'; *t++ = 'D'; *t++ = 0;
 
35
                if((fd = creat(file,0666)) < 0)
 
36
                        return 1;
 
37
 
 
38
                for (i = 0; i < sizeof(buf); ++i)
 
39
                        buf[i] = '0' + (i%10);
 
40
                for (i = 0; i < 16; ++i)
 
41
                        if (write(fd,buf,sizeof(buf)) != sizeof(buf))
 
42
                                return Failed(file);
 
43
                close(fd);
 
44
 
 
45
                if(!(f1 = fopen(file,"r+")) ||
 
46
                   (fd = dup(fileno(f1))) < 0 ||
 
47
                   !(f2 = fdopen(fd,"r+")) )
 
48
                        return Failed(file);
 
49
 
 
50
                if(fread(buf, 1, 7, f2) != 7 || ftell(f2) != 7)
 
51
                        return Failed(file);
 
52
 
 
53
                if(fseek(f1, 1010, 0) < 0 || ftell(f1) != 1010)
 
54
                        return Failed(file);
 
55
 
 
56
                fflush(f2); /* this should set the seek location to 1010 */
 
57
                if(ftell(f2) != 1010)
 
58
                        return Failed(file);
 
59
 
 
60
                unlink(file);
 
61
                return 0;
 
62
        }
 
63
}end
 
64
 
 
65
cat{
 
66
        
 
67
        /* __STD_C indicates that the language is ANSI-C or C++ */
 
68
        #if !defined(__STD_C) && __STDC__
 
69
        #define __STD_C         1
 
70
        #endif
 
71
        #if !defined(__STD_C) && (__cplusplus || c_plusplus)
 
72
        #define __STD_C         1
 
73
        #endif
 
74
        #if !defined(__STD_C) && _proto_stdc
 
75
        #define __STD_C         1
 
76
        #endif
 
77
        #if !defined(__STD_C)
 
78
        #define __STD_C         0
 
79
        #endif
 
80
 
 
81
        /* extern symbols must be protected against C++ name mangling */
 
82
        #ifndef _BEGIN_EXTERNS_
 
83
        #if __cplusplus || c_plusplus
 
84
        #define _BEGIN_EXTERNS_ extern "C" {
 
85
        #define _END_EXTERNS_   }
 
86
        #else
 
87
        #define _BEGIN_EXTERNS_
 
88
        #define _END_EXTERNS_
 
89
        #endif
 
90
        #endif /*_BEGIN_EXTERNS_*/
 
91
 
 
92
        /* _ARG_ simplifies function prototyping among flavors of C */
 
93
        #ifndef _ARG_
 
94
        #if __STD_C
 
95
        #define _ARG_(x)        x
 
96
        #else
 
97
        #define _ARG_(x)        ()
 
98
        #endif
 
99
        #endif /*_ARG_*/
 
100
 
 
101
        /* __INLINE__ is the inline keyword */
 
102
        #if !defined(__INLINE__) && defined(__cplusplus)
 
103
        #define __INLINE__      inline
 
104
        #endif
 
105
        #if !defined(__INLINE__) && defined(_WIN32) && !defined(__GNUC__)
 
106
        #define __INLINE__      __inline
 
107
        #endif
 
108
 
 
109
        /* Void_t is defined so that Void_t* can address any type */
 
110
        #ifndef Void_t
 
111
        #if __STD_C
 
112
        #define Void_t          void
 
113
        #else
 
114
        #define Void_t          char
 
115
        #endif
 
116
        #endif /*Void_t*/
 
117
 
 
118
        /* dynamic linked library external scope handling */
 
119
        #undef extern
 
120
        #if _dll_import && !defined(__EXPORT__) && _DLL_BLD
 
121
        #define __EXPORT__      __declspec(dllexport)
 
122
        #endif
 
123
        #if _dll_import && !defined(__IMPORT__)
 
124
        #define __IMPORT__      __declspec(dllimport)
 
125
        #endif
 
126
        #if !defined(_astimport)
 
127
        #if defined(__IMPORT__) && _DLL_BLD
 
128
        #define _astimport      __IMPORT__
 
129
        #else
 
130
        #define _astimport      extern
 
131
        #endif
 
132
        #endif /*_astimport*/
 
133
}end
 
134
 
 
135
cat{
 
136
        #if !_DLL_BLD && _dll_import
 
137
        #define __EXTERN__(T,obj)       extern T obj; T* _imp__ ## obj = &obj
 
138
        #define __DEFINE__(T,obj,val)   T obj = val; T* _imp__ ## obj = &obj
 
139
        #else
 
140
        #define __EXTERN__(T,obj)       extern T obj
 
141
        #define __DEFINE__(T,obj,val)   T obj = val
 
142
        #endif
 
143
}end
 
144
 
 
145
cat{
 
146
        #ifndef _AST_STD_H
 
147
        #       if _hdr_stddef
 
148
        #       include <stddef.h>
 
149
        #       endif
 
150
        #       if _sys_types
 
151
        #       include <sys/types.h>
 
152
        #       endif
 
153
        #endif
 
154
        #if !_typ_size_t
 
155
        #       define _typ_size_t      1
 
156
                typedef int size_t;
 
157
        #endif
 
158
        #if !_typ_ssize_t
 
159
        #       define _typ_ssize_t     1
 
160
                typedef int ssize_t;
 
161
        #endif
 
162
}end
 
163
 
 
164
tst     - -DN=0 - -DN=1 - -DN=2 - -DN=3 - -DN=4 - -DN=5 - -DN=6 - -DN=7 - -DN=8 output{
 
165
        #define _BYTESEX_H
 
166
 
 
167
        #if _STD_
 
168
        #include        <stddef.h>
 
169
        #else
 
170
        #include        <sys/types.h>
 
171
        #endif
 
172
 
 
173
        _BEGIN_EXTERNS_
 
174
        extern int      printf _ARG_((const char*, ...));
 
175
        _END_EXTERNS_
 
176
        
 
177
        #if N == 0
 
178
        #define _ast_int8_t     long
 
179
        #define _ast_int8_str   "long"
 
180
        #endif
 
181
        #if N == 1
 
182
        #define _ast_int8_t     long long
 
183
        #define _ast_int8_str   "long long"
 
184
        #endif
 
185
        #if N == 2
 
186
        #define _ast_int8_t     __int64_t
 
187
        #define _ast_int8_str   "__int64_t"
 
188
        #endif
 
189
        #if N == 3
 
190
        #define _ast_int8_t     _int64_t
 
191
        #define _ast_int8_str   "_int64_t"
 
192
        #endif
 
193
        #if N == 4
 
194
        #define _ast_int8_t     int64_t
 
195
        #define _ast_int8_str   "int64_t"
 
196
        #endif
 
197
        #if N == 5
 
198
        #define _ast_int8_t     __int64
 
199
        #define _ast_int8_str   "__int64"
 
200
        #endif
 
201
        #if N == 6
 
202
        #define _ast_int8_t     _int64
 
203
        #define _ast_int8_str   "_int64"
 
204
        #endif
 
205
        #if N == 7
 
206
        #define _ast_int8_t     int64
 
207
        #define _ast_int8_str   "int64"
 
208
        #endif
 
209
 
 
210
        #define elementsof(x)   (sizeof(x)/sizeof(x[0]))
 
211
        
 
212
        static char             i_char = 1;
 
213
        static short            i_short = 1;
 
214
        static int              i_int = 1;
 
215
        static long             i_long = 1;
 
216
        #ifdef _ast_int8_t
 
217
        static _ast_int8_t      i_long_long = 1;
 
218
        #endif
 
219
        
 
220
        static struct
 
221
        {
 
222
                char*   name;
 
223
                int     size;
 
224
                char*   swap;
 
225
        } int_type[] = 
 
226
        {
 
227
                "char",         sizeof(char),           (char*)&i_char,
 
228
                "short",        sizeof(short),          (char*)&i_short,
 
229
                "int",          sizeof(int),            (char*)&i_int,
 
230
                "long",         sizeof(long),           (char*)&i_long,
 
231
        #ifdef _ast_int8_t
 
232
                _ast_int8_str,  sizeof(_ast_int8_t),    (char*)&i_long_long,
 
233
        #endif
 
234
        };
 
235
        
 
236
        static struct
 
237
        {
 
238
                char*   name;
 
239
                int     size;
 
240
        } flt_type[] = 
 
241
        {
 
242
                "float",        sizeof(float),
 
243
                "double",       sizeof(double),
 
244
        #ifdef _typ_long_double
 
245
                "long double",  sizeof(long double),
 
246
        #endif
 
247
        };
 
248
        
 
249
        static int      int_size[] = { 1, 2, 4, 8 };
 
250
        
 
251
        main()
 
252
        {
 
253
                register int    t;
 
254
                register int    s;
 
255
                register int    m = 1;
 
256
                register int    b = 1;
 
257
                register int    w = 0;
 
258
        
 
259
        #ifdef _ast_int8_t
 
260
                if (int_type[elementsof(int_type)-1].size <= 4)
 
261
                        return 1;
 
262
        #endif
 
263
                for (s = 0; s < elementsof(int_size); s++)
 
264
                {
 
265
                        for (t = 0; t < elementsof(int_type); t++)
 
266
                                if(int_type[t].size >= int_size[s])
 
267
                                        break;
 
268
                        if (t < elementsof(int_type))
 
269
                        {
 
270
                                m = int_size[s];
 
271
                                printf("#define _ast_int%d_t\t\t%s\n",
 
272
                                        m, int_type[t].name);
 
273
                                if (m > 1)
 
274
                                {
 
275
                                        if (*int_type[t].swap)
 
276
                                                w |= b;
 
277
                                        b <<= 1;
 
278
                                }
 
279
                        }
 
280
                }
 
281
                printf("#define _ast_intmax_t           _ast_int%d_t\n", m);
 
282
                if (m == sizeof(long))
 
283
                        printf("#define _ast_intmax_long                1\n");
 
284
                printf("#define _ast_intswap            %d\n", w);
 
285
                printf("\n");
 
286
                for (t = 0; t < elementsof(flt_type); t++)
 
287
                {
 
288
                        for(; t < elementsof(flt_type); t++)
 
289
                                if(flt_type[t].size != flt_type[t + 1].size)
 
290
                                        break;
 
291
                        m = flt_type[t].size;
 
292
                        printf("#define _ast_flt%d_t\t\t%s\n",
 
293
                                flt_type[t].size, flt_type[t].name);
 
294
                }
 
295
                printf("#define _ast_fltmax_t           _ast_flt%d_t\n", m);
 
296
                if (m == sizeof(double))
 
297
                        printf("#define _ast_fltmax_double              1\n");
 
298
                return 0;
 
299
        }
 
300
}end
 
301
 
 
302
tst - -DTRY=1 - -DTRY=1 -Dvoid=char - -DTRY=2 - -DTRY=3 - -DTRY=4 output{
 
303
        #define printf  ______printf
 
304
        #ifdef __STDC__
 
305
        #include <stdarg.h>
 
306
        #else
 
307
        #include <varargs.h>
 
308
        #endif
 
309
        #undef  printf
 
310
        _BEGIN_EXTERNS_
 
311
        extern int      printf _ARG_((const char*, ...));
 
312
        _END_EXTERNS_
 
313
        static va_list ap;
 
314
        main()
 
315
        {
 
316
        #if TRY == 4
 
317
                printf("\n#ifndef va_listref\n");
 
318
                printf("#define va_listref(p) (&(p))\t");
 
319
                        printf("/* pass va_list to varargs function */\n");
 
320
                printf("#define va_listval(p) (*(p))\t");
 
321
                        printf("/* retrieve va_list from va_arg(ap,va_listarg) */\n");
 
322
                printf("#define va_listarg va_list*\t");
 
323
                        printf("/* va_arg() va_list type */\n");
 
324
        #else
 
325
        #if TRY == 1
 
326
                *ap++;
 
327
        #endif /*TRY == 1*/
 
328
        #if TRY == 2
 
329
                *ap;
 
330
        #endif /*TRY == 2*/
 
331
        #if TRY == 3
 
332
                ap++;
 
333
        #endif /*TRY == 3*/
 
334
 
 
335
                printf("\n#ifndef va_listref\n");
 
336
                printf("#define va_listref(p) (p)\t");
 
337
                        printf("/* pass va_list to varargs function */\n");
 
338
                printf("#define va_listval(p) (p)\t");
 
339
                        printf("/* retrieve va_list from va_arg(ap,va_listarg) */\n");
 
340
        #if TRY == 2
 
341
                printf("#define va_listarg va_list*\t");
 
342
        #else
 
343
                printf("#define va_listarg va_list\t");
 
344
        #endif /*TRY == 2*/
 
345
                        printf("/* va_arg() va_list type */\n");
 
346
        #endif /*TRY == 4*/
 
347
 
 
348
        #if defined(_WIN32) || !defined(va_copy)
 
349
                printf("#ifndef va_copy\n");
 
350
        #if TRY == 2
 
351
                printf("#define va_copy(to,fr) memcpy(to,fr,sizeof(va_list))\t");
 
352
                        printf("/* copy va_list fr -> to */\n");
 
353
        #else
 
354
                printf("#define va_copy(to,fr) ((to)=(fr))\t");
 
355
                        printf("/* copy va_list fr -> to */\n");
 
356
        #endif
 
357
                printf("#endif\n");
 
358
        #endif
 
359
 
 
360
        printf("#undef  _ast_va_list\n");
 
361
        printf("#ifdef  va_start\n");
 
362
        printf("#define _ast_va_list va_list\n");
 
363
        printf("#else\n");
 
364
        #if TRY == 1 || TRY == 2
 
365
                printf("#define _ast_va_list void*\t");
 
366
        #else
 
367
        #if TRY == 3
 
368
                if (sizeof(va_list) == sizeof(long))
 
369
                        printf("#define _ast_va_list long\t");
 
370
                else if (sizeof(va_list) == sizeof(short))
 
371
                        printf("#define _ast_va_list short\t");
 
372
                else
 
373
                        printf("#define _ast_va_list int\t");
 
374
        #else
 
375
                printf("#define _ast_va_list ...\t");
 
376
        #endif
 
377
        #endif
 
378
                printf("/* va_list that avoids #include */\n");
 
379
                printf("#endif\n\n");
 
380
                printf("#endif\n");
 
381
                return 0;
 
382
        }
 
383
}end