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

« back to all changes in this revision

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