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

« back to all changes in this revision

Viewing changes to tools/sfio/features/sfio

  • 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
##################################################################
 
2
# This file defines probes for local features that sfio requires.
 
3
# Such probes are interpreted by the "iffe" language interpreter.
 
4
# Results are stored in the FEATURE directory.
 
5
# Written by Kiem-Phong Vo (06/27/92).
 
6
# Converted to sfio v10/01/94 by Giampiero Sierra (06/08/95).
 
7
##################################################################
 
8
 
 
9
hdr time
 
10
sys time
 
11
 
 
12
hdr string
 
13
hdr math
 
14
lib qfrexp
 
15
lib qldexp
 
16
 
 
17
hdr unistd
 
18
hdr values
 
19
hdr floatingpoint
 
20
hdr float
 
21
lib atexit
 
22
lib onexit
 
23
 
 
24
lib ftruncate
 
25
 
 
26
lib lseek64
 
27
lib stat64
 
28
lib mmap64
 
29
typ off64_t
 
30
typ struct_stat64 compile{
 
31
        #include        <sys/types.h>
 
32
        #include        <sys/stat.h>
 
33
        main()
 
34
        {       struct stat64 statb;
 
35
        }
 
36
}end
 
37
 
 
38
exit    cleanup note{ stuck with standard _cleanup }end execute{
 
39
        #include <stdio.h>
 
40
        _BEGIN_EXTERNS_
 
41
        extern void exit _ARG_((int));
 
42
        extern void _exit _ARG_((int));
 
43
        extern void _cleanup();
 
44
        void _cleanup() { _exit(0); }
 
45
        _END_EXTERNS_
 
46
        main() { printf("cleanup\n"); exit(1); }
 
47
}end
 
48
 
 
49
lib bcopy
 
50
lib bzero
 
51
lib memcpy
 
52
lib memset
 
53
lib memalign
 
54
 
 
55
lib memchr note{ see if memchr is fast }end execute{
 
56
        #include        <sys/types.h>
 
57
        #include        <sys/times.h>
 
58
        #include        <stdlib.h>
 
59
 
 
60
        main()
 
61
        {       struct tms      stm1, etm1, stm2, etm2;
 
62
                register int    i, p;
 
63
                register char   *s, *ends;
 
64
                long            t1, t2;
 
65
                char            buf[128];
 
66
        
 
67
                for(p = 0; p < 100; ++p)
 
68
                        buf[p] = '0' + (p%10);
 
69
                buf[p++] = '\n';
 
70
                buf[p] = 0;
 
71
        
 
72
                times(&stm1);
 
73
                for(i = 0; i < 100000; ++i)
 
74
                        s = memchr(buf,'\n',p);
 
75
                times(&etm1);
 
76
        
 
77
                times(&stm2);
 
78
                for(i = 0; i < 100000; ++i)
 
79
                {       ends = (s = buf) + p;
 
80
                        while(*s != '\n')
 
81
                                if((s += 1) == ends)
 
82
                                        break;
 
83
                }
 
84
                times(&etm2);
 
85
        
 
86
                t1 = (etm1.tms_utime - stm1.tms_utime) +
 
87
                     (etm1.tms_stime - stm1.tms_stime);
 
88
                t2 = (etm2.tms_utime - stm2.tms_utime) +
 
89
                     (etm2.tms_stime - stm2.tms_stime);
 
90
        
 
91
                return t1 < t2 ? 0 : 1;
 
92
        }
 
93
}end
 
94
 
 
95
lib memccpy note{ see if memccpy is fast }end execute{
 
96
        #include        <sys/types.h>
 
97
        #include        <sys/times.h>
 
98
        #include        <stdlib.h>
 
99
 
 
100
        main()
 
101
        {       struct tms      stm1, etm1, stm2, etm2;
 
102
                register int    i, p;
 
103
                register char   *s1, *s2;
 
104
                long            t1, t2;
 
105
                char            buf1[128], buf2[128];
 
106
        
 
107
                for(i = 0; i < 100; ++i)
 
108
                        buf1[i] = '0' + (i%10);
 
109
                buf1[i++] = '\n';
 
110
                buf1[i] = 0;
 
111
        
 
112
                times(&stm1);
 
113
                for(i = 0; i < 100000; ++i)
 
114
                {       p = 128;
 
115
                        memccpy(buf2,buf1,'\n',p);
 
116
                }
 
117
                times(&etm1);
 
118
        
 
119
                times(&stm2);
 
120
                for(i = 0; i < 100000; ++i)
 
121
                {       s1 = buf1; s2 = buf2; p = 128;
 
122
                        while((*s2++ = *s1++) != '\n' && --p > 0)
 
123
                                ;
 
124
                }
 
125
                times(&etm2);
 
126
        
 
127
                t1 = (etm1.tms_utime - stm1.tms_utime) +
 
128
                     (etm1.tms_stime - stm1.tms_stime);
 
129
                t2 = (etm2.tms_utime - stm2.tms_utime) +
 
130
                     (etm2.tms_stime - stm2.tms_stime);
 
131
        
 
132
                return t1 < t2 ? 0 : 1;
 
133
        }
 
134
}end
 
