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
|
/* $NetBSD: compat_defs.h,v 1.103 2015/09/21 21:50:16 pooka Exp $ */
#ifndef __NETBSD_COMPAT_DEFS_H__
#define __NETBSD_COMPAT_DEFS_H__
/*
* On NetBSD, ensure that _NETBSD_SOURCE does not get defined, so that
* accidental attempts to use NetBSD-specific features instead of more
* portable features is likely to be noticed when the tools are built
* on NetBSD. Define enough other feature test macros to expose the
* features we need.
*/
#ifdef __NetBSD__
#define _ISOC99_SOURCE
#define _POSIX_SOURCE 1
#define _POSIX_C_SOURCE 200112L
#define _XOPEN_SOURCE 600
#endif /* __NetBSD__ */
/*
* Linux: <features.h> turns on _POSIX_SOURCE by default, even though the
* program (not the OS) should do that. Preload <features.h> and
* then override some of the feature test macros.
*/
#if defined(__linux__) && HAVE_FEATURES_H
#include <features.h>
#undef _POSIX_SOURCE
#undef _POSIX_C_SOURCE
#define __USE_ISOC99 1
#endif /* __linux__ && HAVE_FEATURES_H */
/* System headers needed for (re)definitions below. */
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/param.h>
/* time.h needs to be pulled in first at least on netbsd w/o _NETBSD_SOURCE */
#include <sys/time.h>
#include <sys/stat.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <paths.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#if HAVE_SYS_CDEFS_H
#include <sys/cdefs.h>
#endif
#if HAVE_SYS_SYSLIMITS_H
#include <sys/syslimits.h>
#endif
#if HAVE_SYS_SYSMACROS_H
/* major(), minor() on SVR4 */
#include <sys/sysmacros.h>
#endif
#if HAVE_INTTYPES_H
#include <inttypes.h>
#endif
#if HAVE_STDDEF_H
#include <stddef.h>
#endif
#if HAVE_RPC_TYPES_H
#include <rpc/types.h>
#endif
#ifdef _NETBSD_SOURCE
#error _NETBSD_SOURCE is *not* to be defined.
#endif
/* Need this since we can't depend on NetBSD's version to be around */
#ifdef __UNCONST
#undef __UNCONST
#endif
#define __UNCONST(a) ((void *)(unsigned long)(const void *)(a))
#ifdef __UNVOLATILE
#undef __UNVOLATILE
#endif
#define __UNVOLATILE(a) ((void *)(unsigned long)(volatile void *)(a))
#undef __predict_false
#define __predict_false(x) (x)
#undef __predict_true
#define __predict_true(x) (x)
/* We don't include <pwd.h> here, so that "compat_pwd.h" works. */
struct passwd;
/* We don't include <grp.h> either */
struct group;
/* Assume an ANSI compiler for the host. */
#undef __P
#define __P(x) x
#ifndef __BEGIN_DECLS
#define __BEGIN_DECLS
#endif
#ifndef __END_DECLS
#define __END_DECLS
#endif
/* Some things in NetBSD <sys/cdefs.h>. */
#ifndef __CONCAT
#define __CONCAT(x,y) x ## y
#endif
#if !defined(__attribute__) && !defined(__GNUC__)
#define __attribute__(x)
#endif
#if !defined(__packed)
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
#define __packed __attribute__((__packed__))
#elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)
#define __packed __attribute__((__packed__))
#else
#define __packed error: no __packed for this compiler
#endif
#endif /* !__packed */
#ifndef __RENAME
#define __RENAME(x)
#endif
#undef __aconst
#define __aconst
#undef __dead
#define __dead
#undef __printflike
#define __printflike(x,y)
#undef __format_arg
#define __format_arg(x)
#undef __restrict
#define __restrict
#undef __unused
#define __unused
#undef __arraycount
#define __arraycount(__x) (sizeof(__x) / sizeof(__x[0]))
#undef __USE
#define __USE(a) ((void)(a))
#undef __type_min_s
#define __type_min_s(t) ((t)((1ULL << (sizeof(t) * NBBY - 1))))
#undef __type_max_s
#define __type_max_s(t) ((t)~((1ULL << (sizeof(t) * NBBY - 1))))
#undef __type_min_u
#define __type_min_u(t) ((t)0ULL)
#undef __type_max_u
#define __type_max_u(t) ((t)~0ULL)
#undef __type_is_signed
#define __type_is_signed(t) (/*LINTED*/__type_min_s(t) + (t)1 < (t)1)
#undef __type_min
#define __type_min(t) (__type_is_signed(t) ? __type_min_s(t) : __type_min_u(t))
#undef __type_max
#define __type_max(t) (__type_is_signed(t) ? __type_max_s(t) : __type_max_u(t))
/* Dirent support. */
#if HAVE_DIRENT_H
# if defined(__linux__) && defined(__USE_BSD)
# undef __USE_BSD
# include <dirent.h>
# define __USE_BSD 1
# undef d_fileno
# else
# include <dirent.h>
# if defined(__DARWIN_UNIX03)
# undef d_fileno
# endif
# endif
# define NAMLEN(dirent) (strlen((dirent)->d_name))
#else
# define dirent direct
# define NAMLEN(dirent) ((dirent)->d_namlen)
# if HAVE_SYS_NDIR_H
# include <sys/ndir.h>
# endif
# if HAVE_SYS_DIR_H
# include <sys/dir.h>
# endif
# if HAVE_NDIR_H
# include <ndir.h>
# endif
#endif
/* Type substitutes. */
#if !HAVE_ID_T
typedef unsigned int id_t;
#endif
#if !HAVE_SOCKLEN_T
/*
* This is defined as int for compatibility with legacy systems (and not
* unsigned int), since universally it was int in most systems that did not
* define it.
*/
typedef int socklen_t;
#endif
#if !HAVE_U_LONG
typedef unsigned long u_long;
#endif
#if !HAVE_U_CHAR
typedef unsigned char u_char;
#endif
#if !HAVE_U_INT
typedef unsigned int u_int;
#endif
#if !HAVE_U_SHORT
typedef unsigned short u_short;
#endif
/* Prototypes for replacement functions. */
#if !HAVE_ATOLL
long long int atoll(const char *);
#endif
#if !HAVE_ASPRINTF
int asprintf(char **, const char *, ...);
#endif
#if !HAVE_ASNPRINTF
int asnprintf(char **, size_t, const char *, ...);
#endif
#if !HAVE_BASENAME
char *basename(char *);
#endif
#if !HAVE_DECL_OPTIND
int getopt(int, char *const *, const char *);
extern char *optarg;
extern int optind, opterr, optopt;
#endif
#if !HAVE_DIRNAME
char *dirname(char *);
#endif
#if !HAVE_DIRFD
#if HAVE_DIR_DD_FD
#define dirfd(dirp) ((dirp)->dd_fd)
#elif HAVE_DIR___DD_FD
#define dirfd(dirp) ((dirp)->__dd_fd)
#else
/*XXX: Very hacky but no other way to bring this into scope w/o defining
_NETBSD_SOURCE which we're avoiding. */
#if defined(__NetBSD__) || defined(__minix)
struct _dirdesc {
int dd_fd; /* file descriptor associated with directory */
long dd_loc; /* offset in current buffer */
long dd_size; /* amount of data returned by getdents */
char *dd_buf; /* data buffer */
int dd_len; /* size of data buffer */
off_t dd_seek; /* magic cookie returned by getdents */
long dd_rewind; /* magic cookie for rewinding */
int dd_flags; /* flags for readdir */
void *dd_lock; /* lock for concurrent access */
};
#define dirfd(dirp) (((struct _dirdesc *)dirp)->dd_fd)
#else
#error cannot figure out how to turn a DIR * into a fd
#endif
#endif
#endif
#if !HAVE_ERR_H
void err(int, const char *, ...);
void errx(int, const char *, ...);
void warn(const char *, ...);
void warnx(const char *, ...);
void vwarnx(const char *, va_list);
#endif
#if !HAVE_DECL_WARNC
void warnc(int, const char *, ...);
#endif
#if !HAVE_DECL_VWARNC
void vwarnc(int, const char *, va_list);
#endif
#if !HAVE_DECL_ERRC
void errc(int, int, const char *, ...);
#endif
#if !HAVE_DECL_VERRC
void verrc(int, int, const char *, va_list);
#endif
#if !HAVE_ESETFUNC
void (*esetfunc(void (*)(int, const char *, ...)))(int, const char *, ...);
size_t estrlcpy(char *, const char *, size_t);
size_t estrlcat(char *, const char *, size_t);
char *estrdup(const char *);
char *estrndup(const char *, size_t);
void *ecalloc(size_t, size_t);
void *emalloc(size_t);
void *erealloc(void *, size_t);
FILE *efopen(const char *, const char *);
int easprintf(char **, const char *, ...);
int evasprintf(char **, const char *, va_list);
#endif
#if !HAVE_FGETLN || defined(__NetBSD__) || defined(__minix)
char *fgetln(FILE *, size_t *);
#endif
#if !HAVE_DPRINTF
int dprintf(int, const char *, ...);
#endif
#if !HAVE_FLOCK
# define LOCK_SH 0x01
# define LOCK_EX 0x02
# define LOCK_NB 0x04
# define LOCK_UN 0x08
int flock(int, int);
#endif
#if !HAVE_FPARSELN || BROKEN_FPARSELN || defined(__NetBSD__) || defined(__minix)
# define FPARSELN_UNESCESC 0x01
# define FPARSELN_UNESCCONT 0x02
# define FPARSELN_UNESCCOMM 0x04
# define FPARSELN_UNESCREST 0x08
# define FPARSELN_UNESCALL 0x0f
char *fparseln(FILE *, size_t *, size_t *, const char [3], int);
#endif
#if !HAVE_GETLINE
ssize_t getdelim(char **, size_t *, int, FILE *);
ssize_t getline(char **, size_t *, FILE *);
#endif
#if !HAVE_ISSETUGID
int issetugid(void);
#endif
#if !HAVE_ISBLANK && !defined(isblank)
#define isblank(x) ((x) == ' ' || (x) == '\t')
#endif
#define __nbcompat_bswap16(x) ((((x) << 8) & 0xff00) | (((x) >> 8) & 0x00ff))
#define __nbcompat_bswap32(x) ((((x) << 24) & 0xff000000) | \
(((x) << 8) & 0x00ff0000) | \
(((x) >> 8) & 0x0000ff00) | \
(((x) >> 24) & 0x000000ff))
#define __nbcompat_bswap64(x) (((u_int64_t)bswap32((x)) << 32) | \
((u_int64_t)bswap32((x) >> 32)))
#if ! HAVE_DECL_BSWAP16
#ifdef bswap16
#undef bswap16
#endif
#define bswap16(x) __nbcompat_bswap16(x)
#endif
#if ! HAVE_DECL_BSWAP32
#ifdef bswap32
#undef bswap32
#endif
#define bswap32(x) __nbcompat_bswap32(x)
#endif
#if ! HAVE_DECL_BSWAP64
#ifdef bswap64
#undef bswap64
#endif
#define bswap64(x) __nbcompat_bswap64(x)
#endif
#if !HAVE_MKSTEMP
int mkstemp(char *);
#endif
#if !HAVE_MKDTEMP
char *mkdtemp(char *);
#endif
#if !HAVE_MKSTEMP || !HAVE_MKDTEMP
/* This is a prototype for the internal function defined in
* src/lib/lib/stdio/gettemp.c */
int __nbcompat_gettemp(char *, int *, int);
#endif
#if !HAVE_PREAD
ssize_t pread(int, void *, size_t, off_t);
#endif
#if !HAVE_HEAPSORT
int heapsort (void *, size_t, size_t, int (*)(const void *, const void *));
#endif
/* Make them use our version */
# define heapsort __nbcompat_heapsort
char *flags_to_string(unsigned long, const char *);
int string_to_flags(char **, unsigned long *, unsigned long *);
/*
* HAVE_X_FROM_Y and HAVE_PWCACHE_FOODB go together, because we cannot
* supply an implementation of one without the others -- some parts are
* libc internal and this varies from system to system.
*
* XXX this is dubious anyway: we assume (see HAVE_DECLs below) that if the
* XXX host system has all of these functions, all of their interfaces
* XXX and interactions are exactly the same as in our libc/libutil -- ugh.
*/
#if !HAVE_USER_FROM_UID || !HAVE_UID_FROM_USER || !HAVE_GROUP_FROM_GID || \
!HAVE_GID_FROM_GROUP || !HAVE_PWCACHE_USERDB || !HAVE_PWCACHE_GROUDB
/* Make them use our version */
# define user_from_uid __nbcompat_user_from_uid
# define uid_from_user __nbcompat_uid_from_user
# define pwcache_userdb __nbcompat_pwcache_userdb
# define group_from_gid __nbcompat_group_from_gid
# define gid_from_group __nbcompat_gid_from_group
# define pwcache_groupdb __nbcompat_pwcache_groupdb
#endif
#if !HAVE_DECL_UID_FROM_USER
int uid_from_user(const char *, uid_t *);
#endif
#if !HAVE_DECL_USER_FROM_UID
const char *user_from_uid(uid_t, int);
#endif
#if !HAVE_DECL_PWCACHE_USERDB
int pwcache_userdb(int (*)(int), void (*)(void),
struct passwd * (*)(const char *), struct passwd * (*)(uid_t));
#endif
#if !HAVE_DECL_GID_FROM_GROUP
int gid_from_group(const char *, gid_t *);
#endif
#if !HAVE_DECL_GROUP_FROM_GID
const char *group_from_gid(gid_t, int);
#endif
#if !HAVE_DECL_PWCACHE_GROUPDB
int pwcache_groupdb(int (*)(int), void (*)(void),
struct group * (*)(const char *), struct group * (*)(gid_t));
#endif
#if !HAVE_DECL_STRNDUP
char *strndup(const char *, size_t);
#endif
#if !HAVE_DECL_STRNLEN
size_t strnlen(const char *, size_t);
#endif
#if !HAVE_DECL_LCHFLAGS
int lchflags(const char *, unsigned long);
#endif
#if !HAVE_DECL_LCHMOD
int lchmod(const char *, mode_t);
#endif
#if !HAVE_DECL_LCHOWN
int lchown(const char *, uid_t, gid_t);
#endif
#if !HAVE_PWRITE
ssize_t pwrite(int, const void *, size_t, off_t);
#endif
#if !HAVE_RAISE_DEFAULT_SIGNAL
int raise_default_signal(int);
#endif
#if !HAVE_REALLOCARR
int reallocarr(void *, size_t, size_t);
#endif
#if !HAVE_SETENV
int setenv(const char *, const char *, int);
#endif
#if !HAVE_DECL_SETGROUPENT
int setgroupent(int);
#endif
#if !HAVE_DECL_SETPASSENT
int setpassent(int);
#endif
#if !HAVE_SETPROGNAME || defined(__NetBSD__) || defined(__minix)
const char *getprogname(void);
void setprogname(const char *);
#endif
#if !HAVE_SNPRINTB_M
int snprintb(char *, size_t, const char *, uint64_t);
int snprintb_m(char *, size_t, const char *, uint64_t, size_t);
#endif
#if !HAVE_SNPRINTF
int snprintf(char *, size_t, const char *, ...);
#endif
#if !HAVE_STRLCAT
size_t strlcat(char *, const char *, size_t);
#endif
#if !HAVE_STRLCPY
size_t strlcpy(char *, const char *, size_t);
#endif
#if !HAVE_STRMODE
void strmode(mode_t, char *);
#endif
#if !HAVE_STRNDUP
char *strndup(const char *, size_t);
#endif
#if !HAVE_STRSEP || defined(__NetBSD__) || defined(__minix)
char *strsep(char **, const char *);
#endif
#if !HAVE_DECL_STRSUFTOLL
long long strsuftoll(const char *, const char *, long long, long long);
long long strsuftollx(const char *, const char *,
long long, long long, char *, size_t);
#endif
#if !HAVE_STRTOLL
long long strtoll(const char *, char **, int);
#endif
#if !HAVE_STRTOI
intmax_t strtoi(const char * __restrict, char ** __restrict, int,
intmax_t, intmax_t, int *);
#endif
#if !HAVE_STRTOU
uintmax_t strtou(const char * __restrict, char ** __restrict, int,
uintmax_t, uintmax_t, int *);
#endif
#if !HAVE_USER_FROM_UID
const char *user_from_uid(uid_t, int);
#endif
#if !HAVE_GROUP_FROM_GID
const char *group_from_gid(gid_t, int);
#endif
#if !HAVE_VASPRINTF
int vasprintf(char **, const char *, va_list);
#endif
#if !HAVE_VASNPRINTF
int vasnprintf(char **, size_t, const char *, va_list);
#endif
#if !HAVE_VSNPRINTF
int vsnprintf(char *, size_t, const char *, va_list);
#endif
/*
* getmode() and setmode() are always defined, as these function names
* exist but with very different meanings on other OS's. The compat
* versions here simply accept an octal mode number; the "u+x,g-w" type
* of syntax is not accepted.
*/
#define getmode __nbcompat_getmode
#define setmode __nbcompat_setmode
mode_t getmode(const void *, mode_t);
void *setmode(const char *);
/* Eliminate assertions embedded in binaries. */
#undef _DIAGASSERT
#define _DIAGASSERT(x)
/* Various sources use this */
#undef __RCSID
#define __RCSID(x) struct XXXNETBSD_RCSID
#undef __SCCSID
#define __SCCSID(x)
#undef __COPYRIGHT
#define __COPYRIGHT(x) struct XXXNETBSD_COPYRIGHT
#undef __KERNEL_RCSID
#define __KERNEL_RCSID(x,y)
/* Heimdal expects this one. */
#undef RCSID
#define RCSID(x)
/* Some definitions not available on all systems. */
#ifndef __inline
#define __inline inline
#endif
/* <errno.h> */
#ifndef EFTYPE
#define EFTYPE EIO
#endif
/* <fcntl.h> */
#ifndef O_EXLOCK
#define O_EXLOCK 0
#endif
#ifndef O_SHLOCK
#define O_SHLOCK 0
#endif
#ifndef O_CLOEXEC
#define O_CLOEXEC 0
#endif
/* <inttypes.h> */
#if UCHAR_MAX == 0xffU /* char is an 8-bit type */
#ifndef PRId8
#define PRId8 "hhd"
#endif
#ifndef PRIi8
#define PRIi8 "hhi"
#endif
#ifndef PRIo8
#define PRIo8 "hho"
#endif
#ifndef PRIu8
#define PRIu8 "hhu"
#endif
#ifndef PRIx8
#define PRIx8 "hhx"
#endif
#ifndef PRIX8
#define PRIX8 "hhX"
#endif
#ifndef SCNd8
#define SCNd8 "hhd"
#endif
#ifndef SCNi8
#define SCNi8 "hhi"
#endif
#ifndef SCNo8
#define SCNo8 "hho"
#endif
#ifndef SCNu8
#define SCNu8 "hhu"
#endif
#ifndef SCNx8
#define SCNx8 "hhx"
#endif
#ifndef SCNX8
#define SCNX8 "hhX"
#endif
#endif /* char is an 8-bit type */
#if ! (defined(PRId8) && defined(PRIi8) && defined(PRIo8) && \
defined(PRIu8) && defined(PRIx8) && defined(PRIX8))
#error "Don't know how to define PRI[diouxX]8"
#endif
#if ! (defined(SCNd8) && defined(SCNi8) && defined(SCNo8) && \
defined(SCNu8) && defined(SCNx8) && defined(SCNX8))
#error "Don't know how to define SCN[diouxX]8"
#endif
#if USHRT_MAX == 0xffffU /* short is a 16-bit type */
#ifndef PRId16
#define PRId16 "hd"
#endif
#ifndef PRIi16
#define PRIi16 "hi"
#endif
#ifndef PRIo16
#define PRIo16 "ho"
#endif
#ifndef PRIu16
#define PRIu16 "hu"
#endif
#ifndef PRIx16
#define PRIx16 "hx"
#endif
#ifndef PRIX16
#define PRIX16 "hX"
#endif
#ifndef SCNd16
#define SCNd16 "hd"
#endif
#ifndef SCNi16
#define SCNi16 "hi"
#endif
#ifndef SCNo16
#define SCNo16 "ho"
#endif
#ifndef SCNu16
#define SCNu16 "hu"
#endif
#ifndef SCNx16
#define SCNx16 "hx"
#endif
#ifndef SCNX16
#define SCNX16 "hX"
#endif
#endif /* short is a 16-bit type */
#if ! (defined(PRId16) && defined(PRIi16) && defined(PRIo16) && \
defined(PRIu16) && defined(PRIx16) && defined(PRIX16))
#error "Don't know how to define PRI[diouxX]16"
#endif
#if ! (defined(SCNd16) && defined(SCNi16) && defined(SCNo16) && \
defined(SCNu16) && defined(SCNx16) && defined(SCNX16))
#error "Don't know how to define SCN[diouxX]16"
#endif
#if UINT_MAX == 0xffffffffU /* int is a 32-bit type */
#ifndef PRId32
#define PRId32 "d"
#endif
#ifndef PRIi32
#define PRIi32 "i"
#endif
#ifndef PRIo32
#define PRIo32 "o"
#endif
#ifndef PRIu32
#define PRIu32 "u"
#endif
#ifndef PRIx32
#define PRIx32 "x"
#endif
#ifndef PRIX32
#define PRIX32 "X"
#endif
#ifndef SCNd32
#define SCNd32 "d"
#endif
#ifndef SCNi32
#define SCNi32 "i"
#endif
#ifndef SCNo32
#define SCNo32 "o"
#endif
#ifndef SCNu32
#define SCNu32 "u"
#endif
#ifndef SCNx32
#define SCNx32 "x"
#endif
#ifndef SCNX32
#define SCNX32 "X"
#endif
#endif /* int is a 32-bit type */
#if ULONG_MAX == 0xffffffffU /* long is a 32-bit type */
#ifndef PRId32
#define PRId32 "ld"
#endif
#ifndef PRIi32
#define PRIi32 "li"
#endif
#ifndef PRIo32
#define PRIo32 "lo"
#endif
#ifndef PRIu32
#define PRIu32 "lu"
#endif
#ifndef PRIx32
#define PRIx32 "lx"
#endif
#ifndef PRIX32
#define PRIX32 "lX"
#endif
#ifndef SCNd32
#define SCNd32 "ld"
#endif
#ifndef SCNi32
#define SCNi32 "li"
#endif
#ifndef SCNo32
#define SCNo32 "lo"
#endif
#ifndef SCNu32
#define SCNu32 "lu"
#endif
#ifndef SCNx32
#define SCNx32 "lx"
#endif
#ifndef SCNX32
#define SCNX32 "lX"
#endif
#endif /* long is a 32-bit type */
#if ! (defined(PRId32) && defined(PRIi32) && defined(PRIo32) && \
defined(PRIu32) && defined(PRIx32) && defined(PRIX32))
#error "Don't know how to define PRI[diouxX]32"
#endif
#if ! (defined(SCNd32) && defined(SCNi32) && defined(SCNo32) && \
defined(SCNu32) && defined(SCNx32) && defined(SCNX32))
#error "Don't know how to define SCN[diouxX]32"
#endif
#if ULONG_MAX == 0xffffffffffffffffU /* long is a 64-bit type */
#ifndef PRId64
#define PRId64 "ld"
#endif
#ifndef PRIi64
#define PRIi64 "li"
#endif
#ifndef PRIo64
#define PRIo64 "lo"
#endif
#ifndef PRIu64
#define PRIu64 "lu"
#endif
#ifndef PRIx64
#define PRIx64 "lx"
#endif
#ifndef PRIX64
#define PRIX64 "lX"
#endif
#ifndef SCNd64
#define SCNd64 "ld"
#endif
#ifndef SCNi64
#define SCNi64 "li"
#endif
#ifndef SCNo64
#define SCNo64 "lo"
#endif
#ifndef SCNu64
#define SCNu64 "lu"
#endif
#ifndef SCNx64
#define SCNx64 "lx"
#endif
#ifndef SCNX64
#define SCNX64 "lX"
#endif
#endif /* long is a 64-bit type */
#if ULLONG_MAX == 0xffffffffffffffffU /* long long is a 64-bit type */
#ifndef PRId64
#define PRId64 "lld"
#endif
#ifndef PRIi64
#define PRIi64 "lli"
#endif
#ifndef PRIo64
#define PRIo64 "llo"
#endif
#ifndef PRIu64
#define PRIu64 "llu"
#endif
#ifndef PRIx64
#define PRIx64 "llx"
#endif
#ifndef PRIX64
#define PRIX64 "llX"
#endif
#ifndef SCNd64
#define SCNd64 "lld"
#endif
#ifndef SCNi64
#define SCNi64 "lli"
#endif
#ifndef SCNo64
#define SCNo64 "llo"
#endif
#ifndef SCNu64
#define SCNu64 "llu"
#endif
#ifndef SCNx64
#define SCNx64 "llx"
#endif
#ifndef SCNX64
#define SCNX64 "llX"
#endif
#endif /* long long is a 64-bit type */
#if ! (defined(PRId64) && defined(PRIi64) && defined(PRIo64) && \
defined(PRIu64) && defined(PRIx64) && defined(PRIX64))
#error "Don't know how to define PRI[diouxX]64"
#endif
#if ! (defined(SCNd64) && defined(SCNi64) && defined(SCNo64) && \
defined(SCNu64) && defined(SCNx64) && defined(SCNX64))
#error "Don't know how to define SCN[diouxX]64"
#endif
/* <limits.h> */
#ifndef UID_MAX
#define UID_MAX 32767
#endif
#ifndef GID_MAX
#define GID_MAX UID_MAX
#endif
#ifndef UQUAD_MAX
#define UQUAD_MAX ((u_quad_t)-1)
#endif
#ifndef QUAD_MAX
#define QUAD_MAX ((quad_t)(UQUAD_MAX >> 1))
#endif
#ifndef QUAD_MIN
#define QUAD_MIN ((quad_t)(~QUAD_MAX))
#endif
#ifndef ULLONG_MAX
#define ULLONG_MAX ((unsigned long long)-1)
#endif
#ifndef LLONG_MAX
#define LLONG_MAX ((long long)(ULLONG_MAX >> 1))
#endif
#ifndef LLONG_MIN
#define LLONG_MIN ((long long)(~LLONG_MAX))
#endif
#ifndef MAXPATHLEN
#define MAXPATHLEN 4096
#endif
#ifndef PATH_MAX
#define PATH_MAX MAXPATHLEN
#endif
/* <paths.h> */
/* The host's _PATH_BSHELL might be broken, so override it. */
#undef _PATH_BSHELL
#define _PATH_BSHELL PATH_BSHELL
#ifndef _PATH_DEFPATH
#define _PATH_DEFPATH "/usr/bin:/bin:/usr/local/bin"
#endif
#ifndef _PATH_DEV
#define _PATH_DEV "/dev/"
#endif
#ifndef _PATH_DEVNULL
#define _PATH_DEVNULL _PATH_DEV "null"
#endif
#ifndef _PATH_TMP
#define _PATH_TMP "/tmp/"
#endif
#ifndef _PATH_DEFTAPE
#define _PATH_DEFTAPE "/dev/nrst0"
#endif
#ifndef _PATH_VI
#define _PATH_VI "/usr/bin/vi"
#endif
/* <stdint.h> */
#if !defined(SIZE_MAX) && defined(SIZE_T_MAX)
#define SIZE_MAX SIZE_T_MAX
#endif
#ifndef UINT8_MAX
#define UINT8_MAX 0xffU
#endif
#ifndef UINT16_MAX
#define UINT16_MAX 0xffffU
#endif
#ifndef UINT32_MAX
#define UINT32_MAX 0xffffffffU
#endif
/* <stdlib.h> */
#ifndef __GNUC__
# if HAVE_ALLOCA_H
# include <alloca.h>
# else
# ifndef alloca /* predefined by HP cc +Olibcalls */
char *alloca ();
# endif
# endif
#endif
/* avoid prototype conflicts with host */
#define cgetcap __nbcompat_cgetcap
#define cgetclose __nbcompat_cgetclose
#define cgetent __nbcompat_cgetent
#define cgetfirst __nbcompat_cgetfirst
#define cgetmatch __nbcompat_cgetmatch
#define cgetnext __nbcompat_cgetnext
#define cgetnum __nbcompat_cgetnum
#define cgetset __nbcompat_cgetset
#define cgetstr __nbcompat_cgetstr
#define cgetustr __nbcompat_cgetustr
char *cgetcap(char *, const char *, int);
int cgetclose(void);
int cgetent(char **, const char * const *, const char *);
int cgetfirst(char **, const char * const *);
int cgetmatch(const char *, const char *);
int cgetnext(char **, const char * const *);
int cgetnum(char *, const char *, long *);
int cgetset(const char *);
int cgetstr(char *, const char *, char **);
int cgetustr(char *, const char *, char **);
/* <sys/endian.h> */
#if WORDS_BIGENDIAN
#if !HAVE_DECL_HTOBE16
#define htobe16(x) (x)
#endif
#if !HAVE_DECL_HTOBE32
#define htobe32(x) (x)
#endif
#if !HAVE_DECL_HTOBE64
#define htobe64(x) (x)
#endif
#if !HAVE_DECL_HTOLE16
#define htole16(x) bswap16((u_int16_t)(x))
#endif
#if !HAVE_DECL_HTOLE32
#define htole32(x) bswap32((u_int32_t)(x))
#endif
#if !HAVE_DECL_HTOLE64
#define htole64(x) bswap64((u_int64_t)(x))
#endif
#else
#if !HAVE_DECL_HTOBE16
#define htobe16(x) bswap16((u_int16_t)(x))
#endif
#if !HAVE_DECL_HTOBE32
#define htobe32(x) bswap32((u_int32_t)(x))
#endif
#if !HAVE_DECL_HTOBE64
#define htobe64(x) bswap64((u_int64_t)(x))
#endif
#if !HAVE_DECL_HTOLE16
#define htole16(x) (x)
#endif
#if !HAVE_DECL_HTOLE32
#define htole32(x) (x)
#endif
#if !HAVE_DECL_HTOLE64
#define htole64(x) (x)
#endif
#endif
#if !HAVE_DECL_BE16TOH
#define be16toh(x) htobe16(x)
#endif
#if !HAVE_DECL_BE32TOH
#define be32toh(x) htobe32(x)
#endif
#if !HAVE_DECL_BE64TOH
#define be64toh(x) htobe64(x)
#endif
#if !HAVE_DECL_LE16TOH
#define le16toh(x) htole16(x)
#endif
#if !HAVE_DECL_LE32TOH
#define le32toh(x) htole32(x)
#endif
#if !HAVE_DECL_LE64TOH
#define le64toh(x) htole64(x)
#endif
#define __GEN_ENDIAN_ENC(bits, endian) \
static void \
endian ## bits ## enc(void *dst, uint ## bits ## _t u) \
{ \
u = hto ## endian ## bits (u); \
memcpy(dst, &u, sizeof(u)); \
}
#if !HAVE_DECL_BE16ENC
__GEN_ENDIAN_ENC(16, be)
#endif
#if !HAVE_DECL_BE32ENC
__GEN_ENDIAN_ENC(32, be)
#endif
#if !HAVE_DECL_BE64ENC
__GEN_ENDIAN_ENC(64, be)
#endif
#if !HAVE_DECL_LE16ENC
__GEN_ENDIAN_ENC(16, le)
#endif
#if !HAVE_DECL_LE32ENC
__GEN_ENDIAN_ENC(32, le)
#endif
#if !HAVE_DECL_LE64ENC
__GEN_ENDIAN_ENC(64, le)
#endif
#undef __GEN_ENDIAN_ENC
#define __GEN_ENDIAN_DEC(bits, endian) \
static uint ## bits ## _t \
endian ## bits ## dec(const void *buf) \
{ \
uint ## bits ## _t u; \
memcpy(&u, buf, sizeof(u)); \
return endian ## bits ## toh (u); \
}
#if !HAVE_DECL_BE16DEC
__GEN_ENDIAN_DEC(16, be)
#endif
#if !HAVE_DECL_BE32DEC
__GEN_ENDIAN_DEC(32, be)
#endif
#if !HAVE_DECL_BE64DEC
__GEN_ENDIAN_DEC(64, be)
#endif
#if !HAVE_DECL_LE16DEC
__GEN_ENDIAN_DEC(16, le)
#endif
#if !HAVE_DECL_LE32DEC
__GEN_ENDIAN_DEC(32, le)
#endif
#if !HAVE_DECL_LE64DEC
__GEN_ENDIAN_DEC(64, le)
#endif
#undef __GEN_ENDIAN_DEC
/* <sys/mman.h> */
#ifndef MAP_FILE
#define MAP_FILE 0
#endif
/* HP-UX has MAP_ANONYMOUS but not MAP_ANON */
#ifndef MAP_ANON
#ifdef MAP_ANONYMOUS
#define MAP_ANON MAP_ANONYMOUS
#endif
#endif
/* <sys/param.h> */
#undef BIG_ENDIAN
#undef LITTLE_ENDIAN
#undef PDP_ENDIAN
#define BIG_ENDIAN 4321
#define LITTLE_ENDIAN 1234
#define PDP_ENDIAN 3412
#undef BYTE_ORDER
#if WORDS_BIGENDIAN
#define BYTE_ORDER BIG_ENDIAN
#else
#define BYTE_ORDER LITTLE_ENDIAN
#endif
/* all references of DEV_BSIZE in tools are for NetBSD's file images */
#undef DEV_BSIZE
#define DEV_BSIZE (1 << 9)
#undef MIN
#undef MAX
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#ifndef MAXBSIZE
#define MAXBSIZE (64 * 1024)
#endif
#ifndef MAXFRAG
#define MAXFRAG 8
#endif
#ifndef MAXPHYS
#define MAXPHYS (64 * 1024)
#endif
#ifndef MAXHOSTNAMELEN
#define MAXHOSTNAMELEN 256
#endif
/* XXX needed by makefs; this should be done in a better way */
#undef btodb
#define btodb(x) ((x) << 9)
#undef setbit
#undef clrbit
#undef isset
#undef isclr
#define setbit(a,i) ((a)[(i)/NBBY] |= 1<<((i)%NBBY))
#define clrbit(a,i) ((a)[(i)/NBBY] &= ~(1<<((i)%NBBY)))
#define isset(a,i) ((a)[(i)/NBBY] & (1<<((i)%NBBY)))
#define isclr(a,i) (((a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0)
#ifndef powerof2
#define powerof2(x) ((((x)-1)&(x))==0)
#endif
#undef roundup
#define roundup(x, y) ((((x)+((y)-1))/(y))*(y))
/* <sys/stat.h> */
#ifndef ALLPERMS
#define ALLPERMS (S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO)
#endif
#ifndef DEFFILEMODE
#define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)
#endif
#ifndef S_ISTXT
#ifdef S_ISVTX
#define S_ISTXT S_ISVTX
#else
#define S_ISTXT 0
#endif
#endif
/* Protected by _NETBSD_SOURCE otherwise. */
#if HAVE_STRUCT_STAT_ST_FLAGS && (defined(__NetBSD__) || defined(__minix))
#define UF_SETTABLE 0x0000ffff
#define UF_NODUMP 0x00000001
#define UF_IMMUTABLE 0x00000002
#define UF_APPEND 0x00000004
#define UF_OPAQUE 0x00000008
#define SF_SETTABLE 0xffff0000
#define SF_ARCHIVED 0x00010000
#define SF_IMMUTABLE 0x00020000
#define SF_APPEND 0x00040000
#endif
/* <sys/syslimits.h> */
#ifndef LINE_MAX
#define LINE_MAX 2048
#endif
/* <sys/time.h> */
#ifndef timercmp
#define timercmp(tvp, uvp, cmp) \
(((tvp)->tv_sec == (uvp)->tv_sec) ? \
((tvp)->tv_usec cmp (uvp)->tv_usec) : \
((tvp)->tv_sec cmp (uvp)->tv_sec))
#endif
#ifndef timeradd
#define timeradd(tvp, uvp, vvp) \
do { \
(vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \
(vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \
if ((vvp)->tv_usec >= 1000000) { \
(vvp)->tv_sec++; \
(vvp)->tv_usec -= 1000000; \
} \
} while (/* CONSTCOND */ 0)
#endif
#ifndef timersub
#define timersub(tvp, uvp, vvp) \
do { \
(vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \
(vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \
if ((vvp)->tv_usec < 0) { \
(vvp)->tv_sec--; \
(vvp)->tv_usec += 1000000; \
} \
} while (/* CONSTCOND */ 0)
#endif
/* <sys/types.h> */
#ifdef major
#undef major
#endif
#define major(x) ((int32_t)((((x) & 0x000fff00) >> 8)))
#ifdef minor
#undef minor
#endif
#define minor(x) ((int32_t)((((x) & 0xfff00000) >> 12) | \
(((x) & 0x000000ff) >> 0)))
#ifdef makedev
#undef makedev
#endif
#define makedev(x,y) ((dev_t)((((x) << 8) & 0x000fff00) | \
(((y) << 12) & 0xfff00000) | \
(((y) << 0) & 0x000000ff)))
#ifndef NBBY
#define NBBY 8
#endif
#if !HAVE_U_QUAD_T
/* #define, not typedef, as quad_t exists as a struct on some systems */
#define quad_t long long
#define u_quad_t unsigned long long
#define strtoq strtoll
#define strtouq strtoull
#endif
/* Has quad_t but these prototypes don't get pulled into scope. w/o we lose */
#if defined(__NetBSD__) || defined(__minix)
quad_t strtoq(const char *, char **, int);
u_quad_t strtouq(const char *, char **, int);
#endif
#endif /* !__NETBSD_COMPAT_DEFS_H__ */
|