1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
|
dnl Copyright (C) 1996, Memorial University of Newfoundland.
dnl This file is covered by the GNU General Public License, version 2, see
dnl the file misc/COPYING for details.
dnl
dnl This file is covered by the GPL 'cause it contains some modified versions
dnl of autoconf's macros, in particular:
dnl AC_FUNC_MMAP AC_LANG_C AC_LANG_CPLUXPLUS AC_TRY_RUN KSH_HEADER_SYS_WAIT
dnl AC_HEADER_STAT AC_PROG_CC
dnl
dnl
dnl Like AC_CHECK_TYPE(), only
dnl - user gets to specify header file(s) in addition to the default
dnl headers (<sys/types.h> and <stdlib.h>)
dnl - user gets to specify the message
dnl - word boundary checks are put at beginning/end of pattern
dnl (ie, \<pattern\>)
dnl - default argument is optional
dnl uses ac_cv_type_X 'cause this is used in other autoconf macros...
dnl KSH_CHECK_H_TYPE(type, message, header files, default)
AC_DEFUN(KSH_CHECK_H_TYPE,
[AC_CACHE_CHECK($2, ac_cv_type_$1,
[AC_EGREP_CPP([(^|[^a-zA-Z0-9_])]$1[([^a-zA-Z0-9_]|\$)],
[#include <sys/types.h>
#if STDC_HEADERS
#include <stdlib.h>
#endif
$3
], ac_cv_type_$1=yes, ac_cv_type_$1=no)])
ifelse($#, 4, [if test $ac_cv_type_$1 = no; then
AC_DEFINE($1, $4)
fi
])dnl
])dnl
dnl
dnl
dnl
dnl Check for memmove and if not found, check for bcopy. AC_CHECK_FUNCS()
dnl not used 'cause it confuses some compilers that have memmove/bcopy builtin;
dnl Also want to check if the function deals with overlapping src/dst properly.
AC_DEFUN(KSH_MEMMOVE,
[AC_CACHE_CHECK(for working memmove, ksh_cv_func_memmove,
[AC_TRY_RUN([
#ifdef HAVE_STRING_H
# include <string.h>
#else
# include <strings.h>
#endif
#ifdef HAVE_MEMORY_H
# include <memory.h>
#endif
int
main()
{
char buf[16];
strcpy(buf, "abcdefABCDEF");
memmove(buf + 4, buf, 6);
if (strcmp(buf, "abcdabcdefEF"))
exit(1);
memmove(buf, buf + 4, 6);
if (strcmp(buf, "abcdefcdefEF"))
exit(2);
exit(0);
return 0;
}],
ksh_cv_func_memmove=yes, ksh_cv_func_memmove=no,
AC_MSG_WARN(assuming memmove broken); ksh_cv_func_memmove=no)])
if test $ksh_cv_func_memmove = yes; then
AC_DEFINE(HAVE_MEMMOVE)
else
AC_CACHE_CHECK(for working bcopy, ksh_cv_func_bcopy,
[AC_TRY_RUN([
#ifdef HAVE_STRING_H
# include <string.h>
#else
# include <strings.h>
#endif
#ifdef HAVE_MEMORY_H
# include <memory.h>
#endif
int
main()
{
char buf[16];
strcpy(buf, "abcdefABCDEF");
bcopy(buf, buf + 4, 6);
if (strcmp(buf, "abcdabcdefEF"))
exit(1);
bcopy(buf + 4, buf, 6);
if (strcmp(buf, "abcdefcdefEF"))
exit(2);
exit(0);
}],
ksh_cv_func_bcopy=yes, ksh_cv_func_bcopy=no,
AC_MSG_WARN(assuming bcopy broken); ksh_cv_func_bcopy=no)])
if test $ksh_cv_func_bcopy = yes; then
AC_DEFINE(HAVE_BCOPY)
fi
fi
])dnl
dnl
dnl
dnl
dnl Check for sigsetjmp()/siglongjmp() and _setjmp()/_longjmp() pairs.
dnl Can't use simple library check as QNX 422 has _setjmp() but not _longjmp()
dnl (go figure).
AC_DEFUN(KSH_SETJMP,
[AC_CACHE_CHECK(for sigsetjmp()/siglongjmp(), ksh_cv_func_sigsetjmp,
[AC_TRY_LINK([], [sigsetjmp(); siglongjmp()],
ksh_cv_func_sigsetjmp=yes, ksh_cv_func_sigsetjmp=no)])
if test $ksh_cv_func_sigsetjmp = yes; then
AC_DEFINE(HAVE_SIGSETJMP)
else
AC_CACHE_CHECK(for _setjmp()/_longjmp(), ksh_cv_func__setjmp,
[AC_TRY_LINK([], [_setjmp(); _longjmp();],
ksh_cv_func__setjmp=yes, ksh_cv_func__setjmp=no)])
if test $ksh_cv_func__setjmp = yes; then
AC_DEFINE(HAVE__SETJMP)
fi
fi
])dnl
dnl
dnl
dnl
dnl Check for memset function. AC_CHECK_FUNCS() not used 'cause it confuses
dnl some compilers that have memset builtin.
AC_DEFUN(KSH_MEMSET,
[AC_CACHE_CHECK(for memset, ksh_cv_func_memset,
[AC_TRY_LINK([
#ifdef HAVE_STRING_H
# include <string.h>
#else
# include <strings.h>
#endif
#ifdef HAVE_MEMORY_H
# include <memory.h>
#endif
], [
char buf[16]; memset(buf, 'x', 7); printf("%7s", buf);],
ksh_cv_func_memset=yes, ksh_cv_func_memset=no)])
if test $ksh_cv_func_memset = yes; then
AC_DEFINE(HAVE_MEMSET)
fi
])dnl
dnl
dnl
dnl
dnl Check for rlim_t in a few places, and if not found, figure out the
dnl size rlim_t should be by looking at struct rlimit.rlim_cur.
AC_DEFUN(KSH_RLIM_CHECK,
[KSH_CHECK_H_TYPE(rlim_t, for rlim_t in <sys/types.h> and <sys/resource.h>,
[#ifdef HAVE_SYS_RESOURCE_H
#include <sys/resource.h>
#endif])dnl
if test $ac_cv_type_rlim_t = no; then
AC_MSG_CHECKING(what to set rlim_t to)
if test $ac_cv_header_sys_resource_h = yes; then
AC_CACHE_VAL(ksh_cv_rlim_check,
[AC_TRY_RUN([
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
main()
{
struct rlimit rl;
if (sizeof(rl.rlim_cur) == sizeof(quad_t))
exit(0);
exit(1);
}
], ksh_cv_rlim_check=quad_t, ksh_cv_rlim_check=long,
AC_MSG_ERROR(cannot determine type for rlimt_t when cross compiling)
)])dnl
else
ksh_cv_rlim_check=long
fi
AC_MSG_RESULT($ksh_cv_rlim_check)
AC_DEFINE_UNQUOTED(rlim_t, $ksh_cv_rlim_check)
fi
])dnl
dnl
dnl
dnl
AC_DEFUN(KSH_DEV_FD,
[AC_CACHE_CHECK(if you have /dev/fd/n, ksh_cv_dev_fd,
[AC_TRY_RUN([
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
main()
{
struct stat s1, s2;
FILE *fp1, *fp2;
char *file = "conftest.file";
char devfd[32];
if (!(fp1 = fopen(file, "w")))
exit(1);
if (fstat(fileno(fp1), &s1) < 0)
exit(2);
sprintf(devfd, "/dev/fd/%d", fileno(fp1));
if (!(fp2 = fopen(devfd, "w")))
exit(3);
if (fstat(fileno(fp2), &s2) < 0)
exit(4);
if (s1.st_dev != s2.st_dev || s1.st_ino != s2.st_ino)
exit(5);
exit(0);
}
], ksh_cv_dev_fd=yes, ksh_cv_dev_fd=no,
AC_MSG_WARN(cannot determine if you have /dev/fd support, assuming not)
ksh_cv_dev_fd=no)])
if test $ksh_cv_dev_fd = yes; then
AC_DEFINE(HAVE_DEV_FD)
fi
])dnl
dnl
dnl
dnl
dnl Check for sys_siglist[] declaration and existence.
AC_DEFUN(KSH_SYS_SIGLIST,
[AC_DECL_SYS_SIGLIST
if test ac_cv_decl_sys_siglist = yes; then
AC_DEFINE(HAVE_SYS_SIGLIST)
else
AC_CACHE_CHECK(for sys_siglist in library, ksh_cv_var_sys_siglist,
[AC_TRY_LINK(, [
extern char *sys_siglist[];
char *p = sys_siglist[2];
if (p)
return 12;
], ksh_cv_var_sys_siglist=yes, ksh_cv_var_sys_siglist=no)])
if test $ksh_cv_var_sys_siglist = yes; then
AC_DEFINE(HAVE_SYS_SIGLIST)
fi
fi
])dnl
dnl
dnl
dnl
dnl Check for sys_errlist[] declaration and existence.
AC_DEFUN(KSH_SYS_ERRLIST,
[AC_CACHE_CHECK(for sys_errlist declaration in errno.h, ksh_cv_decl_sys_errlist,
[AC_TRY_COMPILE([#include <errno.h>],
[char *msg = *(sys_errlist + 1); if (msg && *msg) return 12; ],
ksh_cv_decl_sys_errlist=yes, ksh_cv_decl_sys_errlist=no)])
if test $ksh_cv_decl_sys_errlist = yes; then
AC_DEFINE(SYS_ERRLIST_DECLARED)
AC_DEFINE(HAVE_SYS_ERRLIST)
else
AC_CACHE_CHECK(for sys_errlist in library, ksh_cv_var_sys_errlist,
[AC_TRY_LINK(, [
extern char *sys_errlist[];
extern int sys_nerr;
char *p;
p = sys_errlist[sys_nerr - 1];
if (p) return 12;
], ksh_cv_var_sys_errlist=yes, ksh_cv_var_sys_errlist=no)])
if test $ksh_cv_var_sys_errlist = yes; then
AC_DEFINE(HAVE_SYS_ERRLIST)
fi
fi
])dnl
dnl
dnl
dnl
dnl Check if time() declared in time.h
AC_DEFUN(KSH_TIME_DECLARED,
[AC_CACHE_CHECK(time() declaration in time.h, ksh_cv_time_delcared,
[AC_TRY_COMPILE([#include <sys/types.h>
#include <time.h>], [time_t (*f)() = time; if (f) return 12;],
ksh_cv_time_delcared=yes, ksh_cv_time_delcared=no)])
if test $ksh_cv_time_delcared = yes; then
AC_DEFINE(TIME_DECLARED)
fi
])dnl
dnl
dnl
dnl
dnl Check for working times (ie, it exists and doesn't always return 0).
dnl Defines TIMES_BROKEN if it doesn't exist or if it always returns 0
dnl (also checks for existance of getrusage if times doesn't work).
dnl XXX: requires clock_t to be typedefed/defined...
AC_DEFUN(KSH_TIMES_CHECK,
[AC_CACHE_CHECK(if times() is present/working, ksh_cv_func_times_ok,
[AC_TRY_RUN([
#include <sys/types.h>
#include <sys/times.h>
/* if missing, clock_t is defined to be INT32 */
#if SIZEOF_INT == 4
# define INT32 int
#else /* SIZEOF_INT */
# if SIZEOF_LONG == 4
# define INT32 long
# else /* SIZEOF_LONG */
#error cannot find 32 bit type...
# endif /* SIZEOF_LONG */
#endif /* SIZEOF_INT */
main()
{
extern clock_t times();
struct tms tms;
times(&tms);
sleep(1);
if (times(&tms) == 0)
exit(1);
exit(0);
}
], ksh_cv_func_times_ok=yes, ksh_cv_func_times_ok=no,
AC_MSG_ERROR(cannot determine if times works when cross compiling)
)])
if test $ksh_cv_func_times_ok = no; then
AC_DEFINE(TIMES_BROKEN)
AC_CHECK_FUNCS(getrusage)
fi
])dnl
dnl
dnl
dnl
AC_DEFUN(KSH_C_VOID,
[AC_CACHE_CHECK(if compiler understands void, ksh_cv_c_void,
[AC_TRY_COMPILE(
[
void foo() { }
/* Some compilers (old pcc ones) like "void *a;", but a can't be used */
void *bar(a) void *a; { int *b = (int *) a; *b = 1; return a; }
], , ksh_cv_c_void=yes, ksh_cv_c_void=no)])
if test $ksh_cv_c_void = yes; then
:
else
AC_DEFINE(void, char)
fi
])dnl
dnl
dnl
dnl
dnl Early MIPS compilers (used in Ultrix 4.2) don't like
dnl "int x; int *volatile a = &x; *a = 0;"
AC_DEFUN(KSH_C_VOLATILE,
[AC_CACHE_CHECK(if compiler understands volatile, ksh_cv_c_volatile,
[AC_TRY_COMPILE([int x, y, z;],
[volatile int a; int * volatile b = x ? &y : &z;
/* Older MIPS compilers (eg., in Ultrix 4.2) don't like *b = 0 */
*b = 0;], ksh_cv_c_volatile=yes, ksh_cv_c_volatile=no)])
if test $ksh_cv_c_volatile = yes; then
:
else
AC_DEFINE(volatile, )
fi
])dnl
dnl
dnl
dnl
dnl Check if function prototypes work (including stdc vararg prototypes)
AC_DEFUN(KSH_C_PROTOTYPES,
[AC_CACHE_CHECK(if compiler understands prototypes, ksh_cv_c_prototypes,
[AC_TRY_COMPILE([
#include <stdarg.h>
void foo(char *fmt, ...);
int bar(int a, char b, char *c);
int bar(a, b, c) int a; char b; char *c;
{ foo("%d%c%s\n", a, b, c); return a + b + *c; }
void foo(char *fmt, ...) { va_list a; va_start(a, fmt); va_end(a); }
], , ksh_cv_c_prototypes=yes, ksh_cv_c_prototypes=no)])
if test $ksh_cv_c_prototypes = yes; then
AC_DEFINE(HAVE_PROTOTYPES)
fi
])dnl
dnl
dnl
dnl
dnl Check if C compiler understands gcc's __attribute((...)).
dnl checks for noreturn, const, and format(type,fmt,param), also checks
dnl that the compiler doesn't die when it sees an unknown attribute (this
dnl isn't perfect since gcc doesn't parse unknown attributes with parameters)
AC_DEFUN(KSH_C_FUNC_ATTR,
[AC_CACHE_CHECK(if C compiler groks __attribute__(( .. )), ksh_cv_c_func_attr,
[AC_TRY_COMPILE([
#include <stdarg.h>
void test_fmt(char *fmt, ...) __attribute__((format(printf, 1, 2)));
void test_fmt(char *fmt, ...) { return; }
int test_cnst(int) __attribute__((const));
int test_cnst(int x) { return x + 1; }
void test_nr() __attribute__((noreturn));
void test_nr() { exit(1); }
void test_uk() __attribute__((blah));
void test_uk() { return; }
], [test_nr("%d", 10); test_cnst(2); test_uk(); test_nr(); ],
ksh_cv_c_func_attr=yes, ksh_cv_c_func_attr=no)])
if test $ksh_cv_c_func_attr = yes; then
AC_DEFINE(HAVE_GCC_FUNC_ATTR)
fi
])dnl
dnl
dnl
dnl
dnl Check if dup2() does not clear the close on exec flag
AC_DEFUN(KSH_DUP2_CLEXEC_CHECK,
[AC_CACHE_CHECK([if dup2() works (ie, resets the close-on-exec flag)], ksh_cv_dup2_clexec_ok,
[AC_TRY_RUN([
#include <sys/types.h>
#ifdef HAVE_FCNTL_H
# include <fcntl.h>
#endif /* HAVE_FCNTL_H */
#ifndef F_GETFD
# define F_GETFD 1
#endif
#ifndef F_SETFD
# define F_SETFD 2
#endif
#ifndef O_RDONLY
# define O_RDONLY 0
#endif
/* On some systems (Ultrix 2.1..4.2 (and more?)), dup2() does not clear
the close on exec flag */
main()
{
int fd1, fd2;
fd1 = open("/dev/null", O_RDONLY);
if (fcntl(fd1, F_SETFD, 1) < 0)
exit(1);
fd2 = dup2(fd1, fd1 + 1);
if (fd2 < 0)
exit(2);
exit(fcntl(fd2, F_GETFD, 0) == 0 ? 0 : 3);
}
], ksh_cv_dup2_clexec_ok=yes, ksh_cv_dup2_clexec_ok=no,
AC_MSG_WARN(cannot test if dup2 is broken when cross compiling - assuming it is)
ksh_cv_dup2_clexec_ok=no)])
if test $ksh_cv_dup2_clexec_ok = no; then
AC_DEFINE(DUP2_BROKEN)
fi
])dnl
dnl
dnl
dnl
dnl Check type of signal routines (posix, 4.2bsd, 4.1bsd or v7)
AC_DEFUN(KSH_SIGNAL_CHECK,
[AC_CACHE_CHECK(flavour of signal routines, ksh_cv_signal_check,
[AC_TRY_LINK([#include <signal.h>], [
sigset_t ss;
struct sigaction sa;
sigemptyset(&ss); sigsuspend(&ss);
sigaction(SIGINT, &sa, (struct sigaction *) 0);
sigprocmask(SIG_BLOCK, &ss, (sigset_t *) 0);
], ksh_cv_signal_check=posix,
AC_TRY_LINK([#include <signal.h>], [
int mask = sigmask(SIGINT);
sigsetmask(mask); sigblock(mask); sigpause(mask);
], ksh_cv_signal_check=bsd42,
AC_TRY_LINK([#include <signal.h>
RETSIGTYPE foo() { }],
[
int mask = sigmask(SIGINT);
sigset(SIGINT, foo); sigrelse(SIGINT);
sighold(SIGINT); sigpause(SIGINT);
], ksh_cv_signal_check=bsd41, ksh_cv_signal_check=v7)))])
if test $ksh_cv_signal_check = posix; then
AC_DEFINE(POSIX_SIGNALS)
else
AC_DEFINE(USE_FAKE_SIGACT)
if test $ksh_cv_signal_check = bsd42; then
AC_DEFINE(BSD42_SIGNALS)
elif test $ksh_cv_signal_check = bsd41; then
AC_DEFINE(BSD41_SIGNALS)
AC_CACHE_CHECK(if signals interrupt read(), ksh_cv_signals_interrupt,
[AC_TRY_RUN([
#include <errno.h>
#include <signal.h>
extern int errno;
int flag = 0;
RETSIGTYPE
catcher(int sig)
{
flag = 1;
return RETSIGVAL;
}
int
main()
{
int pid;
int fdc[2]; /* child writes to parent */
int fdp[2]; /* parent writes to child */
char buf;
int nread;
if (pipe(fdc) < 0)
exit(1);
if (pipe(fdp) < 0)
exit(2);
if ((pid = fork()) < 0)
exit(3);
if (pid == 0) {
close(fdc[0]);
close(fdp[1]);
if (read(fdp[0], &buf, 1) != 0)
exit(10);
sleep(1); /* let parent into read */
if (kill(getppid(), SIGALRM) < 0)
exit(11);
sleep(1); /* ensure parent gets to run */
write(fdc[1], "1", 1);
close(fdc[1]);
exit(0);
}
close(fdc[1]);
close(fdp[0]);
/* Use native routines for test as this is what the shell
* will be using...
*/
#ifdef POSIX_SIGNALS
{
struct sigaction sa, osa;
sa.sa_handler = catcher;
sigemptyset(&sa.sa_mask);
sa.sa_flags = 0;
sigaction(SIGALRM, &sa, &osa);
}
#else /* POSIX_SIGNALS */
# ifdef BSD42_SIGNALS
{
struct sigvec vec, ovec;
vec.sv_handler = catcher;
vec.sv_mask = 0;
vec.sv_flags = 0;
# ifdef SV_INTERRUPT
vec.sv_flags |= SV_INTERRUPT;
# endif /* SV_INTERRUPT */
sigvec(SIGALRM, &vec, &ovec);
}
# else /* BSD42_SIGNALS */
# ifdef BSD41_SIGNALS
sigset(SIGALRM, catcher);
# else /* BSD41_SIGNALS */
# ifdef V7_SIGNALS
signal(SIGALRM, catcher);
# else /* V7_SIGNALS */
what kind of signals do you have?
# endif /* V7_SIGNALS */
# endif /* BSD41_SIGNALS */
# endif /* BSD42_SIGNALS */
#endif /* POSIX_SIGNALS */
close(fdp[1]); /* start child */
nread = read(fdc[0], &buf, 1);
if (nread == 0)
exit(4);
if (nread > 0)
exit(5);
if (errno != EINTR)
exit(6);
if (!flag)
exit(7);
exit(0);
return 0;
}
], ksh_cv_signals_interrupt=yes, ksh_cv_signals_interrupt=no,
AC_MSG_ERROR(cannot determine if signals interrupt read() when cross compiling)
)])
if test $ksh_cv_signals_interrupt = no ; then
AC_DEFINE(SIGNALS_DONT_INTERRUPT)
fi
else
AC_DEFINE(V7_SIGNALS)
fi
fi
])dnl
dnl
dnl
dnl
dnl What kind of process groups: POSIX, BSD, SYSV or none
dnl BSD uses setpgrp(pid, pgrp), getpgrp(pid)
dnl POSIX uses setpid(pid, pgrp), getpgrp(void)
dnl SYSV uses setpgrp(void), getpgrp(void)
dnl Checks for BSD first since the posix test may succeed on BSDish systems
dnl (depends on what random value gets passed to getpgrp()).
AC_DEFUN(KSH_PGRP_CHECK,
[AC_CACHE_CHECK(flavour of pgrp routines, ksh_cv_pgrp_check,
[AC_TRY_RUN([
/* Check for BSD process groups */
#include <signal.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif /* HAVE_UNISTD_H */
main()
{
int ecode = 0, child = fork();
if (child < 0)
exit(1);
if (child == 0) {
signal(SIGTERM, SIG_DFL); /* just to make sure */
sleep(10);
exit(9);
}
if (setpgrp(child, child) < 0)
ecode = 2;
else if (getpgrp(child) != child)
ecode = 3;
kill(child, SIGTERM);
exit(ecode);
}
], ksh_cv_pgrp_check=bsd,
[AC_TRY_RUN([
/* Check for POSIX process groups */
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif /* HAVE_UNISTD_H */
main()
{
int child;
int n, p1[2], p2[2];
char buf[1];
if (pipe(p1) < 0 || pipe(p2) < 0)
exit(1);
if ((child = fork()) < 0)
exit(2);
if (child == 0) {
n = read(p1[0], buf, sizeof(buf)); /* wait for parent to setpgid */
buf[0] = (n != 1 ? 10 : (getpgrp() != getpid() ? 11 : 0));
if (write(p2[1], buf, sizeof(buf)) != 1)
exit(12);
exit(0);
}
if (setpgid(child, child) < 0)
exit(3);
if (write(p1[1], buf, 1) != 1)
exit(4);
if (read(p2[0], buf, 1) != 1)
exit(5);
exit((int) buf[0]);
}
], ksh_cv_pgrp_check=posix,
[AC_TRY_RUN([
/* Check for SYSV process groups */
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif /* HAVE_UNISTD_H */
main()
{
int child;
int n, p[2];
char buf[1];
if (pipe(p) < 0)
exit(1);
if ((child = fork()) < 0)
exit(2);
if (child == 0) {
buf[0] = (setpgrp() < 0 ? 10 : (getpgrp() != getpid() ? 11 : 0));
if (write(p[1], buf, sizeof(buf)) != 1)
exit(11);
exit(0);
}
if (read(p[0], buf, 1) != 1)
exit(3);
exit((int) buf[0]);
}
], ksh_cv_pgrp_check=sysv, ksh_cv_pgrp_check=none,
AC_MSG_ERROR(cannot taste pgrp routines when cross compiling))],
AC_MSG_ERROR(cannot taste pgrp routines when cross compiling))],
AC_MSG_ERROR(cannot taste pgrp routines when cross compiling))])
if test $ksh_cv_pgrp_check = bsd; then
AC_DEFINE(BSD_PGRP)
elif test $ksh_cv_pgrp_check = posix; then
AC_DEFINE(POSIX_PGRP)
elif test $ksh_cv_pgrp_check = sysv; then
AC_DEFINE(SYSV_PGRP)
else
AC_DEFINE(NO_PGRP)
fi
])dnl
dnl
dnl
dnl
dnl Check if the pgrp of setpgrp() can't be the pid of a zombie process.
dnl On some systems, the kernel doesn't count zombie processes when checking
dnl if a process group is valid, which can cause problems in creating the
dnl pipeline "cmd1 | cmd2": if cmd1 can die (and go into the zombie state)
dnl before cmd2 is started, the kernel doesn't allow the setpgrp() for cmd2
dnl to succeed. This test defines NEED_PGRP_SYNC if the kernel has this bug.
dnl (pgrp_sync test doesn't mean much if don't have bsd or posix pgrps)
AC_DEFUN(KSH_PGRP_SYNC,
[AC_REQUIRE([KSH_PGRP_CHECK])dnl
if test $ksh_cv_pgrp_check = bsd || test $ksh_cv_pgrp_check = posix ; then
AC_CACHE_CHECK(if process group synchronization is required, ksh_cv_need_pgrp_sync,
[AC_TRY_RUN([
main()
{
#ifdef POSIX_PGRP
# define getpgID() getpgrp()
#else
# define getpgID() getpgrp(0)
# define setpgid(x,y) setpgrp(x,y)
#endif
int pid1, pid2, fds[2];
int status;
char ok;
switch (pid1 = fork()) {
case -1:
exit(1);
case 0:
setpgid(0, getpid());
exit(0);
}
setpgid(pid1, pid1);
sleep(2); /* let first child die */
if (pipe(fds) < 0)
exit(2);
switch (pid2 = fork()) {
case -1:
exit(3);
case 0:
setpgid(0, pid1);
ok = getpgID() == pid1;
write(fds[1], &ok, 1);
exit(0);
}
setpgid(pid2, pid1);
close(fds[1]);
if (read(fds[0], &ok, 1) != 1)
exit(4);
wait(&status);
wait(&status);
exit(ok ? 0 : 5);
}
], ksh_cv_need_pgrp_sync=no, ksh_cv_need_pgrp_sync=yes,
AC_MSG_WARN(cannot test if pgrp synchronization needed when cross compiling - assuming it is)
ksh_cv_need_pgrp_sync=yes)])
if test $ksh_cv_need_pgrp_sync = yes; then
AC_DEFINE(NEED_PGRP_SYNC)
fi
fi
])dnl
dnl
dnl
dnl
dnl Check to see if opendir will open non-directories (not a nice thing)
AC_DEFUN(KSH_OPENDIR_CHECK,
[AC_CACHE_CHECK(if opendir() fails to open non-directories, ksh_cv_opendir_ok,
[AC_TRY_RUN([
#include <stdio.h>
#include <sys/types.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif /* HAVE_UNISTD_H */
#if defined(HAVE_DIRENT_H)
# include <dirent.h>
#else
# define dirent direct
# ifdef SYSNDIR
# include <sys/ndir.h>
# endif /* SYSNDIR */
# ifdef SYSDIR
# include <sys/dir.h>
# endif /* SYSDIR */
# ifdef NDIR
# include <ndir.h>
# endif /* NDIR */
#endif /* DIRENT */
main()
{
int i, ret = 0;
FILE *fp;
char *fname = "conftestod", buf[256];
for (i = 0; i < sizeof(buf); i++) /* memset(buf, 0, sizeof(buf)) */
buf[i] = 0;
unlink(fname); /* paranoia */
i = ((fp = fopen(fname, "w")) == (FILE *) 0 && (ret = 1))
|| (fwrite(buf, sizeof(buf), 1, fp) != 1 && (ret = 2))
|| (fclose(fp) == EOF && (ret = 3))
|| (opendir(fname) && (ret = 4))
|| (opendir("/dev/null") && (ret = 5));
unlink(fname);
exit(ret);
}
], ksh_cv_opendir_ok=yes, ksh_cv_opendir_ok=no,
AC_MSG_WARN(cannot test if opendir opens non-directories when cross compiling - assuming it does)
ksh_cv_opendir_ok=no)])
if test $ksh_cv_opendir_ok = no; then
AC_DEFINE(OPENDIR_DOES_NONDIR)
fi
])dnl
dnl
dnl
dnl
dnl Like AC_HAVE_HEADER(unistd.h) but only defines HAVE_UNISTD_H if
dnl the header file is sane (MIPS RISC/os 5.0 (and later?) has a unistd.h
dnl in the bsd43 environ that is incorrect - it defines POSIX_VERSION even
dnl though its non-posix).
AC_DEFUN(KSH_UNISTD_H,
[AC_CACHE_CHECK(for sane unistd.h, ksh_cv_header_unistd,
[AC_TRY_COMPILE([
#include <unistd.h>
#if defined(_POSIX_VERSION)
# include <sys/types.h>
# include <dirent.h> /* _POSIX_VERSION => HAVE_DIRENT_H test not needed */
#endif
], , ksh_cv_header_unistd=yes, ksh_cv_header_unistd=no)])
if test $ksh_cv_header_unistd = yes; then
AC_DEFINE(HAVE_UNISTD_H)
fi
])dnl
dnl
dnl
dnl
dnl Several OSes need to be detected and symbols defined so the shell can
dnl deal with them. This is a bit kludgy, but...
dnl Currently tests for:
dnl AIX, ISC (Interactive systems corp), MINIX, OS2 using EMX library,
dnl SCO (santa cruz operation), NEXT
dnl DO NOT USE with AC_AIX, AC_MINIX or AC_ISC_POSIX tests as these are
dnl incorperated in this test.
AC_DEFUN(KSH_OS_TYPE,
[AC_BEFORE([$0], [AC_TRY_COMPILE])dnl
AC_BEFORE([$0], [AC_TRY_LINK])dnl
AC_BEFORE([$0], [AC_TRY_RUN])dnl
AC_CACHE_CHECK(if this is a problematic os, ksh_cv_os_type,
[ ksh_cv_os_type=no
# Some tests below add -C to CPPFLAGS
saveCPPFLAGS="$CPPFLAGS"
for i in AIX ISC MINIX SCO OS2_EMX TITANOS NEXT HPUX; do
case $i in #((
AIX)
AC_EGREP_CPP(yes,
[
#ifdef _AIX
yes
#endif
], ksh_cv_os_type=$i)
;; #(
ISC)
# Both native ISC cpp and gcc understand this (leave comments in)
CPPFLAGS="$CPPFLAGS -C"
#XXX grep part won't work if cross-compiling...
AC_EGREP_CPP(INTERACTIVE Systems Corporation,
[#include <unistd.h>],
[if grep _POSIX_VERSION /usr/include/sys/unistd.h > /dev/null 2>&1; then
ksh_cv_os_type="$i-posix"
else
ksh_cv_os_type=$i
fi])dnl
CPPFLAGS="$saveCPPFLAGS"
;; #(
MINIX)
AC_CHECK_HEADER(minix/config.h, ksh_cv_os_type=$i)dnl
;; #(
SCO)
# Both native SCO cpp and gcc understand this (leave comments in)
CPPFLAGS="$CPPFLAGS -C"
AC_EGREP_CPP(The Santa Cruz Operation,
[#include <unistd.h>], ksh_cv_os_type=$i)dnl
CPPFLAGS="$saveCPPFLAGS"
;; #(
OS2_EMX)
AC_EGREP_CPP(yes,
[
#ifdef __EMX__
yes
#endif
], ksh_cv_os_type=$i)dnl
;; #(
TITANOS)
AC_EGREP_CPP(YesTitan,
[
#if defined(titan) || defined(_titan) || defined(__titan)
YesTitan
#endif
], ksh_cv_os_type=$i)dnl
;; #(
NEXT)
#
# NeXT 3.2 (other versions?) - cc -E doesn't work and /lib/cpp
# doesn't define things that need defining, so tests that rely
# on $CPP will break.
#
# Hmmm - can't safely use CPP to test for NeXT defines, so have
# to use a program that won't compile on a NeXT and one that will
# only compile on a NeXT...
AC_TRY_COMPILE([], [
#if defined(__NeXT) || defined(NeXT)
this is a NeXT box and the compile should fail
#endif
], , AC_TRY_COMPILE([], [
#if !defined(__NeXT) && !defined(NeXT)
this is NOT a NeXT box and the compile should fail
#endif
], ksh_cv_os_type=$i))dnl
;; #(
HPUX)
AC_EGREP_CPP(yes,
[
#ifdef __hpux
yes
#endif
], ksh_cv_os_type=$i)
;; #(
esac #))
test $ksh_cv_os_type != no && break
done
])
case $ksh_cv_os_type in #((
AIX)
AC_DEFINE(_ALL_SOURCE)dnl
;; #(
ISC)
AC_DEFINE(OS_ISC)dnl
;; #(
ISC-posix)
AC_DEFINE(OS_ISC)dnl
AC_DEFINE(_POSIX_SOURCE)dnl
if test "$GCC" = yes; then
CC="$CC -posix"
else
CC="$CC -Xp"
fi
;; #(
MINIX)
AC_DEFINE(_POSIX_SOURCE)dnl
AC_DEFINE(_POSIX_1_SOURCE, 2)dnl
AC_DEFINE(_MINIX)dnl
;; #(
SCO)
AC_DEFINE(OS_SCO)dnl
;; #(
OS2_EMX)
# XXX change this to OS_OS2 or OS_OS2_EMX?
AC_DEFINE(OS2)dnl
ac_exe_suffix=.exe
;; #(
TITANOS)
# Need to use cc -43 to get a shell with job control
case "$CC" in #((
*-43*) # Already have -43 option?
;; #(
*/cc|*/cc' '|*/cc' '|cc|cc' '|cc' ') # Using stock compiler?
CC="$CC -43"
;; #(
esac #))
#
# Force dirent check to find the right thing. There is a dirent.h
# (and a sys/dirent.h) file which compiles, but generates garbage...
#
ac_cv_header_dirent_dirent_h=no
ac_cv_header_dirent_sys_ndir_h=no
ac_cv_header_dirent_sys_dir_h=yes
;; #(
NEXT)
#
# NeXT 3.2 (other versions?) - cc -E doesn't work and /lib/cpp
# doesn't define things that need defining, so tests that rely
# on $CPP will break.
#
AC_EGREP_CPP([Bad NeXT], [#include <signal.h>
#if !defined(SIGINT) || !defined(SIGQUIT)
Bad NeXT
#endif
], AC_MSG_ERROR([
There is a problem on NeXT boxes resulting in a bad siglist.out file being
generated (which breaks the trap and kill commands) and probably resulting
in many configuration tests not working correctly.
You appear to have this problem - see the comments on NeXT in the pdksh
README file for work arounds.]))dnl
;; #(
HPUX)
#
# In some versions of hpux (eg, 10.2), getwd & getcwd will dump core
# if directory is not readble.
#
# name is used in test program
AC_CACHE_CHECK(for bug in getwd, ksh_cv_hpux_getwd_bug,
[ tmpdir=conftest.dir
if mkdir $tmpdir ; then
AC_TRY_RUN([
int
main()
{
char buf[8 * 1024];
char *dirname = "conftest.dir";
int ok = 0;
if (chdir(dirname) < 0)
exit(2);
if (chmod(".", 0) < 0)
exit(3);
/* Test won't work if run as root - so don't be root */
if (getuid() == 0 || geteuid() == 0)
setresuid(1, 1, 1); /* hpux has this */
#ifdef HAVE_GETWD /* silly since HAVE_* tests haven't been done yet */
{
extern char *getwd();
ok = getwd(buf) == 0;
}
#else
{
extern char *getcwd();
ok = getcwd(buf, sizeof(buf)) == 0;
}
#endif
exit(ok ? 0 : 10);
return ok ? 0 : 10;
}],
ksh_cv_hpux_getwd_bug=no, ksh_cv_hpux_getwd_bug=yes,
AC_MSG_WARN(assuming getwd broken); ksh_cv_hpux_getwd_bug=yes)
test -d $tmpdir && rmdir $tmpdir
else
AC_MSG_ERROR(could not make temp directory for test); ksh_cv_hpux_getwd_bug=yes
fi])
if test $ksh_cv_hpux_getwd_bug = yes; then
AC_DEFINE(HPUX_GETWD_BUG)
fi
;; #(
esac #))
])dnl
dnl
dnl
dnl
dnl Some systems (eg, SunOS 4.0.3) have <termios.h> and <termio.h> but don't
dnl have the related functions/defines (eg, tcsetattr(), TCSADRAIN, etc.)
dnl or the functions don't work well with tty process groups. Sun's bad
dnl termios can be detected by the lack of tcsetattr(), but its bad termio
dnl is harder to detect - so check for (sane) termios first, then check for
dnl BSD, then termio.
AC_DEFUN(KSH_TERM_CHECK,
[AC_CACHE_CHECK(terminal interface, ksh_cv_term_check,
[AC_TRY_LINK([#include <termios.h>], [
struct termios t;
#if defined(ultrix) || defined(__ultrix__)
Termios in ultrix 4.2 botches type-ahead when going from cooked to
cbreak mode. The BSD tty interface works fine though, so use it
(would be good to know if alter versions of ultrix work).
#endif /* ultrix */
tcgetattr(0, &t); tcsetattr(0, TCSADRAIN, &t);
], ksh_cv_term_check=termios,
[AC_TRY_LINK([#include <sys/ioctl.h>], [
struct sgttyb sb; ioctl(0, TIOCGETP, &sb);
#ifdef TIOCGATC
{ struct ttychars lc; ioctl(0, TIOCGATC, &lc); }
#else /* TIOCGATC */
{ struct tchars tc; ioctl(0, TIOCGETC, &tc); }
# ifdef TIOCGLTC
{ struct ltchars ltc; ioctl(0, TIOCGLTC, <c); }
# endif /* TIOCGLTC */
#endif /* TIOCGATC */
], ksh_cv_term_check=bsd,
[AC_CHECK_HEADER(termio.h, ksh_cv_term_check=termio,
ksh_cv_term_check=sgtty)])])])
if test $ksh_cv_term_check = termios; then
AC_DEFINE(HAVE_TERMIOS_H)
dnl Don't know of a system on which this fails...
dnl AC_CACHE_CHECK(sys/ioctl.h can be included with termios.h,
dnl ksh_cv_sys_ioctl_with_termios,
dnl [AC_TRY_COMPILE([#include <termios.h>
dnl #include <sys/ioctl.h>], , ksh_cv_sys_ioctl_with_termios=yes,
dnl ksh_cv_sys_ioctl_with_termios=no)])
dnl if test $ksh_cv_sys_ioctl_with_termios = yes; then
dnl AC_DEFINE(SYS_IOCTL_WITH_TERMIOS)
dnl fi
elif test $ksh_cv_term_check = termio; then
AC_DEFINE(HAVE_TERMIO_H)
dnl Don't know of a system on which this fails...
dnl AC_CACHE_CHECK(sys/ioctl.h can be included with termio.h,
dnl ksh_cv_sys_ioctl_with_termio,
dnl [AC_TRY_COMPILE([#include <termio.h>
dnl #include <sys/ioctl.h>], , ksh_cv_sys_ioctl_with_termio=yes,
dnl ksh_cv_sys_ioctl_with_termio=no)])
dnl if test $ksh_cv_sys_ioctl_with_termio = yes; then
dnl AC_DEFINE(SYS_IOCTL_WITH_TERMIO)
dnl fi
fi
])dnl
dnl
dnl
dnl
dnl Check if lstat() is available - special test needed 'cause lstat only
dnl becomes visable if <sys/stat.h> is included (linux 1.3.x)...
AC_DEFUN(KSH_FUNC_LSTAT,
[AC_CACHE_CHECK(for lstat, ksh_cv_func_lstat,
[AC_TRY_LINK([
#include <sys/types.h>
#include <sys/stat.h>
], [
struct stat statb;
lstat("/", &statb);
],
ksh_cv_func_lstat=yes, ksh_cv_func_lstat=no)])
if test $ksh_cv_func_lstat = yes; then
AC_DEFINE(HAVE_LSTAT)
fi
])
dnl
dnl
dnl
dnl Modified test from autoconf's acspecific.m4: MMAP test needs to check
dnl for/use the MAP_FILE flag. (Needed for older NetBSD systems).
undefine([AC_FUNC_MMAP])dnl
AC_DEFUN(AC_FUNC_MMAP,
[AC_CHECK_FUNCS(valloc getpagesize)
AC_CACHE_CHECK(for working mmap, ac_cv_func_mmap,
[AC_TRY_RUN([
/* Thanks to Mike Haertel and Jim Avera for this test. */
#include <sys/types.h>
#include <fcntl.h>
#include <sys/mman.h>
#ifndef HAVE_GETPAGESIZE
# include <sys/param.h>
# ifdef EXEC_PAGESIZE
# define getpagesize() EXEC_PAGESIZE
# else
# ifdef NBPG
# define getpagesize() NBPG * CLSIZE
# ifndef CLSIZE
# define CLSIZE 1
# endif
# else
# ifdef NBPC
# define getpagesize() NBPC
# else
# define getpagesize() PAGESIZE /* SVR4 */
# endif
# endif
# endif
#endif
#ifndef HAVE_VALLOC
# define valloc malloc
#endif
#ifdef __cplusplus
extern "C" { void *valloc(unsigned), *malloc(unsigned); }
#else
char *valloc(), *malloc();
#endif
#ifndef MAP_FILE
# define MAP_FILE 0
#endif /* MAP_FILE */
int
main()
{
char *buf1, *buf2, *buf3;
int i = getpagesize(), j;
int i2 = i * 2;
int fd;
buf1 = (char *)valloc(i2);
buf2 = (char *)valloc(i);
buf3 = (char *)malloc(i2);
for (j = 0; j < i2; ++j)
*(buf1 + j) = rand();
fd = open("conftestmmap", O_CREAT | O_RDWR, 0666);
write(fd, buf1, i2);
mmap(buf2, i, PROT_READ | PROT_WRITE, MAP_FILE | MAP_FIXED | MAP_PRIVATE, fd, 0);
for (j = 0; j < i; ++j)
if (*(buf1 + j) != *(buf2 + j))
exit(1);
lseek(fd, (long)i, 0);
read(fd, buf2, i); /* read into mapped memory -- file should not change */
/* (it does in i386 SVR4.0 - Jim Avera, jima@netcom.com) */
lseek(fd, (long)0, 0);
read(fd, buf3, i2);
for (j = 0; j < i2; ++j)
if (*(buf1 + j) != *(buf3 + j))
exit(1);
exit(0);
}
], ac_cv_func_mmap=yes, ac_cv_func_mmap=no, ac_cv_func_mmap=no)])
if test $ac_cv_func_mmap = yes; then
AC_DEFINE(HAVE_MMAP)
fi
])
dnl
dnl
dnl
dnl Modified AC_LANG_C, AC_LANG_CPLUSPLUS, AC_TRY_RUN to handle executable
dnl extensions.
undefine([AC_LANG_C])dnl
undefine([AC_LANG_CPLUXPLUS])dnl
undefine([AC_TRY_RUN])dnl
dnl AC_LANG_C()
AC_DEFUN(AC_LANG_C,
[define([AC_LANG], [C])dnl
ac_ext=c
# CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
ac_cpp='echo $CPP $CPPFLAGS 1>&AC_FD_CC;
$CPP $CPPFLAGS'
ac_compile='echo ${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&AC_FD_CC;
${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&AC_FD_CC 2>&AC_FD_CC'
ac_link='echo ${CC-cc} -o conftest$ac_exe_suffix $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&AC_FD_CC;
${CC-cc} -o conftest$ac_exe_suffix $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&AC_FD_CC 2>&AC_FD_CC'
])
dnl AC_LANG_CPLUSPLUS()
AC_DEFUN(AC_LANG_CPLUSPLUS,
[define([AC_LANG], [CPLUSPLUS])dnl
ac_ext=C
# CXXFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
ac_cpp='echo $CXXCPP $CPPFLAGS 1>&AC_FD_CC;
$CXXCPP $CPPFLAGS'
ac_compile='echo ${CXX-g++} -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext 1>&AC_FD_CC;
${CXX-g++} -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext 1>&AC_FD_CC 2>&AC_FD_CC'
ac_link='echo ${CXX-g++} -o conftest$ac_exe_suffix $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&AC_FD_CC;
${CXX-g++} -o conftest$ac_exe_suffix $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&AC_FD_CC 2>&AC_FD_CC'
])
dnl AC_TRY_RUN(PROGRAM, [ACTION-IF-TRUE [, ACTION-IF-FALSE
dnl [, ACTION-IF-CROSS-COMPILING]]])
AC_DEFUN(AC_TRY_RUN,
[AC_REQUIRE([AC_PROG_CC])dnl
if test "$cross_compiling" = yes; then
ifelse([$4], ,
[errprint(__file__:__line__: warning: [AC_TRY_RUN] called without default to allow cross compiling
)dnl
AC_MSG_ERROR(can not run test program while cross compiling)],
[$4])
else
cat > conftest.$ac_ext <<EOF
[#]line __oline__ "configure"
#include "confdefs.h"
ifelse(AC_LANG, CPLUSPLUS, [#ifdef __cplusplus
extern "C" void exit(int);
#endif
])dnl
[$1]
EOF
eval $ac_link
if test -s conftest$ac_exe_suffix && (./conftest; exit) 2>/dev/null; then
ifelse([$2], , :, [$2])
ifelse([$3], , , [else
$3
])dnl
fi
fi
rm -fr conftest*])
dnl
dnl
dnl Like AC_HEADER_SYS_WAIT, only HAVE_SYS_WAIT_H if sys/wait.h exists and
dnl defines POSIX_SYS_WAIT if it is posix compatable. This way things
dnl like WNOHANG, WUNTRACED can still be used.
AC_DEFUN(KSH_HEADER_SYS_WAIT,
[AC_CACHE_CHECK([for sys/wait.h that is POSIX.1 compatible], ksh_cv_header_sys_wait_h,
[AC_TRY_COMPILE([#include <sys/types.h>
#include <sys/wait.h>
#ifndef WEXITSTATUS
#define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
#endif
#ifndef WIFEXITED
#define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
#endif], [int s;
wait (&s);
s = WIFEXITED (s) ? WEXITSTATUS (s) : 1;],
ksh_cv_header_sys_wait_h=yes, ksh_cv_header_sys_wait_h=no)])
if test $ksh_cv_header_sys_wait_h = yes; then
AC_DEFINE(POSIX_SYS_WAIT)dnl
AC_DEFINE(HAVE_SYS_WAIT_H)dnl
else
AC_CHECK_HEADERS(sys/wait.h)dnl
fi
])
dnl
dnl
dnl Modified test from autoconf's acspecific.m4(AC_HEADER_STAT) test: need
dnl to check if S_ISSOCK == S_ISFIFO (FreeBSD).
undefine([AC_HEADER_STAT])dnl
AC_DEFUN(AC_HEADER_STAT,
[AC_CACHE_CHECK(whether stat file-mode macros are broken,
ac_cv_header_stat_broken,
[AC_EGREP_CPP([You lose], [#include <sys/types.h>
#include <sys/stat.h>
#if defined(S_ISBLK) && defined(S_IFDIR)
# if S_ISBLK (S_IFDIR)
You lose.
# endif
#endif
#if defined(S_ISBLK) && defined(S_IFCHR)
# if S_ISBLK (S_IFCHR)
You lose.
# endif
#endif
#if defined(S_ISLNK) && defined(S_IFREG)
# if S_ISLNK (S_IFREG)
You lose.
# endif
#endif
#if defined(S_ISSOCK) && defined(S_IFREG)
# if S_ISSOCK (S_IFREG)
You lose.
# endif
#endif
#if defined(S_ISSOCK) && defined(S_IFIFO)
# if S_ISSOCK (S_IFIFO)
You lose.
# endif
#endif
], ac_cv_header_stat_broken=yes, ac_cv_header_stat_broken=no)])
if test $ac_cv_header_stat_broken = yes; then
AC_DEFINE(STAT_MACROS_BROKEN)
fi
])
dnl
dnl
dnl Need to change the "accepts -g" test - some broken systems
dnl allow "cc -c -g ..." but fail on the link (missing -lg).
dnl LaserMoon's linux/FT is such a broken system...
undefine([AC_PROG_CC])dnl
AC_DEFUN(AC_PROG_CC,
[AC_BEFORE([$0], [AC_PROG_CPP])dnl
AC_CHECK_PROG(CC, gcc, gcc, cc)
AC_CACHE_CHECK(whether we are using GNU C, ac_cv_prog_gcc,
[dnl The semicolon is to pacify NeXT's syntax-checking cpp.
cat > conftest.c <<EOF
#ifdef __GNUC__
yes;
#endif
EOF
if ${CC-cc} -E conftest.c 2>&AC_FD_CC | egrep yes >/dev/null 2>&1; then
ac_cv_prog_gcc=yes
else
ac_cv_prog_gcc=no
fi])
if test $ac_cv_prog_gcc = yes; then
GCC=yes
if test "${CFLAGS+set}" != set; then
AC_CACHE_CHECK(whether ${CC-cc} accepts -g, ac_cv_prog_gcc_g,
[echo 'int main(){ return 0; }' > conftest.c
if test -z "`${CC-cc} -g conftest.c 2>&1`"; then
ac_cv_prog_gcc_g=yes
else
ac_cv_prog_gcc_g=no
fi
rm -f conftest*
])
if test $ac_cv_prog_gcc_g = yes; then
CFLAGS="-g -O"
else
CFLAGS="-O"
fi
fi
else
GCC=
test "${CFLAGS+set}" = set || CFLAGS="-g"
fi
])
dnl
dnl
dnl Need to change to check for ndir
dnl
undefine([AC_HEADER_DIRENT])dnl
AC_DEFUN(AC_HEADER_DIRENT,
[ac_header_dirent=no
AC_CHECK_HEADERS_DIRENT(dirent.h sys/ndir.h sys/dir.h ndir.h,
[ac_header_dirent=$ac_hdr; break])
# Two versions of opendir et al. are in -ldir and -lx on SCO Xenix.
if test $ac_header_dirent = dirent.h; then
AC_CHECK_LIB(dir, opendir, LIBS="$LIBS -ldir", AC_CHECK_LIB(ndir, opendir, LIBS="$LIBS -lndir"))
else
AC_CHECK_LIB(x, opendir, LIBS="$LIBS -lx")
fi
])
|