135
 
 
136
sys stat note{ stat() in default lib(s) }end link{
 
137
        #if _STD_
 
138
        #include        <stddef.h>
 
139
        #else
 
140
        #include        <sys/types.h>
 
141
        #endif
 
142
        #include        <time.h>
 
143
        #include        <sys/stat.h>
 
144
        main()
 
145
        {       struct stat     st;
 
146
                fstat(0,&st);
 
147
        }
 
148
}end
 
149
 
 
150
hdr stat note{ stat() in default lib(s) }end link{
 
151
        #if _STD_
 
152
        #include        <stddef.h>
 
153
        #else
 
154
        #include        <sys/types.h>
 
155
        #endif
 
156
        #include        <time.h>
 
157
        #include        <stat.h>
 
158
        main()
 
159
        {       struct stat     st;
 
160
                fstat(0,&st);
 
161
        }
 
162
}end
 
163
 
 
164
#############################################################
 
165
# See if  memory mapping is available and fast enough to use
 
166
#############################################################
 
167
sys mman
 
168
 
 
169
tst     output{
 
170
        #include        <sys/types.h>
 
171
        #include        <sys/mman.h>
 
172
        #include        <sys/times.h>
 
173
        
 
174
        _BEGIN_EXTERNS_
 
175
        int creat _ARG_((char*, int));
 
176
        int open _ARG_((char*, int));
 
177
        int unlink _ARG_((char*));
 
178
        int read _ARG_((int, char*, int));
 
179
        _END_EXTERNS_
 
180
        
 
181
        #define MAPSIZE (64*1024)
 
182
        #define BUFSIZE (MAPSIZE/8)
 
183
        #define WRITE   (64)
 
184
        #define RUN     (64)
 
185
        
 
186
        #define Failed(file)    (unlink(file),1)
 
187
        
 
188
        #if _STD_
 
189
        main(int argc, char** argv)
 
190
        #else
 
191
        main(argc,argv)
 
192
        int     argc;
 
193
        char**  argv;
 
194
        #endif
 
195
        {
 
196
                caddr_t         mm;
 
197
                char            *t, *f;
 
198
                int             i, fd, k, run;
 
199
                char            file[1024], buf[MAPSIZE];
 
200
                struct tms      stm, etm;
 
201
                clock_t         rdtm, mmtm;
 
202
        
 
203
                /* create data file */
 
204
                f = argv[0]; t = file;
 
205
                while (*t = *f++)
 
206
                        t++;
 
207
                *t++ = '.'; *t++ = 'D'; *t = 0;
 
208
                if ((fd = creat(file,0666)) < 0)
 
209
                        return 1;
 
210
        
 
211
                for (i = 0; i < sizeof(buf); ++i)
 
212
                        buf[i] = '0' + (i%10);
 
213
                for (i = 0; i < WRITE; ++i)
 
214
                        if (write(fd,buf,sizeof(buf)) != sizeof(buf))
 
215
                                return Failed(file);
 
216
                close(fd);
 
217
        
 
218
                /* read time */
 
219
                times(&stm);
 
220
                for(run = 0; run < RUN; ++run)
 
221
                {       if((fd = open(file, 0)) < 0)
 
222
                                return Failed(file);
 
223
                        for (i = 0; i < WRITE; ++i)
 
224
                        {       for(k = 0; k < MAPSIZE; k += BUFSIZE)
 
225
                                        if (read(fd,buf,BUFSIZE) != BUFSIZE)
 
226
                                                return Failed(file);
 
227
                        }
 
228
                        close(fd);
 
229
                }
 
230
                times(&etm);
 
231
                rdtm = (etm.tms_utime-stm.tms_utime) + (etm.tms_stime-stm.tms_stime);
 
232
        
 
233
                /* mmap time */
 
234
                times(&stm);
 
235
                for(run = 0; run < RUN; ++run)
 
236
                {       if ((fd = open(file,0)) < 0)
 
237
                                return Failed(file);
 
238
                        for(i = 0, mm = (caddr_t)0; i < WRITE; ++i)
 
239
                        {       if(mm)
 
240
                                        munmap(mm, MAPSIZE);
 
241
                                mm = (caddr_t)mmap((caddr_t)0, MAPSIZE,
 
242
                                                   (PROT_READ|PROT_WRITE),
 
243
                                                   MAP_PRIVATE, fd, i*MAPSIZE );
 
244
                                if(mm == (caddr_t)(-1) || mm == (caddr_t)0)
 
245
                                        return Failed(file);
 
246
        
 
247
                                /* the memcpy is < BUFSIZE to simulate the
 
248
                                   fact that functions like sfreserve/sfgetr do
 
249
                                   not do buffer copying.
 
250
                                */
 
251
                                t = (char*)mm;
 
252
                                for(k = 0; k < MAPSIZE; k += BUFSIZE, t += BUFSIZE)
 
253
                                        memcpy(buf,t,(3*BUFSIZE)/4);
 
254
                        }
 
255
                        close(fd);
 
256
                }
 
257
                times(&etm);
 
258
                mmtm = (etm.tms_utime-stm.tms_utime) + (etm.tms_stime-stm.tms_stime);
 
259
 
 
260
                unlink(file);
 
261
        
 
262
                if(4*mmtm <= 3*rdtm)            /* mmap is great! */
 
263
                        printf("#define _mmap_worthy    2       \n");
 
264
                else if(4*mmtm <= 5*rdtm)       /* mmap is good */
 
265
                        printf("#define _mmap_worthy    1       \n");
 
266
        
 
267
                return 0;
 
268
        }
 
269
}end
 
270
 
 
271
##################################################
 
272
# vfork and any associated header files
 
273
##################################################
 
274
 
 
275
hdr vfork
 
276
sys vfork
 
277
lib vfork
 
278
 
 
279
##################################################
 
280
# file control checks
 
281
##################################################
 
282
 
 
283
hdr filio
 
284
sys filio
 
285
sys ioctl
 
286
lib remove
 
287
lib unlink
 
288
lib waitpid
 
289
lib getpagesize
 
290
 
 
291
tmp rmfail note{ file not removable if still opened }end execute{
 
292
        #include        <sys/time.h>
 
293
        _BEGIN_EXTERNS_
 
294
        extern int creat _ARG_((char*, int));
 
295
        extern int unlink _ARG_((char*));
 
296
        extern int write _ARG_((int, char*, int));
 
297
        _END_EXTERNS_
 
298
        main()
 
299
        {       int             fw, fr;
 
300
                char            file[128];
 
301
                sprintf(file,"/tmp/iffe%lu",(unsigned long)time(0));
 
302
                if((fw = creat(file,0666)) < 0)
 
303
                        return 0;
 
304
                if((fr = open(file,0)) < 0 )
 
305
                        return 0;
 
306
                if(unlink(file) < 0)
 
307
                        return 0;
 
308
                if(write(fw,"0123456789",11) != 11 )
 
309
                        return 0;
 
310
                if(read(fr,file,11) != 11)
 
311
                        return 0;
 
312
                if(strcmp(file,"0123456789") != 0)
 
313
                        return 0;
 
314
                return 1;
 
315
        }
 
316
}end
 
317
 
 
318
more void_int note{ voidptr is larger than int }end execute{
 
319
        main() {
 
320
        return sizeof(char*) > sizeof(int) ? 0 : 1;
 
321
        }
 
322
}end
 
323
 
 
324
more long_int note{ long is larger than int }end execute{
 
325
        main() {
 
326
        return sizeof(long) > sizeof(int) ? 0 : 1;
 
327
        }
 
328
}end
 
329
 
 
330
################################################################
 
331
# See if there is a preferred block size for a file system
 
332
################################################################
 
333
 
 
334
stat blksize note{ st_blksize is a field in struct stat }end compile{
 
335
        #include        <sys/types.h>
 
336
        #include        <sys/stat.h>
 
337
        main () {
 
338
                struct stat sb;
 
339
                sb.st_blksize = 0;
 
340
                return 0;
 
341
        }
 
342
}end
 
343
 
 
344
##################################################
 
345
# See if certain prototypes are required
 
346
##################################################
 
347
 
 
348
proto open note{ open() has a vararg prototype }end compile{
 
349
        #include        <sys/types.h>
 
350
        #include        <errno.h>
 
351
        #include        <ctype.h>
 
352
        #include        <fcntl.h>
 
353
 
 
354
        _BEGIN_EXTERNS_
 
355
        extern int open _ARG_((const char*,int,...));
 
356
        _END_EXTERNS_
 
357
        main()
 
358
        {
 
359
                open("file",0);
 
360
                open("file",0,1);
 
361
        }
 
362
}end
 
363
 
 
364
proto bcopy note{ bcopy() has prototype }end compile{
 
365
        #include        <string.h>
 
366
        main()
 
367
        {       char    buf[128];
 
368
                bcopy(buf, "abc", 3);
 
369
        }
 
370
}end
 
371
 
 
372
proto bzero note{ bzero() has prototype }end compile{
 
373
        #include        <string.h>
 
374
        main()
 
375
        {       char    buf[128];
 
376
                bzero(buf, 128);
 
377
        }
 
378
}end
 
379
 
 
380
lib     poll_fd_1 note{ fd is first arg to poll() }end execute{
 
381
        #include <poll.h>
 
382
        _BEGIN_EXTERNS_
 
383
        extern int      pipe _ARG_((int*));
 
384
        _END_EXTERNS_
 
385
        main()
 
386
        {       int             rw[2];
 
387
                struct pollfd   fd;
 
388
                if (pipe(rw) < 0) return 1;
 
389
                fd.fd = rw[0];
 
390
                fd.events = POLLIN;
 
391
                fd.revents = 0;
 
392
                return poll(&fd, 1, 0) < 0;
 
393
        }
 
394
}end
 
395
 
 
396
lib     poll_fd_2 note{ fd is second arg to poll() }end execute{
 
397
        #include <poll.h>
 
398
        _BEGIN_EXTERNS_
 
399
        extern int      pipe _ARG_((int*));
 
400
        _END_EXTERNS_
 
401
        main()
 
402
        {       int             rw[2];
 
403
                struct pollfd   fd;
 
404
                if (pipe(rw) < 0) return 1;
 
405
                fd.fd = rw[0];
 
406
                fd.events = POLLIN;
 
407
                fd.revents = 0;
 
408
                return poll(1, &fd, 0) < 0;
 
409
        }
 
410
}end
 
411
 
 
412
lib     select note{ select() has standard 5 arg interface }end link{
 
413
        #include <sys/types.h>
 
414
        #include <sys/time.h>
 
415
        #include <sys/socket.h>
 
416
        main()
 
417
        {       struct timeval  tmb;
 
418
                fd_set          rd;
 
419
                FD_ZERO(&rd);
 
420
                FD_SET(0,&rd);
 
421
                tmb.tv_sec = 0;
 
422
                tmb.tv_usec = 0;
 
423
                select(1,&rd,(fd_set*)0,(fd_set*)0,&tmb);
 
424
                return 0;
 
425
        }
 
426
}end
 
427
 
 
428
################################################################
 
429
## See if we can peek ahead in unseekable devices
 
430
################################################################
 
431
 
 
432
stream  peek note{ ioctl(I_PEEK) works }end link{
 
433
        #include <sys/types.h>
 
434
        #include <stropts.h>
 
435
        main()
 
436
        {       struct strpeek  pbuf;
 
437
                pbuf.flags = 0;
 
438
                pbuf.ctlbuf.maxlen = pbuf.databuf.maxlen =
 
439
                pbuf.ctlbuf.len = pbuf.databuf.len = 0;
 
440
                pbuf.ctlbuf.buf = pbuf.databuf.buf = 0;
 
441
                ioctl(0,I_PEEK,&pbuf);
 
442
                return 0;
 
443
        }
 
444
}end
 
445
 
 
446
socket  peek note{ recv(MSG_PEEK) works }end link{
 
447
        #include <sys/types.h>
 
448
        #include <sys/socket.h>
 
449
        main()
 
450
        {       char    buf[128];
 
451
                recv(0,buf,sizeof(buf),MSG_PEEK);
 
452
                return 0;
 
453
        }
 
454
}end
 
455
 
 
456
 
 
457
################################################################
 
458
## See if register layout is ok for vax string operations
 
459
################################################################
 
460
 
 
461
vax asm note{ register layout ok for vax string operations }end execute{
 
462
        main()
 
463
        {
 
464
        #ifndef vax
 
465
                return absurd = -1;
 
466
        #else
 
467
                register int    r11, r10, r9, r8, r7, r6;
 
468
                r11 = r10 = r9 = r8 = r7 = r6 = -1;
 
469
                asm("clrw       r11");
 
470
                asm("clrw       r10");
 
471
                asm("clrw       r9");
 
472
                asm("clrw       r8");
 
473
                asm("clrw       r7");
 
474
                asm("clrw       r6");
 
475
                if(sizeof(int) != sizeof(char*) || r11 || r10 || r9 || r8 || r7 || r6 )
 
476
                        return -1;
 
477
                return 0;
 
478
        #endif
 
479
        }
 
480
}end
 
481
 
 
482
lib strtod note{ native strtod exists }end
 
483
 
 
484
################################################################
 
485
## See if there is "locale" stuff for conditioning printf/scanf
 
486
################################################################
 
487
 
 
488
lib locale note{ Check for localeconv }end compile{
 
489
        #include        <locale.h>
 
490
        main()
 
491
        {       struct lconv* lv = localeconv();
 
492
                return 0;
 
493
        }
 
494
}end