summaryrefslogtreecommitdiff
path: root/src/lib/libast/features
diff options
context:
space:
mode:
authorIgor Pashev <pashev.igor@gmail.com>2012-06-24 22:28:35 +0000
committerIgor Pashev <pashev.igor@gmail.com>2012-06-24 22:28:35 +0000
commit3950ffe2a485479f6561c27364d3d7df5a21d124 (patch)
tree468c6e14449d1b1e279222ec32f676b0311917d2 /src/lib/libast/features
downloadksh-upstream.tar.gz
Imported Upstream version 93u+upstream
Diffstat (limited to 'src/lib/libast/features')
-rw-r--r--src/lib/libast/features/align.c188
-rw-r--r--src/lib/libast/features/api11
-rw-r--r--src/lib/libast/features/aso671
-rw-r--r--src/lib/libast/features/botch.c72
-rw-r--r--src/lib/libast/features/ccode81
-rw-r--r--src/lib/libast/features/common624
-rw-r--r--src/lib/libast/features/dirent275
-rw-r--r--src/lib/libast/features/eaccess11
-rw-r--r--src/lib/libast/features/errno31
-rw-r--r--src/lib/libast/features/fcntl.c360
-rw-r--r--src/lib/libast/features/float1191
-rw-r--r--src/lib/libast/features/fs251
-rw-r--r--src/lib/libast/features/hack1
-rw-r--r--src/lib/libast/features/iconv116
-rw-r--r--src/lib/libast/features/isoc9913
-rw-r--r--src/lib/libast/features/lib664
-rw-r--r--src/lib/libast/features/libpath.sh73
-rw-r--r--src/lib/libast/features/limits.c339
-rw-r--r--src/lib/libast/features/locale28
-rw-r--r--src/lib/libast/features/map.c565
-rw-r--r--src/lib/libast/features/mmap342
-rw-r--r--src/lib/libast/features/mode.c218
-rw-r--r--src/lib/libast/features/ndbm29
-rw-r--r--src/lib/libast/features/nl_types64
-rw-r--r--src/lib/libast/features/omitted110
-rw-r--r--src/lib/libast/features/options1
-rw-r--r--src/lib/libast/features/param.sh47
-rw-r--r--src/lib/libast/features/preroot.sh46
-rw-r--r--src/lib/libast/features/prog12
-rw-r--r--src/lib/libast/features/sfinit.c94
-rw-r--r--src/lib/libast/features/sfio170
-rw-r--r--src/lib/libast/features/sig.sh132
-rw-r--r--src/lib/libast/features/siglist14
-rw-r--r--src/lib/libast/features/signal.c371
-rw-r--r--src/lib/libast/features/sizeof13
-rw-r--r--src/lib/libast/features/standards153
-rw-r--r--src/lib/libast/features/stdio568
-rw-r--r--src/lib/libast/features/sys272
-rw-r--r--src/lib/libast/features/syscall18
-rw-r--r--src/lib/libast/features/time46
-rw-r--r--src/lib/libast/features/tmlib45
-rw-r--r--src/lib/libast/features/tmx106
-rw-r--r--src/lib/libast/features/tty127
-rw-r--r--src/lib/libast/features/tv81
-rw-r--r--src/lib/libast/features/tvlib80
-rw-r--r--src/lib/libast/features/uwin10
-rw-r--r--src/lib/libast/features/vfork13
-rw-r--r--src/lib/libast/features/vmalloc220
-rw-r--r--src/lib/libast/features/wait9
-rw-r--r--src/lib/libast/features/wchar158
-rw-r--r--src/lib/libast/features/wctype14
51 files changed, 9148 insertions, 0 deletions
diff --git a/src/lib/libast/features/align.c b/src/lib/libast/features/align.c
new file mode 100644
index 0000000..e2c97c8
--- /dev/null
+++ b/src/lib/libast/features/align.c
@@ -0,0 +1,188 @@
+/***********************************************************************
+* *
+* This software is part of the ast package *
+* Copyright (c) 1985-2011 AT&T Intellectual Property *
+* and is licensed under the *
+* Eclipse Public License, Version 1.0 *
+* by AT&T Intellectual Property *
+* *
+* A copy of the License is available at *
+* http://www.eclipse.org/org/documents/epl-v10.html *
+* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
+* *
+* Information and Software Systems Research *
+* AT&T Research *
+* Florham Park NJ *
+* *
+* Glenn Fowler <gsf@research.att.com> *
+* David Korn <dgk@research.att.com> *
+* Phong Vo <kpv@research.att.com> *
+* *
+***********************************************************************/
+#pragma prototyped
+/*
+ * Glenn Fowler
+ * AT&T Bell Laboratories
+ *
+ * generate align features
+ *
+ * NOTE: two's complement binary integral representation assumed
+ */
+
+#include "FEATURE/common"
+
+#include <setjmp.h>
+
+union _u_
+{
+ long u1;
+ char* u2;
+ double u3;
+ char u4[1024];
+ intmax_t u5;
+ uintmax_t u6;
+ _ast_fltmax_t u7;
+ void* u8;
+ char* (*u9)();
+ jmp_buf u10;
+};
+
+struct _s_
+{
+ char s1;
+ union _u_ s2;
+};
+
+#define roundof(x,y) (((x)+((y)-1))&~((y)-1))
+
+static union _u_ u;
+static union _u_ v;
+
+int
+main()
+{
+ register int i;
+ register int j;
+ register int k;
+
+ int align0;
+ int align1;
+ int align2;
+ unsigned long bit1;
+ unsigned long bit2;
+ unsigned long bits0;
+ unsigned long bits1;
+ unsigned long bits2;
+
+ u.u2 = u.u4;
+ v.u2 = u.u2 + 1;
+ bit1 = u.u1 ^ v.u1;
+ v.u2 = u.u2 + 2;
+ bit2 = u.u1 ^ v.u1;
+ align0 = sizeof(struct _s_) - sizeof(union _u_);
+ bits0 = 0;
+ k = 0;
+ for (j = 0; j < align0; j++)
+ {
+ u.u2 = u.u4 + j;
+ bits1 = 0;
+ for (i = 0; i < align0; i++)
+ {
+ v.u2 = u.u2 + i;
+ bits1 |= u.u1 ^ v.u1;
+ }
+ if (!bits0 || bits1 < bits0)
+ {
+ bits0 = bits1;
+ k = j;
+ }
+ }
+ align1 = roundof(align0, 2);
+ u.u2 = u.u4 + k;
+ for (bits1 = bits0; i < align1; i++)
+ {
+ v.u2 = u.u2 + i;
+ bits1 |= u.u1 ^ v.u1;
+ }
+ align2 = roundof(align0, 4);
+ for (bits2 = bits1; i < align2; i++)
+ {
+ v.u2 = u.u2 + i;
+ bits2 |= u.u1 ^ v.u1;
+ }
+ printf("\n");
+ printf("#define ALIGN_CHUNK %d\n", sizeof(char*) >= 4 ? 8192 : 1024);
+ printf("#define ALIGN_INTEGRAL uintptr_t\n");
+ printf("#define ALIGN_INTEGER(x) ((char*)(x)-(char*)0)\n");
+ printf("#define ALIGN_POINTER(x) ((char*)(x))\n");
+ if (bits2 == (align2 - 1))
+ printf("#define ALIGN_ROUND(x,y) ALIGN_POINTER(ALIGN_INTEGER((x)+(y)-1)&~((y)-1))\n");
+ else
+ printf("#define ALIGN_ROUND(x,y) ALIGN_POINTER(ALIGN_INTEGER(ALIGN_ALIGN(x)+(((y)+%d)/%d)-1)&~((((y)+%d)/%d)-1))\n", align0, align0, align0, align0);
+ printf("\n");
+ if (align0 == align2)
+ {
+ printf("#define ALIGN_BOUND ALIGN_BOUND2\n");
+ printf("#define ALIGN_ALIGN(x) ALIGN_ALIGN2(x)\n");
+ printf("#define ALIGN_TRUNC(x) ALIGN_TRUNC2(x)\n");
+ }
+ else if (align0 == align1)
+ {
+ printf("#define ALIGN_BOUND ALIGN_BOUND1\n");
+ printf("#define ALIGN_ALIGN(x) ALIGN_ALIGN1(x)\n");
+ printf("#define ALIGN_TRUNC(x) ALIGN_TRUNC1(x)\n");
+ }
+ else
+ {
+ printf("#define ALIGN_BOUND 1\n");
+ printf("#define ALIGN_ALIGN(x) ALIGN_POINTER(x)\n");
+ printf("#define ALIGN_TRUNC(x) ALIGN_POINTER(x)\n");
+ }
+ printf("\n");
+ printf("#define ALIGN_BIT1 0x%lx\n", bit1);
+ if (align1 == align2)
+ {
+ printf("#define ALIGN_BOUND1 ALIGN_BOUND2\n");
+ printf("#define ALIGN_ALIGN1(x) ALIGN_ALIGN2(x)\n");
+ printf("#define ALIGN_TRUNC1(x) ALIGN_TRUNC2(x)\n");
+ }
+ else
+ {
+ printf("#define ALIGN_BOUND1 %d\n", align1);
+ printf("#define ALIGN_ALIGN1(x) ALIGN_TRUNC1((x)+%d)\n", align1 - 1);
+ printf("#define ALIGN_TRUNC1(x) ALIGN_POINTER(ALIGN_INTEGER((x)+%d)&0x%lx)\n", align1 - 1, ~(bits0|bits1));
+ }
+#if _X86_ || _X64_
+ printf("#if _X64_\n");
+ printf("#define ALIGN_CLRBIT1(x) ALIGN_POINTER(ALIGN_INTEGER(x)&0xfffffffffffffffeULL)\n");
+ printf("#else\n");
+ printf("#define ALIGN_CLRBIT1(x) ALIGN_POINTER(ALIGN_INTEGER(x)&0xfffffffe)\n");
+ printf("#endif\n");
+#else
+ printf("#define ALIGN_CLRBIT1(x) ALIGN_POINTER(ALIGN_INTEGER(x)&0x%lx)\n", ~bit1);
+#endif
+ printf("#define ALIGN_SETBIT1(x) ALIGN_POINTER(ALIGN_INTEGER(x)|0x%lx)\n", bit1);
+ printf("#define ALIGN_TSTBIT1(x) ALIGN_POINTER(ALIGN_INTEGER(x)&0x%lx)\n", bit1);
+ printf("\n");
+ printf("#define ALIGN_BIT2 0x%lx\n", bit2);
+#if _X86_ || _X64_
+ printf("#if _X64_\n");
+ printf("#define ALIGN_BOUND2 16\n");
+ printf("#define ALIGN_ALIGN2(x) ALIGN_TRUNC2((x)+15)\n");
+ printf("#define ALIGN_TRUNC2(x) ALIGN_POINTER(ALIGN_INTEGER(x)&0xfffffffffffffffeULL)\n");
+ printf("#else\n");
+ printf("#define ALIGN_BOUND2 8\n");
+ printf("#define ALIGN_ALIGN2(x) ALIGN_TRUNC2((x)+7)\n");
+ printf("#define ALIGN_TRUNC2(x) ALIGN_POINTER(ALIGN_INTEGER(x)&0xfffffff8)\n");
+ printf("#endif\n");
+#else
+ printf("#define ALIGN_BOUND2 %d\n", align2);
+ printf("#define ALIGN_ALIGN2(x) ALIGN_TRUNC2((x)+%d)\n", align2 - 1);
+ printf("#define ALIGN_TRUNC2(x) ALIGN_POINTER(ALIGN_INTEGER(x)&0x%lx)\n", ~(bits0|bits1|bits2));
+#endif
+ printf("#define ALIGN_CLRBIT2(x) ALIGN_POINTER(ALIGN_INTEGER(x)&0x%lx)\n", ~bit2);
+ printf("#define ALIGN_SETBIT2(x) ALIGN_POINTER(ALIGN_INTEGER(x)|0x%lx)\n", bit2);
+ printf("#define ALIGN_TSTBIT2(x) ALIGN_POINTER(ALIGN_INTEGER(x)&0x%lx)\n", bit2);
+ printf("\n");
+ return 0;
+}
diff --git a/src/lib/libast/features/api b/src/lib/libast/features/api
new file mode 100644
index 0000000..acfcd71
--- /dev/null
+++ b/src/lib/libast/features/api
@@ -0,0 +1,11 @@
+iff AST_API
+
+ver ast 20110505
+
+api ast 20110505 cmdopen
+
+api ast 20100601 pathaccess pathcanon pathcat pathkey pathpath pathprobe pathrepl
+
+api ast 20000308 sfkeyprintf
+
+print #define _AST_VERSION AST_VERSION /* pre-20100601 compatibility */
diff --git a/src/lib/libast/features/aso b/src/lib/libast/features/aso
new file mode 100644
index 0000000..2b7f01a
--- /dev/null
+++ b/src/lib/libast/features/aso
@@ -0,0 +1,671 @@
+# ast atomic scalar operations feature tests
+
+if aso note{ gcc 4.1+ 64 bit memory atomic operations model }end link{
+ #include "FEATURE/common"
+ int main()
+ {
+ uint64_t i = 0;
+ return __sync_fetch_and_add(&i,7);
+ }
+ }end && {
+ #define _aso_cas8(p,o,n) __sync_val_compare_and_swap(p,o,n)
+ #define _aso_inc8(p) __sync_fetch_and_add(p,1)
+ #define _aso_dec8(p) __sync_fetch_and_sub(p,1)
+ #define _aso_cas16(p,o,n) __sync_val_compare_and_swap(p,o,n)
+ #define _aso_inc16(p) __sync_fetch_and_add(p,1)
+ #define _aso_dec16(p) __sync_fetch_and_sub(p,1)
+ #define _aso_cas32(p,o,n) __sync_val_compare_and_swap(p,o,n)
+ #define _aso_inc32(p) __sync_fetch_and_add(p,1)
+ #define _aso_dec32(p) __sync_fetch_and_sub(p,1)
+ #define _aso_cas64(p,o,n) __sync_val_compare_and_swap(p,o,n)
+ #define _aso_inc64(p) __sync_fetch_and_add(p,1)
+ #define _aso_dec64(p) __sync_fetch_and_sub(p,1)
+ #if _ast_sizeof_pointer == 8
+ #define _aso_casptr(p,o,n) ((void*)__sync_val_compare_and_swap(p,(uint64_t)o,(uint64_t)n))
+ #else
+ #define _aso_casptr(p,o,n) ((void*)__sync_val_compare_and_swap(p,(uint32_t)o,(uint32_t)n))
+ #endif
+ }
+elif aso note{ gcc 4.1+ 32 bit memory atomic operations model }end link{
+ #include "FEATURE/common"
+ int main()
+ {
+ uint32_t i = 0;
+ return __sync_fetch_and_add(&i,7);
+ }
+ }end && {
+ #define _aso_cas8(p,o,n) __sync_val_compare_and_swap(p,o,n)
+ #define _aso_inc8(p) __sync_fetch_and_add(p,1)
+ #define _aso_dec8(p) __sync_fetch_and_sub(p,1)
+ #define _aso_cas16(p,o,n) __sync_val_compare_and_swap(p,o,n)
+ #define _aso_inc16(p) __sync_fetch_and_add(p,1)
+ #define _aso_dec16(p) __sync_fetch_and_sub(p,1)
+ #define _aso_cas32(p,o,n) __sync_val_compare_and_swap(p,o,n)
+ #define _aso_inc32(p) __sync_fetch_and_add(p,1)
+ #define _aso_dec32(p) __sync_fetch_and_sub(p,1)
+ #define _aso_casptr(p,o,n) ((void*)__sync_val_compare_and_swap(p,(uint32_t)o,(uint32_t)n))
+ }
+elif aso note{ <atomic.h> atomic_cas_64 }end link{
+ #include "FEATURE/common"
+ #include <atomic.h>
+ int main()
+ {
+ uint64_t i = 0;
+ uint32_t j = 1;
+ return atomic_cas_64(&i, 0, 1) != 0 || atomic_add_32_nv(&j, 1) != 1;
+ }
+ }end && {
+ #include <atomic.h>
+ #define _aso_cas8(p,o,n) atomic_cas_8(p,o,n)
+ #define _aso_inc8(p) (atomic_add_8_nv(p,1)-1)
+ #define _aso_dec8(p) (atomic_add_8_nv(p,-1)+1)
+ #define _aso_cas16(p,o,n) atomic_cas_16(p,o,n)
+ #define _aso_inc16(p) (atomic_add_16_nv(p,1)-1)
+ #define _aso_dec16(p) (atomic_add_16_nv(p,-1)+1)
+ #define _aso_cas32(p,o,n) atomic_cas_32(p,o,n)
+ #define _aso_inc32(p) (atomic_add_32_nv(p,1)-1)
+ #define _aso_dec32(p) (atomic_add_32_nv(p,-1)+1)
+ #define _aso_cas64(p,o,n) atomic_cas_64(p,o,n)
+ #define _aso_inc64(p) (atomic_add_64_nv(p,1)-1)
+ #define _aso_dec64(p) (atomic_add_64_nv(p,-1)+1)
+ #if _ast_sizeof_pointer == 8
+ #define _aso_casptr(p,o,n) ((void*)atomic_cas_64((uint64_t*)p,(uint64_t)o,(uint64_t)n))
+ #else
+ #define _aso_casptr(p,o,n) ((void*)atomic_cas_32((uint32_t*)p,(uint32_t)o,(uint32_t)n))
+ #endif
+ }
+elif aso note{ <atomic.h> atomic_cas_32 }end link{
+ #include "FEATURE/common"
+ #include <atomic.h>
+ int main()
+ {
+ uint32_t i = 0;
+ return atomic_cas_32(&i, 0, 1) != 0 || (atomic_add_32_nv(&i, 1) - 1) != 1;
+ }
+ }end && {
+ #include <atomic.h>
+ #define _aso_cas8(p,o,n) atomic_cas_8(p,o,n)
+ #define _aso_inc8(p) (atomic_add_8_nv(p,1)-1)
+ #define _aso_dec8(p) (atomic_add_8_nv(p,-1)+1)
+ #define _aso_cas16(p,o,n) atomic_cas_16(p,o,n)
+ #define _aso_inc16(p) (atomic_add_16_nv(p,1)-1)
+ #define _aso_dec16(p) (atomic_add_16_nv(p,-1)+1)
+ #define _aso_cas32(p,o,n) atomic_cas_32(p,o,n)
+ #define _aso_inc32(p) (atomic_add_32_nv(p,1)-1)
+ #define _aso_dec32(p) (atomic_add_32_nv(p,-1)+1)
+ #define _aso_casptr(p,o,n) ((void*)atomic_cas_32((uint32_t*)p,(uint32_t)o,(uint32_t)n))
+ }
+elif aso -latomic note{ <atomic.h> atomic_cas_64 with -latomic }end link{
+ #include "FEATURE/common"
+ #include <atomic.h>
+ int main()
+ {
+ uint64_t i = 0;
+ uint32_t j = 1;
+ return atomic_cas_64(&i, 0, 1) != 0 || (atomic_add_32_nv(&j, 1) - 1) != 1;
+ }
+ }end && {
+ #include <atomic.h>
+ #define _REQ_atomic
+ #define _aso_cas8(p,o,n) atomic_cas_8(p,o,n)
+ #define _aso_inc8(p) (atomic_add_8_nv(p,1)-1)
+ #define _aso_dec8(p) (atomic_add_8_nv(p,-1)+1)
+ #define _aso_cas16(p,o,n) atomic_cas_16(p,o,n)
+ #define _aso_inc16(p) (atomic_add_16_nv(p,1)-1)
+ #define _aso_dec16(p) (atomic_add_16_nv(p,-1)+1)
+ #define _aso_cas32(p,o,n) atomic_cas_32(p,o,n)
+ #define _aso_inc32(p) (atomic_add_32_nv(p,1)-1)
+ #define _aso_dec32(p) (atomic_add_32_nv(p,-1)+1)
+ #define _aso_cas64(p,o,n) atomic_cas_64(p,o,n)
+ #define _aso_inc64(p) (atomic_add_64_nv(p,1)-1)
+ #define _aso_dec64(p) (atomic_add_64_nv(p,-1)+1)
+ #if _ast_sizeof_pointer == 8
+ #define _aso_casptr(p,o,n) ((void*)atomic_cas_64((uint64_t*)p,(uint64_t)o,(uint64_t)n))
+ #else
+ #define _aso_casptr(p,o,n) ((void*)atomic_cas_32((uint32_t*)p,(uint32_t)o,(uint32_t)n))
+ #endif
+ }
+elif aso note{ <atomic.h> atomic_cas_32 with -latomic }end link{
+ #include "FEATURE/common"
+ #include <atomic.h>
+ int main()
+ {
+ uint32_t i = 0;
+ return atomic_cas_32(&i, 0, 1) != 0 || (atomic_add_32_nv(&i, 1) - 1) != 1;
+ }
+ }end && {
+ #include <atomic.h>
+ #define _REQ_atomic
+ #define _aso_cas8(p,o,n) atomic_cas_8(p,o,n)
+ #define _aso_inc8(p) (atomic_add_8_nv(p,1)-1)
+ #define _aso_dec8(p) (atomic_add_8_nv(p,-1)+1)
+ #define _aso_cas16(p,o,n) atomic_cas_16(p,o,n)
+ #define _aso_inc16(p) (atomic_add_16_nv(p,1)-1)
+ #define _aso_dec16(p) (atomic_add_16_nv(p,-1)+1)
+ #define _aso_cas32(p,o,n) atomic_cas_32(p,o,n)
+ #define _aso_inc32(p) (atomic_add_32_nv(p,1)-1)
+ #define _aso_dec32(p) (atomic_add_32_nv(p,-1)+1)
+ #define _aso_casptr(p,o,n) ((void*)atomic_cas_32((uint32_t*)p,(uint32_t)o,(uint32_t)n))
+ }
+elif aso note{ <atomic.h> cas64 }end link{
+ #include "FEATURE/common"
+ #include <atomic.h>
+ int main()
+ {
+ uint64_t i = 0;
+ uint32_t j = 1;
+ return cas64(&i, 0, 1) != 0 || (atomic_add_32_nv(&j, 1) - 1) != 1;
+ }
+ }end && {
+ #include <atomic.h>
+ #define _aso_cas8(p,o,n) cas8(p,o,n)
+ #define _aso_inc8(p) (atomic_add_8_nv(p,1)-1)
+ #define _aso_dec8(p) (atomic_add_8_nv(p,-1)+1)
+ #define _aso_cas16(p,o,n) cas16(p,o,n)
+ #define _aso_inc16(p) (atomic_add_16_nv(p,1)-1)
+ #define _aso_dec16(p) (atomic_add_16_nv(p,-1)+1)
+ #define _aso_cas32(p,o,n) cas32(p,o,n)
+ #define _aso_inc32(p) (atomic_add_32_nv(p,1)-1)
+ #define _aso_dec32(p) (atomic_add_32_nv(p,-1)+1)
+ #define _aso_cas64(p,o,n) cas64(p,o,n)
+ #define _aso_inc64(p) (atomic_add_64_nv(p,1)-1)
+ #define _aso_dec64(p) (atomic_add_64_nv(p,-1)+1)
+ #if _ast_sizeof_pointer == 8
+ #define _aso_casptr(p,o,n) ((void*)cas64((uint64_t*)p,(uint64_t)o,(uint64_t)n))
+ #else
+ #define _aso_casptr(p,o,n) ((void*)cas32((uint32_t*)p,(uint32_t)o,(uint32_t)n))
+ #endif
+ }
+elif aso note{ <atomic.h> just cas64 }end link{
+ #include "FEATURE/common"
+ #include <atomic.h>
+ int main()
+ {
+ uint64_t i = 0;
+ uint32_t j = 1;
+ uint16_t k = 1;
+ uint8_t l = 1;
+ return cas64(&i, 0, 1) != 0 || cas32(&j, 0, 1) != 0 || cas16(&k, 0, 1) != 0 || cas8(&l, 0, 1) != 0;
+ }
+ }end && {
+ #include <atomic.h>
+ #define _aso_cas8(p,o,n) cas8(p,o,n)
+ #define _aso_cas16(p,o,n) cas16(p,o,n)
+ #define _aso_cas32(p,o,n) cas32(p,o,n)
+ #define _aso_cas64(p,o,n) cas64(p,o,n)
+ #if _ast_sizeof_pointer == 8
+ #define _aso_casptr(p,o,n) ((void*)cas64((uint64_t*)p,(uint64_t)o,(uint64_t)n))
+ #else
+ #define _aso_casptr(p,o,n) ((void*)cas32((uint32_t*)p,(uint32_t)o,(uint32_t)n))
+ #endif
+ }
+elif aso note{ <atomic.h> cas32 }end link{
+ #include "FEATURE/common"
+ #include <atomic.h>
+ int main()
+ {
+ uint32_t i = 0;
+ return cas32(&i, 0, 1) != 0 || (atomic_add_32_nv(&i, 1) - 1) != 1;
+ }
+ }end && {
+ #include <atomic.h>
+ #define _aso_cas8(p,o,n) cas8(p,o,n)
+ #define _aso_inc8(p) (atomic_add_8_nv(p,1)-1)
+ #define _aso_dec8(p) (atomic_add_8_nv(p,-1)+1)
+ #define _aso_cas16(p,o,n) cas16(p,o,n)
+ #define _aso_inc16(p) (atomic_add_16_nv(p,1)-1)
+ #define _aso_dec16(p) (atomic_add_16_nv(p,-1)+1)
+ #define _aso_cas32(p,o,n) cas32(p,o,n)
+ #define _aso_inc32(p) (atomic_add_32_nv(p,1)-1)
+ #define _aso_dec32(p) (atomic_add_32_nv(p,-1)+1)
+ #define _aso_casptr(p,o,n) ((void*)cas32((uint32_t*)p,(uint32_t)o,(uint32_t)n))
+ }
+elif aso note{ <atomic.h> just cas32 }end link{
+ #include "FEATURE/common"
+ #include <atomic.h>
+ int main()
+ {
+ uint32_t j = 1;
+ uint16_t k = 1;
+ uint8_t l = 1;
+ return cas32(&j, 0, 1) != 0 || cas16(&k, 0, 1) != 0 || cas8(&l, 0, 1) != 0;
+ }
+ }end && {
+ #include <atomic.h>
+ #define _aso_cas8(p,o,n) cas8(p,o,n)
+ #define _aso_cas16(p,o,n) cas16(p,o,n)
+ #define _aso_cas32(p,o,n) cas32(p,o,n)
+ #define _aso_casptr(p,o,n) ((void*)cas32((uint32_t*)p,(uint32_t)o,(uint32_t)n))
+ }
+elif aso note{ winix Interlocked }end link{
+ #include <windows.h>
+ int main()
+ {
+ LONG i = 0;
+ LONGLONG j = 0;
+ return InterlockedCompareExchange(&i, 1, 0) != 0 ||
+ InterlockedIncrement(&i) != 1 ||
+ InterlockedDecrement(&i) != 2;
+ }
+ }end && {
+ #include <ast_windows.h>
+ #define _aso_cas32(p,o,n) InterlockedCompareExchange((LONG volatile*)p,n,o)
+ #define _aso_inc32(p) (InterlockedIncrement((LONG volatile*)p)-1)
+ #define _aso_dec32(p) (InterlockedDecrement((LONG volatile*)p)+1)
+ #if _X64
+ #define _aso_cas64(p,o,n) InterlockedCompareExchange64((LONGLONG volatile*)p,n,o)
+ #define _aso_inc64(p) (InterlockedIncrement64((LONGLONG volatile*)p)-1)
+ #define _aso_dec64(p) (InterlockedDecrement64((LONGLONG volatile*)p)+1)
+ #define _aso_casptr(p,o,n) ((void*)InterlockedCompareExchange64((LONGLONG volatile*)p,(LONGLONG)n,(LONGLONG)o))
+ #else
+ #if _BLD_posix
+ #include "dl.h"
+ typedef struct LL_s
+ {
+ LONG a;
+ LONG b;
+ } LL_t;
+ typedef union
+ {
+ LONGLONG i;
+ LL_t ll;
+ } LL_u;
+
+ #define _aso_cas64(p,o,n) _aso_InterlockedCompareExchange64((LONGLONG volatile*)p,n,o)
+ static LONGLONG _aso_InterlockedCompareExchange64_init(LONGLONG volatile*, LONGLONG, LONGLONG);
+ typedef LONGLONG (*_aso_InterlockedCompareExchange64_f)(LONGLONG volatile*, LONGLONG, LONGLONG);
+ static _aso_InterlockedCompareExchange64_f _aso_InterlockedCompareExchange64 = _aso_InterlockedCompareExchange64_init;
+ static LONGLONG _aso_InterlockedCompareExchange64_32(LONGLONG volatile* p, LONGLONG o, LONGLONG n)
+ {
+ LL_t* lp = (LL_t*)p;
+ LL_t* op = (LL_t*)&o;
+ LL_t* np = (LL_t*)&n;
+ LONGLONG r;
+
+ r = *p;
+ if (_aso_cas32(&lp->a, op->a, np->a) == op->a)
+ {
+ if (_aso_cas32(&lp->b, op->b, np->b) == op->b)
+ return o;
+ _aso_cas32(&lp->a, np->a, op->a);
+ }
+ return r;
+ }
+ static LONGLONG _aso_InterlockedCompareExchange64_init(LONGLONG volatile* p, LONGLONG o, LONGLONG n)
+ {
+ if (!(_aso_InterlockedCompareExchange64 = (_aso_InterlockedCompareExchange64_f)getsymbol(MODULE_kernel, "InterlockedCompareExchange64")))
+ _aso_InterlockedCompareExchange64 = _aso_InterlockedCompareExchange64_32;
+ return _aso_InterlockedCompareExchange64(p, o, n);
+ }
+
+ #define _aso_inc64(p) (_aso_InterlockedIncrement64((LONGLONG volatile*)p)-1)
+ typedef LONGLONG (*_aso_InterlockedIncrement64_f)(LONGLONG volatile*);
+ static LONGLONG _aso_InterlockedIncrement64_init(LONGLONG volatile*);
+ static _aso_InterlockedIncrement64_f _aso_InterlockedIncrement64 = _aso_InterlockedIncrement64_init;
+ static LONGLONG _aso_InterlockedIncrement64_32(LONGLONG volatile* p)
+ {
+ LONGLONG o;
+
+ do
+ {
+ o = *p;
+ } while (_aso_InterlockedCompareExchange64_32(p, o, o + 1) != o);
+ return o;
+ }
+ static LONGLONG _aso_InterlockedIncrement64_init(LONGLONG volatile* p)
+ {
+ if (!(_aso_InterlockedIncrement64 = (_aso_InterlockedIncrement64_f)getsymbol(MODULE_kernel, "InterlockedIncrement64")))
+ _aso_InterlockedIncrement64 = _aso_InterlockedIncrement64_32;
+ return _aso_InterlockedIncrement64(p);
+ }
+
+ #define _aso_dec64(p) (_aso_InterlockedDecrement64((LONGLONG volatile*)p)+1)
+ typedef LONGLONG (*_aso_InterlockedDecrement64_f)(LONGLONG volatile*);
+ static LONGLONG _aso_InterlockedDecrement64_init(LONGLONG volatile*);
+ static _aso_InterlockedDecrement64_f _aso_InterlockedDecrement64 = _aso_InterlockedDecrement64_init;
+ static LONGLONG _aso_InterlockedDecrement64_32(LONGLONG volatile* p)
+ {
+ LONGLONG o;
+
+ do
+ {
+ o = *p;
+ } while (_aso_InterlockedCompareExchange64_32(p, o, o - 1) != o);
+ return o;
+ }
+ static LONGLONG _aso_InterlockedDecrement64_init(LONGLONG volatile* p)
+ {
+ if (!(_aso_InterlockedDecrement64 = (_aso_InterlockedDecrement64_f)getsymbol(MODULE_kernel, "InterlockedDecrement64")))
+ _aso_InterlockedDecrement64 = _aso_InterlockedDecrement64_32;
+ return _aso_InterlockedDecrement64(p);
+ }
+ #endif
+ #define _aso_casptr(p,o,n) ((void*)InterlockedCompareExchange((LONG volatile*)p,(LONG)n,(LONG)o))
+ #endif
+ }
+elif aso note{ aix fetch and add }end link{
+ #include <sys/atomic_op.h>
+ int main()
+ {
+ int i = 0;
+ return fetch_and_add((atomic_p)&i,1);
+ }
+ }end && {
+ #include <sys/atomic_op.h>
+ #define _aso_incint(p) fetch_and_add((atomic_p)p,1)
+ #define _aso_decint(p) fetch_and_add((atomic_p)p,-1)
+ #define _aso_casint(p,o,n) (compare_and_swap((atomic_p)p,(int*)&o,(int)n) ? o : *p)
+ #if _ast_sizeof_pointer == 8
+ #define _aso_casptr(p,o,n) (compare_and_swaplp((atomic_l)p,(long*)&o,(long)n) ? o : *(void**)p)
+ #else
+ #define _aso_casptr(p,o,n) (compare_and_swap((atomic_p)p,(int*)&o,(int)n) ? o : *(void**)p)
+ #endif
+ }
+elif aso note{ mips compare and swap }end link{
+ int main()
+ {
+ int i = 1;
+ return __compare_and_swap(&i, 0, 1) != 1;
+ }
+ }end && {
+ #define _aso_cas32(p,o,n) (__compare_and_swap(p,o,n) ? o : *p)
+ #define _aso_casptr(p,o,n) (__compare_and_swap((long*)p,(long)o,(long)n) ? o : *(void**)p)
+ }
+elif aso note{ i386|i386-64 asm compare and swap }end link{
+ #include "FEATURE/common"
+
+ static uint32_t
+ cas32(uint32_t volatile* p, uint32_t o, uint32_t n)
+ {
+ uint32_t r;
+
+ __asm__ __volatile__ (
+ "lock ; cmpxchg %3,%4"
+ : "=a"(r), "=m"(*p)
+ : "0"(o), "q"(n), "m"(*p)
+ : "memory", "cc"
+ );
+ return r;
+ }
+
+ #if _ast_sizeof_pointer == 8
+
+ static uint64_t
+ cas64(uint64_t volatile* p, uint64_t o, uint64_t n)
+ {
+ uint64_t r;
+
+ __asm__ __volatile__ (
+ "lock ; cmpxchg %3,%4"
+ : "=a"(r), "=m"(*p)
+ : "0"(o), "q"(n), "m"(*p)
+ : "memory", "cc"
+ );
+ return r;
+ }
+
+ #else
+
+ #define cas64(p,o,n) (*(p))
+
+ #endif
+
+ int main()
+ {
+ uint32_t i = 0;
+ uint64_t j = 0;
+ return cas32(&i, 0, 1) || cas64(&j, 0, 1);
+ }
+ }end && {
+ static uint32_t
+ cas32(uint32_t volatile* p, uint32_t o, uint32_t n)
+ {
+ uint32_t r;
+
+ __asm__ __volatile__ (
+ "lock ; cmpxchg %3,%4"
+ : "=a"(r), "=m"(*p)
+ : "0"(o), "q"(n), "m"(*p)
+ : "memory", "cc"
+ );
+ return r;
+ }
+
+ #if _ast_sizeof_pointer == 8
+
+ static uint64_t
+ cas64(uint64_t volatile* p, uint64_t o, uint64_t n)
+ {
+ uint64_t r;
+
+ __asm__ __volatile__ (
+ "lock ; cmpxchg %3,%4"
+ : "=a"(r), "=m"(*p)
+ : "0"(o), "q"(n), "m"(*p)
+ : "memory", "cc"
+ );
+ return r;
+ }
+
+ #endif
+
+ #define _aso_cas32(p,o,n) cas32(p,o,n)
+ #if _ast_sizeof_pointer == 8
+ #define _aso_cas64(p,o,n) cas64(p,o,n)
+ #define _aso_casptr(p,o,n) ((void*)cas64((uint64_t*)p,(uint64_t)o,(uint64_t)n))
+ #else
+ #define _aso_casptr(p,o,n) ((void*)cas32((uint32_t*)p,(uint32_t)o,(uint32_t)n))
+ #endif
+ }
+elif aso note{ ia64 asm compare and swap }end link{
+ #include "FEATURE/common"
+
+ static uint32_t
+ cas32(uint32_t volatile* p, uint32_t o, uint32_t n)
+ {
+ uint32_t r;
+
+ __asm__ __volatile__ (
+ "zxt4 %3=%3 ;; mov ar.ccv=%3 ;; cmpxchg4.acq %0=%1,%2,ar.ccv"
+ : "=r"(r), "+S"(*p)
+ : "r"(n), "r"(o) : "memory"
+ );
+ return r;
+ }
+
+ static uint64_t
+ cas64(uint64_t volatile* p, uint64_t o, uint64_t n)
+ {
+ uint64_t r;
+
+ __asm__ __volatile__ (
+ "mov ar.ccv=%3 ;; cmpxchg8.acq %0=%1,%2,ar.ccv"
+ : "=r"(r), "+S"(*p)
+ : "r"(n), "r"(o) : "memory"
+ );
+ return r;
+ }
+
+ int main()
+ {
+ uint32_t i = 0;
+ uint64_t j = 0;
+ return cas32(&i, 0, 1) || cas64(&j, 0, 1);
+ }
+ }end && {
+ static uint32_t
+ cas32(uint32_t volatile* p, uint32_t o, uint32_t n)
+ {
+ uint32_t r;
+
+ __asm__ __volatile__ (
+ "zxt4 %3=%3 ;; mov ar.ccv=%3 ;; cmpxchg4.acq %0=%1,%2,ar.ccv"
+ : "=r"(r), "+S"(*p)
+ : "r"(n), "r"(o) : "memory"
+ );
+ return r;
+ }
+
+ static uint64_t
+ cas64(uint64_t volatile* p, uint64_t o, uint64_t n)
+ {
+ uint64_t r;
+
+ __asm__ __volatile__ (
+ "mov ar.ccv=%3 ;; cmpxchg8.acq %0=%1,%2,ar.ccv"
+ : "=r"(r), "+S"(*p)
+ : "r"(n), "r"(o) : "memory"
+ );
+ return r;
+ }
+
+ #define _aso_cas32(p,o,n) cas32(p,o,n)
+ #define _aso_cas64(p,o,n) cas64(p,o,n)
+ #if _ast_sizeof_pointer == 8
+ #define _aso_casptr(p,o,n) ((void*)cas64((uint64_t*)p,(uint64_t)o,(uint64_t)n))
+ #else
+ #define _aso_casptr(p,o,n) ((void*)cas32((uint32_t*)p,(uint32_t)o,(uint32_t)n))
+ #endif
+ }
+elif aso note{ ppc asm compare and swap }end link{
+ #include "FEATURE/common"
+
+ static uint32_t
+ cas32(uint32_t volatile* p, uint32_t o, uint32_t n)
+ {
+ int r;
+
+ __asm__ __volatile__ (
+ "0: lwarx %0,0,%1 ;"
+ " xor. %0,%3,%0;"
+ " bne 1f;"
+ " stwcx. %2,0,%1;"
+ " bne- 0b;"
+ "1:"
+ : "=&r"(r)
+ : "r"(p), "r"(n), "r"(o)
+ : "cr0", "memory"
+ );
+ __asm__ __volatile__ ("isync" : : : "memory");
+ return r ? *p : o;
+ }
+
+ static uint64_t
+ cas64(uint64_t volatile* p, uint64_t o, uint64_t n)
+ {
+ long r;
+
+ __asm__ __volatile__ (
+ "0: ldarx %0,0,%1 ;"
+ " xor. %0,%3,%0;"
+ " bne 1f;"
+ " stdcx. %2,0,%1;"
+ " bne- 0b;"
+ "1:"
+ : "=&r"(r)
+ : "r"(p), "r"(n), "r"(o)
+ : "cr0", "memory"
+ );
+ __asm__ __volatile__ ("isync" : : : "memory");
+ return r ? *p : o;
+ }
+
+ int main()
+ {
+ uint32_t i = 0;
+ uint64_t j = 0;
+ return cas32(&i, 0, 1) || cas64(&j, 0, 1);
+ }
+ }end && {
+ static uint32_t
+ cas32(uint32_t volatile* p, uint32_t o, uint32_t n)
+ {
+ int r;
+
+ __asm__ __volatile__ (
+ "0: lwarx %0,0,%1 ;"
+ " xor. %0,%3,%0;"
+ " bne 1f;"
+ " stwcx. %2,0,%1;"
+ " bne- 0b;"
+ "1:"
+ : "=&r"(r)
+ : "r"(p), "r"(n), "r"(o)
+ : "cr0", "memory"
+ );
+ __asm__ __volatile__ ("isync" : : : "memory");
+ return r ? *p : o;
+ }
+
+ static uint64_t
+ cas64(uint64_t volatile* p, uint64_t o, uint64_t n)
+ {
+ long r;
+
+ __asm__ __volatile__ (
+ "0: ldarx %0,0,%1 ;"
+ " xor. %0,%3,%0;"
+ " bne 1f;"
+ " stdcx. %2,0,%1;"
+ " bne- 0b;"
+ "1:"
+ : "=&r"(r)
+ : "r"(p), "r"(n), "r"(o)
+ : "cr0", "memory"
+ );
+ __asm__ __volatile__ ("isync" : : : "memory");
+ return r ? *p : o;
+ }
+
+ #define _aso_cas32(p,o,n) cas32(p,o,n)
+ #define _aso_cas64(p,o,n) cas64(p,o,n)
+ #if _ast_sizeof_pointer == 8
+ #define _aso_casptr(p,o,n) ((void*)cas64((uint64_t*)p,(uint64_t)o,(uint64_t)n))
+ #else
+ #define _aso_casptr(p,o,n) ((void*)cas32((uint32_t*)p,(uint32_t)o,(uint32_t)n))
+ #endif
+ }
+endif
+
+aso fcntl note{ fcntl(F_SETLCK[W]) work }end link{
+ #include <sys/types.h>
+ #include <unistd.h>
+ #include <fcntl.h>
+
+ int main()
+ {
+ struct flock lock;
+
+ lock.l_type = F_WRLCK;
+ lock.l_whence = SEEK_SET;
+ lock.l_start = 0;
+ lock.l_len = 1;
+ return fcntl(1, F_SETLKW, &lock) < 0;
+ }
+}end
+
+aso semaphore note{ semget semop semctl work }end link{
+ #include <sys/types.h>
+ #include <sys/stat.h>
+ #include <unistd.h>
+ #include <fcntl.h>
+ #include <sys/ipc.h>
+ #include <sys/sem.h>
+
+ int main()
+ {
+ int id;
+ struct sembuf sem;
+
+ if ((id = semget(IPC_PRIVATE, 16, IPC_CREAT|IPC_EXCL|S_IRUSR|S_IWUSR)) < 0)
+ return 1;
+ sem.sem_num = 0;
+ sem.sem_op = 1;
+ sem.sem_flg = 0;
+ if (semop(id, &sem, 1) < 0)
+ return 1;
+ if (semctl(id, 0, IPC_RMID) < 0)
+ return 1;
+ return 0;
+ }
+}end
diff --git a/src/lib/libast/features/botch.c b/src/lib/libast/features/botch.c
new file mode 100644
index 0000000..d30547d
--- /dev/null
+++ b/src/lib/libast/features/botch.c
@@ -0,0 +1,72 @@
+/***********************************************************************
+* *
+* This software is part of the ast package *
+* Copyright (c) 1985-2011 AT&T Intellectual Property *
+* and is licensed under the *
+* Eclipse Public License, Version 1.0 *
+* by AT&T Intellectual Property *
+* *
+* A copy of the License is available at *
+* http://www.eclipse.org/org/documents/epl-v10.html *
+* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
+* *
+* Information and Software Systems Research *
+* AT&T Research *
+* Florham Park NJ *
+* *
+* Glenn Fowler <gsf@research.att.com> *
+* David Korn <dgk@research.att.com> *
+* Phong Vo <kpv@research.att.com> *
+* *
+***********************************************************************/
+#pragma prototyped
+/*
+ * Glenn Fowler
+ * AT&T Bell Laboratories
+ *
+ * generate ast traps for botched standard prototypes
+ */
+
+#include <sys/types.h>
+
+#include "FEATURE/lib"
+#include "FEATURE/sys"
+
+#if _lib_getgroups
+extern int getgroups(int, gid_t*);
+#endif
+
+int
+main()
+{
+#if _lib_getgroups
+ if (sizeof(int) > sizeof(gid_t))
+ {
+ int n;
+ int i;
+ int r;
+ gid_t groups[32 * sizeof(int) / sizeof(gid_t)];
+
+ r = sizeof(int) / sizeof(gid_t);
+ if ((n = getgroups((sizeof(groups) / sizeof(groups[0])) / r, groups)) > 0)
+ for (i = 1; i <= n; i++)
+ {
+ groups[i] = ((gid_t)0);
+ if (getgroups(i, groups) != i)
+ goto botched;
+ if (groups[i] != ((gid_t)0))
+ goto botched;
+ groups[i] = ((gid_t)-1);
+ if (getgroups(i, groups) != i)
+ goto botched;
+ if (groups[i] != ((gid_t)-1))
+ goto botched;
+ }
+ }
+ return 0;
+ botched:
+ printf("#undef getgroups\n");
+ printf("#define getgroups _ast_getgroups /* implementation botches gid_t* arg */\n");
+#endif
+ return 0;
+}
diff --git a/src/lib/libast/features/ccode b/src/lib/libast/features/ccode
new file mode 100644
index 0000000..0175763
--- /dev/null
+++ b/src/lib/libast/features/ccode
@@ -0,0 +1,81 @@
+tst output{
+ int main()
+ {
+ printf("\n");
+ printf("#define CC_ASCII 1 /* ISO-8859-1 */\n");
+ printf("#define CC_EBCDIC_E 2 /* Xopen dd(1) EBCDIC */\n");
+ printf("#define CC_EBCDIC_I 3 /* Xopen dd(1) IBM */\n");
+ printf("#define CC_EBCDIC_O 4 /* IBM-1047 mvs OpenEdition */\n");
+ printf("#define CC_EBCDIC_S 5 /* Siemens posix-bc */\n");
+ printf("#define CC_EBCDIC_H 6 /* IBM-37 AS/400 */\n");
+ printf("#define CC_EBCDIC_M 7 /* IBM mvs cobol */\n");
+ printf("#define CC_EBCDIC_U 8 /* microfocus cobol */\n");
+ printf("\n");
+ printf("#define CC_MAPS 8 /* number of code maps */\n");
+ printf("\n");
+ printf("#define CC_EBCDIC CC_EBCDIC_E\n");
+ printf("#define CC_EBCDIC1 CC_EBCDIC_E\n");
+ printf("#define CC_EBCDIC2 CC_EBCDIC_I\n");
+ printf("#define CC_EBCDIC3 CC_EBCDIC_O\n");
+ printf("\n");
+ switch ('~')
+ {
+ case 0137:
+ printf("#define CC_NATIVE CC_EBCDIC_E /* native character code */\n");
+ break;
+ case 0176:
+ printf("#define CC_NATIVE CC_ASCII /* native character code */\n");
+ break;
+ case 0241:
+ switch ('\n')
+ {
+ case 0025:
+ printf("#define CC_NATIVE CC_EBCDIC_O /* native character code */\n");
+ break;
+ default:
+ switch ('[')
+ {
+ case 0272:
+ printf("#define CC_NATIVE CC_EBCDIC_H /* native character code */\n");
+ break;
+ default:
+ printf("#define CC_NATIVE CC_EBCDIC_I /* native character code */\n");
+ break;
+ }
+ break;
+ }
+ break;
+ case 0377:
+ printf("#define CC_NATIVE CC_EBCDIC_S /* native character code */\n");
+ break;
+ default:
+ switch ('A')
+ {
+ case 0301:
+ printf("#define CC_NATIVE CC_EBCDIC_O /* native character code */\n");
+ break;
+ default:
+ printf("#define CC_NATIVE CC_ASCII /* native character code */\n");
+ break;
+ }
+ break;
+ }
+ if ('A' == 0101)
+ {
+ printf("#define CC_ALIEN CC_EBCDIC /* alien character code */\n\n");
+ printf("#define CC_bel 0007 /* bel character */\n");
+ printf("#define CC_esc 0033 /* esc character */\n");
+ printf("#define CC_sub 0032 /* sub character */\n");
+ printf("#define CC_vt 0013 /* vt character */\n");
+ }
+ else
+ {
+ printf("#define CC_ALIEN CC_ASCII /* alien character code */\n\n");
+ printf("#define CC_bel 0057 /* bel character */\n");
+ printf("#define CC_esc 0047 /* esc character */\n");
+ printf("#define CC_sub 0077 /* sub character */\n");
+ printf("#define CC_vt 0013 /* vt character */\n");
+ }
+ return 0;
+ }
+}end
diff --git a/src/lib/libast/features/common b/src/lib/libast/features/common
new file mode 100644
index 0000000..500ce87
--- /dev/null
+++ b/src/lib/libast/features/common
@@ -0,0 +1,624 @@
+iff AST_COMMON
+hdr pthread,stdarg,stddef,stdint,inttypes,types,unistd
+sys types
+typ long.double,size_t,ssize_t
+typ __va_list stdio.h
+
+mac SF_APPEND,SF_CLOSE sys/stat.h sys/socket.h
+
+dll import note{ Microsoft import/export nonsense }end execute{
+ __declspec(dllimport) int foo;
+ int main() { return foo == 5 ? 0 : 1; }
+ int bar = 5;
+ int* _imp__foo = &bar;
+}end
+
+std proto note{ standard C prototypes ok }end compile{
+ extern int foo(int, int);
+ bar() { foo(1, 1); }
+}end
+
+tst ptr_void note{ standard C void* ok }end compile{
+ extern void* foo();
+ void* bar() { return foo(); }
+}end
+
+cat{
+ /* disable non-standard linux/gnu inlines */
+ #ifdef __GNUC__
+ # undef __OPTIMIZE_SIZE__
+ # define __OPTIMIZE_SIZE__ 1
+ #endif
+
+ /* __STD_C indicates that the language is ANSI-C or C++ */
+ #if !defined(__STD_C) && __STDC__
+ # define __STD_C 1
+ #endif
+ #if !defined(__STD_C) && (__cplusplus || c_plusplus)
+ # define __STD_C 1
+ #endif
+ #if !defined(__STD_C) && _std_proto
+ # define __STD_C 1
+ #endif
+ #if !defined(__STD_C)
+ # define __STD_C 0
+ #endif
+
+ /* extern symbols must be protected against C++ name mangling */
+ #ifndef _BEGIN_EXTERNS_
+ # if __cplusplus || c_plusplus
+ # define _BEGIN_EXTERNS_ extern "C" {
+ # define _END_EXTERNS_ }
+ # else
+ # define _BEGIN_EXTERNS_
+ # define _END_EXTERNS_
+ # endif
+ #endif
+
+ /* _ARG_ simplifies function prototyping among flavors of C */
+ #ifndef _ARG_
+ # if __STD_C
+ # define _ARG_(x) x
+ # else
+ # define _ARG_(x) ()
+ # endif
+ #endif
+
+ /* _NIL_ simplifies defining nil pointers to a given type */
+ #ifndef _NIL_
+ # define _NIL_(x) ((x)0)
+ #endif
+
+ /* __INLINE__, if defined, is the inline keyword */
+ #if !defined(__INLINE__) && defined(__cplusplus)
+ # define __INLINE__ inline
+ #endif
+ #if !defined(__INLINE__) && defined(_WIN32) && !defined(__GNUC__)
+ # define __INLINE__ __inline
+ #endif
+
+ /* Void_t is defined so that Void_t* can address any type */
+ #ifndef Void_t
+ # if __STD_C
+ # define Void_t void
+ # else
+ # define Void_t char
+ # endif
+ #endif
+
+ /* windows variants and veneers */
+ #if !defined(_WINIX) && (_UWIN || __CYGWIN__ || __EMX__)
+ # define _WINIX 1
+ #endif
+
+ /* dynamic linked library external scope handling */
+ #ifdef __DYNAMIC__
+ # undef __DYNAMIC__
+ # ifndef _DLL
+ # define _DLL 1
+ # endif
+ #endif
+ #if _dll_import
+ # if _BLD_STATIC && !_BLD_DLL
+ # undef _DLL
+ # else
+ # if !_UWIN && !defined(_DLL)
+ # define _DLL 1
+ # endif
+ # endif
+ # if !defined(__EXPORT__) && _BLD_DLL
+ # define __EXPORT__ __declspec(dllexport)
+ # endif
+ # if !defined(__IMPORT__) && ( _BLD_DLL || defined(_DLL) )
+ # define __IMPORT__ __declspec(dllimport)
+ # endif
+ # if _BLD_DLL && _UWIN
+ # define __DYNAMIC__(v) (_ast_getdll()->_ast_ ## v)
+ # endif
+ #endif
+ #if !defined(_astimport)
+ # if defined(__IMPORT__) && defined(_DLL)
+ # define _astimport __IMPORT__
+ # else
+ # define _astimport extern
+ # endif
+ #endif
+ #if _dll_import && ( !_BLD_DLL || _WINIX && !_UWIN )
+ # ifdef __STDC__
+ # define __EXTERN__(T,obj) extern T obj; T* _imp__ ## obj = &obj
+ # define __DEFINE__(T,obj,val) T obj = val; T* _imp__ ## obj = &obj
+ # else
+ # define __EXTERN__(T,obj) extern T obj; T* _imp__/**/obj = &obj
+ # define __DEFINE__(T,obj,val) T obj = val; T* _imp__/**/obj = &obj
+ # endif
+ #else
+ # define __EXTERN__(T,obj) extern T obj
+ # define __DEFINE__(T,obj,val) T obj = val
+ #endif
+}end
+
+if tst - note{ <stdarg.h>+<wchar.h> works }end compile{
+ /*<NOSTDIO>*/
+ #include <stdarg.h>
+ #include <wchar.h>
+ }end
+elif tst - note{ explicit <sys/va_list.h> before <stdarg.h>+<wchar.h> }end compile{
+ /*<NOSTDIO>*/
+ #include <sys/va_list.h>
+ #include <stdarg.h>
+ #include <wchar.h>
+ }end {
+ #include <sys/va_list.h>
+ }
+endif
+
+tst ast_LL note{ LL numeric suffix supported }end compile{
+ int i = 1LL;
+ unsigned int u = 1ULL; /* NOTE: some compilers choke on 1LLU */
+}end
+
+tst - -DN=1 - -DN=2 - -DN=3 - -DN=4 - -DN=5 - -DN=6 - -DN=7 - -DN=8 - -DN=0 output{
+ #define _BYTESEX_H
+
+ #include <string.h>
+ #include <sys/types.h>
+
+ #if _STD_
+ #if N == 1
+ #define _ast_int8_t long
+ #define _ast_int8_str "long"
+ #endif
+ #if N == 2
+ #define _ast_int8_t long long
+ #define _ast_int8_str "long long"
+ #endif
+ #if N == 3
+ #define _ast_int8_t __int64
+ #define _ast_int8_str "__int64"
+ #endif
+ #if N == 4
+ #define _ast_int8_t __int64_t
+ #define _ast_int8_str "__int64_t"
+ #endif
+ #if N == 5
+ #define _ast_int8_t _int64_t
+ #define _ast_int8_str "_int64_t"
+ #endif
+ #if N == 6
+ #define _ast_int8_t int64_t
+ #define _ast_int8_str "int64_t"
+ #endif
+ #if N == 7
+ #define _ast_int8_t _int64
+ #define _ast_int8_str "_int64"
+ #endif
+ #if N == 8
+ #define _ast_int8_t int64
+ #define _ast_int8_str "int64"
+ #endif
+ #endif
+
+ #define elementsof(x) (sizeof(x)/sizeof(x[0]))
+
+ static char i_char = 1;
+ static short i_short = 1;
+ static int i_int = 1;
+ static long i_long = 1L;
+ #ifdef _ast_int8_t
+ #if _ast_LL
+ static _ast_int8_t i_long_long = 1LL;
+ static unsigned _ast_int8_t u_long_long = 18446744073709551615ULL;
+ #else
+ static _ast_int8_t i_long_long = 1;
+ static unsigned _ast_int8_t u_long_long = 18446744073709551615;
+ #endif
+ #endif
+
+ static struct
+ {
+ char* name;
+ int size;
+ char* swap;
+ } int_type[] =
+ {
+ "char", sizeof(char), (char*)&i_char,
+ "short", sizeof(short), (char*)&i_short,
+ "int", sizeof(int), (char*)&i_int,
+ "long", sizeof(long), (char*)&i_long,
+ #ifdef _ast_int8_t
+ _ast_int8_str, sizeof(_ast_int8_t), (char*)&i_long_long,
+ #endif
+ };
+
+ static int int_size[] = { 1, 2, 4, 8 };
+
+ int
+ main()
+ {
+ register int t;
+ register int s;
+ register int m = 1;
+ register int b = 1;
+ register int w = 0;
+
+ #ifdef _ast_int8_t
+ unsigned _ast_int8_t p;
+ char buf[64];
+
+ if (int_type[elementsof(int_type)-1].size <= 4)
+ return 1;
+ p = 0x12345678;
+ p <<= 32;
+ p |= 0x9abcdef0;
+ sprintf(buf, "0x%016llx", p);
+ if (strcmp(buf, "0x123456789abcdef0"))
+ return 1;
+ #endif
+ for (s = 0; s < elementsof(int_size); s++)
+ {
+ for (t = 0; t < elementsof(int_type) && int_type[t].size < int_size[s]; t++);
+ if (t < elementsof(int_type))
+ {
+ m = int_size[s];
+ #if __INTERIX
+ if (m == 8)
+ {
+ printf("#ifdef _MSC_VER\n");
+ printf("#define _ast_int8_t __int64\n");
+ printf("#else\n");
+ printf("#define _ast_int8_t long long\n");
+ printf("#endif\n");
+ }
+ else
+ #endif
+ printf("#define _ast_int%d_t %s\n", m, int_type[t].name);
+ if (m > 1)
+ {
+ if (*int_type[t].swap)
+ w |= b;
+ b <<= 1;
+ }
+ }
+ }
+ printf("#define _ast_intmax_t _ast_int%d_t\n", m);
+ if (m == sizeof(long))
+ printf("#define _ast_intmax_long 1\n");
+ printf("#define _ast_intswap %d\n", w);
+ printf("\n");
+ return 0;
+ }
+}end
+
+tst - output{
+ #include <string.h>
+ #include <sys/types.h>
+
+ #if _X86_ || _X64_
+ #define COND 1
+ #define CONDNAME "_X64_"
+ #else
+ #define COND 0
+ #endif
+
+ #define elementsof(x) (sizeof(x)/sizeof(x[0]))
+
+ static struct
+ {
+ char* name;
+ int size;
+ int cond;
+ } types[] =
+ {
+ "short", sizeof(short), 0,
+ "int", sizeof(int), 0,
+ "long", sizeof(long), 0,
+ "size_t", sizeof(size_t), 0,
+ "pointer", sizeof(void*), COND * 4,
+ "float", sizeof(float), 0,
+ "double", sizeof(double), 0,
+ #ifdef _typ_long_double
+ "long_double", sizeof(long double), 0,
+ #endif
+ };
+
+ int
+ main()
+ {
+ register int t;
+
+ for (t = 0; t < elementsof(types); t++)
+ #if COND
+ if (types[t].cond)
+ {
+ printf("#if %s\n", CONDNAME);
+ printf("#define _ast_sizeof_%s%s %d /* sizeof(%s) */\n", types[t].name, strlen(types[t].name) < 4 ? "\t" : "", types[t].cond * 2, types[t].name);
+ printf("#else\n");
+ printf("#define _ast_sizeof_%s%s %d /* sizeof(%s) */\n", types[t].name, strlen(types[t].name) < 4 ? "\t" : "", types[t].cond, types[t].name);
+ printf("#endif\n");
+ }
+ else
+ #endif
+ printf("#define _ast_sizeof_%s%s %d /* sizeof(%s) */\n", types[t].name, strlen(types[t].name) < 4 ? "\t" : "", types[t].size, types[t].name);
+ printf("\n");
+ return 0;
+ }
+}end
+
+tst - -DN=1 - -DN=0 output{
+ #define _BYTESEX_H
+
+ #include <string.h>
+ #include <sys/types.h>
+
+ #if !N || !_STD_
+ #undef _typ_long_double
+ #endif
+
+ #define elementsof(x) (sizeof(x)/sizeof(x[0]))
+
+ static struct
+ {
+ char* name;
+ int size;
+ } flt_type[] =
+ {
+ "float", sizeof(float),
+ "double", sizeof(double),
+ #ifdef _typ_long_double
+ "long double", sizeof(long double),
+ #endif
+ };
+
+ int
+ main()
+ {
+ register int t;
+ register int m = 1;
+
+ #ifdef _typ_long_double
+ long double p;
+ char buf[64];
+
+ if (flt_type[elementsof(flt_type)-1].size <= sizeof(double))
+ return 1;
+ p = 1.12345E-55;
+ sprintf(buf, "%1.5LE", p);
+ if (strcmp(buf, "1.12345E-55"))
+ return 1;
+ #endif
+ for (t = 0; t < elementsof(flt_type); t++)
+ {
+ while (t < (elementsof(flt_type) - 1) && flt_type[t].size == flt_type[t + 1].size)
+ t++;
+ m = flt_type[t].size;
+ printf("#define _ast_flt%d_t %s\n", flt_type[t].size, flt_type[t].name);
+ }
+ printf("#define _ast_fltmax_t _ast_flt%d_t\n", m);
+ if (m == sizeof(double))
+ printf("#define _ast_fltmax_double 1\n");
+ return 0;
+ }
+}end
+
+typ int8_t stdint.h inttypes.h no{
+ #undef _typ_int8_t
+ #define _typ_int8_t 1
+ typedef _ast_int1_t int8_t;
+}end
+typ uint8_t stdint.h inttypes.h no{
+ #undef _typ_uint8_t
+ #define _typ_uint8_t 1
+ typedef unsigned _ast_int1_t uint8_t;
+}end
+typ int16_t stdint.h inttypes.h no{
+ #undef _typ_int16_t
+ #define _typ_int16_t 1
+ typedef _ast_int2_t int16_t;
+}end
+typ uint16_t stdint.h inttypes.h no{
+ #undef _typ_uint16_t
+ #define _typ_uint16_t 1
+ typedef unsigned _ast_int2_t uint16_t;
+}end
+typ int32_t stdint.h inttypes.h no{
+ #undef _typ_int32_t
+ #define _typ_int32_t 1
+ typedef _ast_int4_t int32_t;
+}end
+typ uint32_t stdint.h inttypes.h no{
+ #undef _typ_uint32_t
+ #define _typ_uint32_t 1
+ typedef unsigned _ast_int4_t uint32_t;
+}end
+typ int64_t stdint.h inttypes.h no{
+ #ifdef _ast_int8_t
+ #undef _typ_int64_t
+ #define _typ_int64_t 1
+ typedef _ast_int8_t int64_t;
+ #endif
+}end
+typ uint64_t stdint.h inttypes.h no{
+ #ifdef _ast_int8_t
+ #undef _typ_uint64_t
+ #define _typ_uint64_t 1
+ typedef unsigned _ast_int8_t uint64_t;
+ #endif
+}end
+typ intmax_t stdint.h inttypes.h no{
+ #undef _typ_intmax_t
+ #define _typ_intmax_t 1
+ typedef _ast_intmax_t intmax_t;
+}end
+typ uintmax_t stdint.h inttypes.h no{
+ #undef _typ_uintmax_t
+ #define _typ_uintmax_t 1
+ typedef unsigned _ast_intmax_t uintmax_t;
+}end
+typ uintptr_t stdint.h inttypes.h no{
+ #undef _typ_uintptr_t
+ #define _typ_uintptr_t 1
+ #if _ast_sizeof_pointer == 8 && defined(_ast_int8_t)
+ typedef unsigned _ast_int8_t uintptr_t;
+ #else
+ typedef unsigned _ast_int4_t uintptr_t;
+ #endif
+}end
+
+tst - -DTRY=1 - -DTRY=1 -Dvoid=char - -DTRY=2 - -DTRY=3 - -DTRY=4 output{
+ #if _STD_ && _hdr_stdarg
+ #include <stdarg.h>
+ static void
+ varyfunny(int* p, ...)
+ {
+ va_list ap;
+ va_start(ap, p);
+ #if TRY == 1
+ *p = *ap++ != 0;
+ #endif /*TRY == 1*/
+ #if TRY == 2
+ *p = *ap != 0;
+ #endif /*TRY == 2*/
+ #if TRY == 3
+ *p = ap++ != 0;
+ #endif /*TRY == 3*/
+ va_end(ap);
+ }
+ #else
+ #include <varargs.h>
+ static void
+ varyfunny(va_alist)
+ va_dcl
+ {
+ va_list ap;
+ int* p;
+ va_start(ap);
+ p = va_arg(ap, int*);
+ #if TRY == 1
+ *p = *ap++ != 0;
+ #endif /*TRY == 1*/
+ #if TRY == 2
+ *p = *ap != 0;
+ #endif /*TRY == 2*/
+ #if TRY == 3
+ *p = ap++ != 0;
+ #endif /*TRY == 3*/
+ va_end(ap);
+ }
+ #endif
+ int
+ main()
+ {
+ int r;
+
+ printf("\n#ifndef va_listref\n");
+ printf("#ifndef va_start\n");
+ printf("#if __STD_C\n");
+ printf("#include <stdarg.h>\n");
+ printf("#else\n");
+ printf("#include <varargs.h>\n");
+ printf("#endif\n");
+ printf("#endif\n");
+ #if TRY == 4
+ printf("#define va_listref(p) (&(p))\t");
+ printf("/* pass va_list to varargs function */\n");
+ printf("#define va_listval(p) (*(p))\t");
+ printf("/* retrieve va_list from va_arg(ap,va_listarg) */\n");
+ printf("#define va_listarg va_list*\t");
+ printf("/* va_arg() va_list type */\n");
+ #else
+ varyfunny(&r);
+ printf("#define va_listref(p) (p)\t");
+ printf("/* pass va_list to varargs function */\n");
+ if (sizeof(va_list) > sizeof(void*))
+ printf("#define va_listval(p) (*(p))\t");
+ else
+ printf("#define va_listval(p) (p)\t");
+ printf("/* retrieve va_list from va_arg(ap,va_listarg) */\n");
+ #if TRY == 2
+ printf("#define va_listarg va_list*\t");
+ #else
+ printf("#define va_listarg va_list\t");
+ #endif /*TRY == 2*/
+ printf("/* va_arg() va_list type */\n");
+ #endif /*TRY == 4*/
+
+ #if _UWIN
+ printf("#ifndef va_copy\n");
+ printf("#define va_copy(to,fr) ((to)=(fr))\t");
+ printf("/* copy va_list fr -> to */\n");
+ printf("#endif\n");
+ #else
+ #if !defined(va_copy)
+ #if defined(__va_copy)
+ printf("#ifndef va_copy\n");
+ printf("#define va_copy(to,fr) __va_copy(to,fr)\t");
+ printf("/* copy va_list fr -> to */\n");
+ printf("#endif\n");
+ #else
+ #if TRY == 2
+ printf("#ifndef va_copy\n");
+ printf("#define va_copy(to,fr) memcpy(to,fr,sizeof(va_list))\t");
+ printf("/* copy va_list fr -> to */\n");
+ printf("#endif\n");
+ #else
+ printf("#ifndef va_copy\n");
+ printf("#define va_copy(to,fr) ((to)=(fr))\t");
+ printf("/* copy va_list fr -> to */\n");
+ printf("#endif\n");
+ #endif
+ #endif
+ #endif
+ #endif
+
+ printf("#endif\n");
+ return 0;
+ }
+}end
+
+cat{
+ #ifndef _AST_STD_H
+ # if __STD_C && _hdr_stddef
+ # include <stddef.h>
+ # endif
+ # if _sys_types
+ # include <sys/types.h>
+ # endif
+ # if _hdr_stdint
+ # include <stdint.h>
+ # else
+ # if _hdr_inttypes
+ # include <inttypes.h>
+ # endif
+ # endif
+ #endif
+ #if !_typ_size_t
+ # define _typ_size_t 1
+ typedef int size_t;
+ #endif
+ #if !_typ_ssize_t
+ # define _typ_ssize_t 1
+ typedef int ssize_t;
+ #endif
+ #ifndef _AST_STD_H
+ # define _def_map_ast 1
+ # if !_def_map_ast
+ # include <ast_map.h>
+ # endif
+ #endif
+}end
+
+run{
+ grep __NO_INCLUDE_WARN__ /usr/include/stat.h >/dev/null 2>&1 &&
+ grep '<name.h>' /usr/include/sys/stat.h >/dev/null 2>&1 &&
+ grep __name_h /usr/include/name.h >/dev/null 2>&1 &&
+ cat <<!
+ /* disable ${HOSTTYPE} <sys/foo.h> vs. <foo.h> clash warnings */
+ #ifndef __NO_INCLUDE_WARN__
+ #define __NO_INCLUDE_WARN__ 1
+ #endif
+ /* disable ${HOSTTYPE} <sys/stat.h> <name.h> hijack */
+ #ifndef __name_h
+ #define __name_h 1
+ #endif
+ !
+}end
diff --git a/src/lib/libast/features/dirent b/src/lib/libast/features/dirent
new file mode 100644
index 0000000..a36d35a
--- /dev/null
+++ b/src/lib/libast/features/dirent
@@ -0,0 +1,275 @@
+set prototyped
+
+set nodefine
+lib stat64 -D_LARGEFILE64_SOURCE
+typ off64_t -D_LARGEFILE64_SOURCE
+set define
+
+lib opendir
+hdr dirent,ndir
+sys dir
+nxt dirent
+
+tst botch_d_ino_dirent64 -D_LARGEFILE64_SOURCE note{ dirent64.d_ino vs. readdir64 mismatch }end compile{
+ #if !__arm__
+ )
+ #endif
+ #include <dirent.h>
+ int
+ main()
+ {
+ struct dirent64 ent;
+ char aha[5-((int)sizeof(ent.d_ino))];
+ return sizeof(aha);
+ }
+}end
+
+if ( ! _lib_opendir ) {
+ /*
+ * <dirent.h> for systems with no opendir()
+ */
+
+ #ifndef _DIRENT_H
+ #define _DIRENT_H
+
+ typedef struct
+ {
+ int dd_fd; /* file descriptor */
+ #ifdef _DIR_PRIVATE_
+ _DIR_PRIVATE_
+ #endif
+ } DIR;
+
+ struct dirent
+ {
+ long d_fileno; /* entry serial number */
+ int d_reclen; /* entry length */
+ int d_namlen; /* entry name length */
+ char d_name[1]; /* entry name */
+ };
+
+ #ifndef _DIR_PRIVATE_
+
+ #ifdef rewinddir
+ #undef rewinddir
+ #define rewinddir(p) seekdir(p,0L)
+ #endif
+
+ extern DIR* opendir(const char*);
+ extern void closedir(DIR*);
+ extern struct dirent* readdir(DIR*);
+ extern void seekdir(DIR*, long);
+ extern long telldir(DIR*);
+
+ #endif
+
+ #endif
+}
+elif ( _nxt_dirent && _lib_stat64 && _typ_off64_t && _botch_d_ino_dirent64 ) pass{
+cat <<!
+ /*
+ * <dirent.h> for [fl]stat64 and off64_t with sizeof(ino64_t)==4
+ */
+
+ #ifndef _AST_STD_H
+
+ #include ${_nxt_dirent-_nxt_dirent} /* the native <dirent.h> */
+
+ #else
+
+ #ifndef _DIR64_H
+ #define _DIR64_H
+
+ #include <ast_std.h>
+
+ #if _typ_off64_t
+ #undef off_t
+ #endif
+
+ #undef __ino64_t
+ #define __ino64_t int64_t
+
+ #include ${_nxt_dirent-_nxt_dirent} /* the native <dirent.h> */
+
+ #undef __ino64_t
+ #define __ino64_t __ino64_t
+
+ #if _typ_off64_t
+ #define off_t off64_t
+ #endif
+
+ #if _lib_readdir64 && _typ_struct_dirent64
+ #ifndef dirent
+ #define dirent dirent64
+ #endif
+ #ifndef readdir
+ #define readdir readdir64
+ #endif
+ #endif
+
+ #endif
+
+ #endif
+!
+}end
+elif ( _nxt_dirent && _lib_stat64 && _typ_off64_t ) pass{
+cat <<!
+ /*
+ * <dirent.h> for [fl]stat64 and off64_t
+ */
+
+ #ifndef _AST_STD_H
+
+ #include ${_nxt_dirent-_nxt_dirent} /* the native <dirent.h> */
+
+ #else
+
+ #ifndef _DIR64_H
+ #define _DIR64_H
+
+ #include <ast_std.h>
+
+ #if _typ_off64_t
+ #undef off_t
+ #endif
+
+ #include ${_nxt_dirent-_nxt_dirent} /* the native <dirent.h> */
+
+ #if _typ_off64_t
+ #define off_t off64_t
+ #endif
+
+ #if _lib_readdir64 && _typ_struct_dirent64
+ #ifndef dirent
+ #define dirent dirent64
+ #endif
+ #ifndef readdir
+ #define readdir readdir64
+ #endif
+ #endif
+
+ #endif
+
+ #endif
+!
+}end
+elif ( _nxt_dirent && _hdr_dirent ) pass{
+cat <<!
+ /*
+ * <dirent.h> for systems with ok <dirent.h>
+ */
+
+ #ifndef _DIRENT_H
+
+ #include ${_nxt_dirent-_nxt_dirent} /* the native <dirent.h> */
+
+ #ifndef _DIRENT_H
+ #define _DIRENT_H
+ #endif
+
+ #endif
+!
+}end
+elif ( _hdr_ndir ) {
+ /*
+ * <dirent.h> for systems with opendir() and <ndir.h>
+ */
+
+ #ifndef _DIRENT_H
+ #define _DIRENT_H
+
+ #if defined(__STDPP__directive) && defined(__STDPP__hide)
+ __STDPP__directive pragma pp:hide closedir opendir readdir seekdir telldir
+ #else
+ #define closedir ______closedir
+ #define opendir ______opendir
+ #define readdir ______readdir
+ #define seekdir ______seekdir
+ #define telldir ______telldir
+ #endif
+
+ #include <ndir.h>
+
+ #if defined(__STDPP__directive) && defined(__STDPP__hide)
+ __STDPP__directive pragma pp:nohide closedir opendir readdir seekdir telldir
+ #else
+ #undef closedir
+ #undef opendir
+ #undef readdir
+ #undef seekdir
+ #undef telldir
+ #endif
+
+ #ifndef dirent
+ #define dirent direct
+ #endif
+
+ #if !defined(d_fileno) && !defined(d_ino)
+ #define d_fileno d_ino
+ #endif
+
+ #ifdef rewinddir
+ #undef rewinddir
+ #define rewinddir(p) seekdir(p,0L)
+ #endif
+
+ extern DIR* opendir(const char*);
+ extern void closedir(DIR*);
+ extern struct dirent* readdir(DIR*);
+ extern void seekdir(DIR*, long);
+ extern long telldir(DIR*);
+
+ #endif
+}
+elif ( _sys_dir ) {
+ /*
+ * <dirent.h> for systems with opendir() and no <ndir.h>
+ */
+
+ #ifndef _DIRENT_H
+ #define _DIRENT_H
+
+ #if defined(__STDPP__directive) && defined(__STDPP__hide)
+ __STDPP__directive pragma pp:hide closedir opendir readdir seekdir telldir
+ #else
+ #define closedir ______closedir
+ #define opendir ______opendir
+ #define readdir ______readdir
+ #define seekdir ______seekdir
+ #define telldir ______telldir
+ #endif
+
+ #include <sys/dir.h>
+
+ #if defined(__STDPP__directive) && defined(__STDPP__hide)
+ __STDPP__directive pragma pp:nohide closedir opendir readdir seekdir telldir
+ #else
+ #undef closedir
+ #undef opendir
+ #undef readdir
+ #undef seekdir
+ #undef telldir
+ #endif
+
+ #ifndef dirent
+ #define dirent direct
+ #endif
+
+ #if !defined(d_fileno) && !defined(d_ino)
+ #define d_fileno d_ino
+ #endif
+
+ #ifdef rewinddir
+ #undef rewinddir
+ #define rewinddir(p) seekdir(p,0L)
+ #endif
+
+ extern DIR* opendir(const char*);
+ extern void closedir(DIR*);
+ extern struct dirent* readdir(DIR*);
+ extern void seekdir(DIR*, long);
+ extern long telldir(DIR*);
+
+ #endif
+}
+endif
diff --git a/src/lib/libast/features/eaccess b/src/lib/libast/features/eaccess
new file mode 100644
index 0000000..bf9710a
--- /dev/null
+++ b/src/lib/libast/features/eaccess
@@ -0,0 +1,11 @@
+lib eaccess,euidaccess
+macro{
+ #include <sys/types.h>
+ #include <unistd.h>
+ #ifdef EFF_ONLY_OK
+ <<"#define EFF_ONLY_OK">> EFF_ONLY_OK
+ #endif
+ #ifdef EX_OK
+ <<"#define EX_OK">> EX_OK
+ #endif
+}end
diff --git a/src/lib/libast/features/errno b/src/lib/libast/features/errno
new file mode 100644
index 0000000..271fe6d
--- /dev/null
+++ b/src/lib/libast/features/errno
@@ -0,0 +1,31 @@
+tst dat_sys_nerr note{ sys_nerr in default libs }end compile{
+ extern int sys_nerr;
+ int f()
+ {
+ return sys_nerr > 0;
+ }
+}end
+
+tst def_errno_sys_nerr note{ sys_nerr declared in errno.h }end compile{
+ #include <errno.h>
+ int f()
+ {
+ return sys_nerr > 0;
+ }
+}end
+
+tst dat_sys_errlist note{ sys_errlist in default libs }end compile{
+ extern char* sys_errlist[];
+ int f()
+ {
+ return *sys_errlist[1] != 0;
+ }
+}end
+
+tst def_errno_sys_errlist note{ sys_errlist declared in errno.h }end compile{
+ #include <errno.h>
+ int f()
+ {
+ return *sys_errlist[1] != 0;
+ }
+}end
diff --git a/src/lib/libast/features/fcntl.c b/src/lib/libast/features/fcntl.c
new file mode 100644
index 0000000..0868f06
--- /dev/null
+++ b/src/lib/libast/features/fcntl.c
@@ -0,0 +1,360 @@
+/***********************************************************************
+* *
+* This software is part of the ast package *
+* Copyright (c) 1985-2011 AT&T Intellectual Property *
+* and is licensed under the *
+* Eclipse Public License, Version 1.0 *
+* by AT&T Intellectual Property *
+* *
+* A copy of the License is available at *
+* http://www.eclipse.org/org/documents/epl-v10.html *
+* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
+* *
+* Information and Software Systems Research *
+* AT&T Research *
+* Florham Park NJ *
+* *
+* Glenn Fowler <gsf@research.att.com> *
+* David Korn <dgk@research.att.com> *
+* Phong Vo <kpv@research.att.com> *
+* *
+***********************************************************************/
+#pragma prototyped
+/*
+ * Glenn Fowler
+ * AT&T Research
+ *
+ * generate POSIX fcntl.h
+ */
+
+#include <sys/types.h>
+
+#include "FEATURE/lib"
+
+#define getdtablesize ______getdtablesize
+#define getpagesize ______getpagesize
+#define ioctl ______ioctl
+
+#if _typ_off64_t
+#undef off_t
+#ifdef __STDC__
+#define off_t off_t
+#endif
+#endif
+
+#if _hdr_fcntl
+#include <fcntl.h>
+#endif
+#if _hdr_unistd
+#include <unistd.h>
+#endif
+
+#include <sys/stat.h>
+
+#include "FEATURE/fs"
+
+#undef getdtablesize
+#undef getpagesize
+#undef ioctl
+
+#include "FEATURE/tty"
+
+#if _typ_off64_t
+#undef off_t
+#define off_t off64_t
+#endif
+
+int
+main()
+{
+ int f_local = 0;
+ int f_lck = 0;
+ int o_local = 2;
+
+ printf("#pragma prototyped\n");
+ printf("\n");
+ printf("#if _typ_off64_t\n");
+ printf("#undef off_t\n");
+ printf("#ifdef __STDC__\n");
+ printf("#define off_t off_t\n");
+ printf("#endif\n");
+ printf("#endif\n");
+ printf("\n");
+ printf("#include <ast_fs.h>\n");
+ printf("\n");
+ printf("#if _typ_off64_t\n");
+ printf("#undef off_t\n");
+ printf("#ifdef __STDC__\n");
+ printf("#define off_t off_t\n");
+ printf("#endif\n");
+ printf("#endif\n");
+ printf("\n");
+ printf("#include <fcntl.h>\n");
+#if _hdr_mman
+ printf("#include <mman.h>\n");
+#else
+#if _sys_mman
+ printf("#include <sys/mman.h>\n");
+#endif
+#endif
+ printf("\n");
+#ifndef FD_CLOEXEC
+ printf("#define FD_CLOEXEC 1\n");
+ printf("\n");
+#endif
+
+#ifndef F_DUPFD
+#define NEED_F 1
+#else
+ if (F_DUPFD > f_local) f_local = F_DUPFD;
+#endif
+#ifndef F_GETFD
+#define NEED_F 1
+#else
+ if (F_GETFD > f_local) f_local = F_GETFD;
+#endif
+#ifndef F_GETFL
+#define NEED_F 1
+#else
+ if (F_GETFL > f_local) f_local = F_GETFL;
+#endif
+#ifndef F_GETLK
+#define NEED_F 1
+#else
+ if (F_GETLK > f_local) f_local = F_GETLK;
+#endif
+#ifndef F_RDLCK
+#define NEED_F 1
+#define NEED_LCK 1
+#else
+ if (F_RDLCK > f_lck) f_lck = F_RDLCK;
+#endif
+#ifndef F_SETFD
+#define NEED_F 1
+#else
+ if (F_SETFD > f_local) f_local = F_SETFD;
+#endif
+#ifndef F_SETFL
+#define NEED_F 1
+#else
+ if (F_SETFL > f_local) f_local = F_SETFL;
+#endif
+#ifndef F_SETLK
+#define NEED_F 1
+#else
+ if (F_SETLK > f_local) f_local = F_SETLK;
+#endif
+#ifndef F_SETLKW
+#define NEED_F 1
+#else
+ if (F_SETLKW > f_local) f_local = F_SETLKW;
+#endif
+#ifndef F_UNLCK
+#define NEED_F 1
+#define NEED_LCK 1
+#else
+ if (F_UNLCK > f_lck) f_lck = F_UNLCK;
+#endif
+#ifndef F_WRLCK
+#define NEED_F 1
+#define NEED_LCK 1
+#else
+ if (F_WRLCK > f_lck) f_lck = F_WRLCK;
+#endif
+
+#if NEED_F
+ printf("#define fcntl _ast_fcntl\n");
+#if _lib_fcntl
+ printf("#define _lib_fcntl 1\n");
+#endif
+ printf("#define _ast_F_LOCAL %d\n", f_local + 1);
+#ifndef F_DUPFD
+ printf("#define F_DUPFD %d\n", ++f_local);
+#endif
+#ifndef F_GETFD
+ printf("#define F_GETFD %d\n", ++f_local);
+#endif
+#ifndef F_GETFL
+ printf("#define F_GETFL %d\n", ++f_local);
+#endif
+#ifndef F_GETLK
+ printf("#define F_GETLK %d\n", ++f_local);
+#endif
+#ifndef F_SETFD
+ printf("#define F_SETFD %d\n", ++f_local);
+#endif
+#ifndef F_SETFL
+ printf("#define F_SETFL %d\n", ++f_local);
+#endif
+#ifndef F_SETLK
+ printf("#define F_SETLK %d\n", ++f_local);
+#endif
+#ifndef F_SETLKW
+ printf("#define F_SETLKW %d\n", ++f_local);
+#endif
+#if NEED_LCK
+ printf("\n");
+#ifndef F_RDLCK
+ printf("#define F_RDLCK %d\n", f_lck++);
+#endif
+#ifndef F_WRLCK
+ printf("#define F_WRLCK %d\n", f_lck++);
+#endif
+#ifndef F_UNLCK
+ printf("#define F_UNLCK %d\n", f_lck++);
+#endif
+#endif
+ printf("\n");
+ if (f_lck == 3)
+ {
+ printf("struct flock\n");
+ printf("{\n");
+ printf(" short l_type;\n");
+ printf(" short l_whence;\n");
+ printf(" off_t l_start;\n");
+ printf(" off_t l_len;\n");
+ printf(" short l_pid;\n");
+ printf("};\n");
+ printf("\n");
+ }
+ printf("\n");
+#endif
+
+#ifndef O_APPEND
+#define NEED_O 1
+#else
+ if (O_APPEND > o_local) o_local = O_APPEND;
+#endif
+#ifndef O_CREAT
+#define NEED_O 1
+#else
+ if (O_CREAT > o_local) o_local = O_CREAT;
+#endif
+#ifndef O_EXCL
+#define NEED_O 1
+#else
+ if (O_EXCL > o_local) o_local = O_EXCL;
+#endif
+#ifndef O_NOCTTY
+#ifdef TIOCNOTTY
+#define NEED_O 1
+#endif
+#else
+ if (O_NOCTTY > o_local) o_local = O_NOCTTY;
+#endif
+#ifndef O_NONBLOCK
+#ifndef O_NDELAY
+#define NEED_O 1
+#endif
+#else
+ if (O_NONBLOCK > o_local) o_local = O_NONBLOCK;
+#endif
+#ifndef O_RDONLY
+#define NEED_O 1
+#endif
+#ifndef O_RDWR
+#define NEED_O 1
+#endif
+#ifndef O_TRUNC
+#define NEED_O 1
+#else
+ if (O_TRUNC > o_local) o_local = O_TRUNC;
+#endif
+#ifndef O_WRONLY
+#define NEED_O 1
+#endif
+
+#if NEED_O
+ printf("#define open _ast_open\n");
+ printf("#define _ast_O_LOCAL 0%o\n", o_local<<1);
+#ifndef O_RDONLY
+ printf("#define O_RDONLY 0\n");
+#endif
+#ifndef O_WRONLY
+ printf("#define O_WRONLY 1\n");
+#endif
+#ifndef O_RDWR
+ printf("#define O_RDWR 2\n");
+#endif
+#ifndef O_APPEND
+ printf("#define O_APPEND 0%o\n", o_local <<= 1);
+#endif
+#ifndef O_CREAT
+ printf("#define O_CREAT 0%o\n", o_local <<= 1);
+#endif
+#ifndef O_EXCL
+ printf("#define O_EXCL 0%o\n", o_local <<= 1);
+#endif
+#ifndef O_NOCTTY
+#ifdef TIOCNOTTY
+ printf("#define O_NOCTTY 0%o\n", o_local <<= 1);
+#endif
+#endif
+#ifndef O_NONBLOCK
+#ifndef O_NDELAY
+ printf("#define O_NONBLOCK 0%o\n", o_local <<= 1);
+#endif
+#endif
+#ifndef O_TRUNC
+ printf("#define O_TRUNC 0%o\n", o_local <<= 1);
+#endif
+#endif
+#ifndef O_ACCMODE
+ printf("#define O_ACCMODE (O_RDONLY|O_WRONLY|O_RDWR)\n");
+#endif
+#ifndef O_NOCTTY
+#ifndef TIOCNOTTY
+ printf("#define O_NOCTTY 0\n");
+#endif
+#endif
+#ifndef O_NONBLOCK
+#ifdef O_NDELAY
+ printf("#define O_NONBLOCK O_NDELAY\n");
+#endif
+#endif
+#ifndef O_BINARY
+ printf("#define O_BINARY 0\n");
+#endif
+#ifndef O_TEMPORARY
+ printf("#define O_TEMPORARY 0\n");
+#endif
+#ifndef O_TEXT
+ printf("#define O_TEXT 0\n");
+#endif
+#if NEED_F || NEED_O
+ printf("\n");
+#if NEED_F
+ printf("extern int fcntl(int, int, ...);\n");
+#endif
+#if NEED_O
+ printf("extern int open(const char*, int, ...);\n");
+#endif
+#endif
+ printf("\n");
+ printf("#include <ast_fs.h>\n");
+ printf("#if _typ_off64_t\n");
+ printf("#undef off_t\n");
+ printf("#define off_t off64_t\n");
+ printf("#endif\n");
+ printf("#if _lib_fstat64\n");
+ printf("#define fstat fstat64\n");
+ printf("#endif\n");
+ printf("#if _lib_lstat64\n");
+ printf("#define lstat lstat64\n");
+ printf("#endif\n");
+ printf("#if _lib_stat64\n");
+ printf("#define stat stat64\n");
+ printf("#endif\n");
+ printf("#if _lib_creat64\n");
+ printf("#define creat creat64\n");
+ printf("#endif\n");
+ printf("#if _lib_mmap64\n");
+ printf("#define mmap mmap64\n");
+ printf("#endif\n");
+ printf("#if _lib_open64\n");
+ printf("#undef open\n");
+ printf("#define open open64\n");
+ printf("#endif\n");
+
+ return 0;
+}
diff --git a/src/lib/libast/features/float b/src/lib/libast/features/float
new file mode 100644
index 0000000..de27bb2
--- /dev/null
+++ b/src/lib/libast/features/float
@@ -0,0 +1,1191 @@
+set prototyped
+set nooptimize
+set stdio FEATURE/isoc99
+hdr float,limits,math,values
+lib fpclassify,frexp,frexpl,ldexp,ldexpl,finite,finitel,isinf,isinfl,isnan,isnanl,signbit,copysign,copysignl FEATURE/isoc99 math.h -lm
+
+tst ast_no_um2fm note{ no unsigned intmax => floatmax cast }end nolink{
+ #include "FEATURE/common"
+ int
+ main()
+ {
+ _ast_fltmax_t f = 0;
+ unsigned _ast_intmax_t i = 0;
+ f = i;
+ i = f;
+ return f == i;
+ }
+}end
+
+tst ast_mpy_overflow_fpe note{ fpe on mpy overflow }end noexecute{
+ int
+ main()
+ {
+ float f;
+ float p;
+ int i;
+
+ i = 0;
+ p = f = 1.0;
+ do
+ {
+ p = f;
+ f *= 2.0;
+ } while (f != p && ++i < 1024);
+ return 0;
+ }
+}end
+
+tst ast_div_underflow_fpe note{ fpe on div underflow }end noexecute{
+ int
+ main()
+ {
+ float f;
+ float p;
+ int i;
+
+ i = 0;
+ p = f = 1.0;
+ do
+ {
+ p = f;
+ f /= 2.0;
+ } while (f != p && ++i < 1024);
+ return 0;
+ }
+}end
+
+macro{
+ #if _hdr_float
+ #include <float.h>
+ #endif
+ #if _hdr_limits
+ #include <limits.h>
+ #endif
+ #if _hdr_math
+ #include <math.h>
+ #endif
+ #if _hdr_values
+ #include <values.h>
+ #endif
+
+ #if !defined(FLT_MIN_EXP) && defined(FMINEXP)
+ #define FLT_MIN_EXP FMINEXP
+ #endif
+ #if !defined(FLT_MIN) && defined(MINFLOAT)
+ #define FLT_MIN MINFLOAT
+ #endif
+ #if !defined(FLT_MAX_EXP) && defined(FMAXEXP)
+ #define FLT_MAX_EXP FMAXEXP
+ #endif
+ #if !defined(FLT_MAX) && defined(MAXFLOAT)
+ #define FLT_MAX MAXFLOAT
+ #endif
+
+ #if !defined(DBL_MIN_EXP) && defined(DMINEXP)
+ #define DBL_MIN_EXP DMINEXP
+ #endif
+ #if !defined(DBL_MIN) && defined(MINDOUBLE)
+ #define DBL_MIN MINDOUBLE
+ #endif
+ #if !defined(DBL_MAX_EXP) && defined(DMAXEXP)
+ #define DBL_MAX_EXP DMAXEXP
+ #endif
+ #if !defined(DBL_MAX) && defined(MAXDOUBLE)
+ #define DBL_MAX MAXDOUBLE
+ #endif
+
+ <<"#include <ast_common.h>">>
+ #if _hdr_float
+ <<"#include <float.h>">>
+ #endif
+ #if _hdr_math
+ <<"#include <math.h>">>
+ #endif
+ #ifdef FLT_DIG
+ <<"#ifndef FLT_DIG">>
+ <<"#define FLT_DIG">> FLT_DIG
+ <<"#endif">>
+ #endif
+ #ifdef FLT_MAX
+ <<"#ifndef FLT_MAX">>
+ <<"#define FLT_MAX">> FLT_MAX
+ <<"#endif">>
+ #endif
+ #ifdef FLT_MAX_10_EXP
+ <<"#ifndef FLT_MAX_10_EXP">>
+ <<"#define FLT_MAX_10_EXP">> FLT_MAX_10_EXP
+ <<"#endif">>
+ #endif
+ #ifdef FLT_MAX_EXP
+ <<"#ifndef FLT_MAX_EXP">>
+ <<"#define FLT_MAX_EXP">> FLT_MAX_EXP
+ <<"#endif">>
+ #endif
+ #ifdef FLT_MIN
+ <<"#ifndef FLT_MIN">>
+ <<"#define FLT_MIN">> FLT_MIN
+ <<"#endif">>
+ #endif
+ #ifdef FLT_MIN_10_EXP
+ <<"#ifndef FLT_MIN_10_EXP">>
+ <<"#define FLT_MIN_10_EXP">> FLT_MIN_10_EXP
+ <<"#endif">>
+ #endif
+ #ifdef FLT_MIN_EXP
+ <<"#ifndef FLT_MIN_EXP">>
+ <<"#define FLT_MIN_EXP">> FLT_MIN_EXP
+ <<"#endif">>
+ #endif
+
+ #ifdef DBL_DIG
+ <<"#ifndef DBL_DIG">>
+ <<"#define DBL_DIG">> DBL_DIG
+ <<"#endif">>
+ #endif
+ #ifdef DBL_MAX
+ <<"#ifndef DBL_MAX">>
+ <<"#define DBL_MAX">> DBL_MAX
+ <<"#endif">>
+ #endif
+ #ifdef DBL_MAX_10_EXP
+ <<"#ifndef DBL_MAX_10_EXP">>
+ <<"#define DBL_MAX_10_EXP">> DBL_MAX_10_EXP
+ <<"#endif">>
+ #endif
+ #ifdef DBL_MAX_EXP
+ <<"#ifndef DBL_MAX_EXP">>
+ <<"#define DBL_MAX_EXP">> DBL_MAX_EXP
+ <<"#endif">>
+ #endif
+ #ifdef DBL_MIN
+ <<"#ifndef DBL_MIN">>
+ <<"#define DBL_MIN">> DBL_MIN
+ <<"#endif">>
+ #endif
+ #ifdef DBL_MIN_10_EXP
+ <<"#ifndef DBL_MIN_10_EXP">>
+ <<"#define DBL_MIN_10_EXP">> DBL_MIN_10_EXP
+ <<"#endif">>
+ #endif
+ #ifdef DBL_MIN_EXP
+ <<"#ifndef DBL_MIN_EXP">>
+ <<"#define DBL_MIN_EXP">> DBL_MIN_EXP
+ <<"#endif">>
+ #endif
+
+ #ifdef LDBL_DIG
+ <<"#ifndef LDBL_DIG">>
+ <<"#define LDBL_DIG">> LDBL_DIG
+ <<"#endif">>
+ #endif
+ #ifdef LDBL_MAX
+ <<"#ifndef LDBL_MAX">>
+ <<"#define LDBL_MAX">> LDBL_MAX
+ <<"#endif">>
+ #endif
+ #ifdef LDBL_MAX_10_EXP
+ <<"#ifndef LDBL_MAX_10_EXP">>
+ <<"#define LDBL_MAX_10_EXP">> LDBL_MAX_10_EXP
+ <<"#endif">>
+ #endif
+ #ifdef LDBL_MAX_EXP
+ <<"#ifndef LDBL_MAX_EXP">>
+ <<"#define LDBL_MAX_EXP">> LDBL_MAX_EXP
+ <<"#endif">>
+ #endif
+ #ifdef LDBL_MIN
+ <<"#ifndef LDBL_MIN">>
+ <<"#define LDBL_MIN">> LDBL_MIN
+ <<"#endif">>
+ #endif
+ #ifdef LDBL_MIN_10_EXP
+ <<"#ifndef LDBL_MIN_10_EXP">>
+ <<"#define LDBL_MIN_10_EXP">> LDBL_MIN_10_EXP
+ <<"#endif">>
+ #endif
+ #ifdef LDBL_MIN_EXP
+ <<"#ifndef LDBL_MIN_EXP">>
+ <<"#define LDBL_MIN_EXP">> LDBL_MIN_EXP
+ <<"#endif">>
+ #endif
+}end
+
+tst - note{ missing floating point limits }end output{
+ #include "FEATURE/common"
+ #include <stdio.h>
+ #if _hdr_float
+ #include <float.h>
+ #endif
+ #if _hdr_limits
+ #include <limits.h>
+ #endif
+ #if _hdr_math
+ #include <math.h>
+ #endif
+ #if _hdr_values
+ #include <values.h>
+ #endif
+ #include <signal.h>
+ #ifdef SIGFPE
+ static int caught = 0;
+ #if _STD_
+ static void catch(int sig)
+ #else
+ static void catch(sig) int sig;
+ #endif
+ {
+ signal(sig, SIG_IGN);
+ caught++;
+ }
+ #endif
+ int
+ main()
+ {
+ register int i;
+ register int s;
+ float f;
+ float pf;
+ float mf;
+ float xf;
+ double d;
+ double pd;
+ double md;
+ char* fp;
+ #if _ast_fltmax_double
+ char* fs = "";
+ char* ds = "";
+ #else
+ _ast_fltmax_t l;
+ _ast_fltmax_t pl;
+ _ast_fltmax_t ml;
+ char* fs = "F";
+ char* ds = "";
+ char* ls = "L";
+ #endif
+ unsigned long u;
+ unsigned _ast_intmax_t w;
+ unsigned _ast_intmax_t pw;
+ unsigned _ast_intmax_t x;
+ unsigned short us;
+ unsigned int ui;
+ unsigned long ul;
+ unsigned _ast_intmax_t uq;
+
+ #ifdef SIGFPE
+ signal(SIGFPE, catch);
+ #endif
+ printf("\n");
+ printf("\n");
+ us = 0;
+ us = ~us;
+ i = 0;
+ while (us /= 10)
+ i++;
+ printf("#define USHRT_DIG %d\n", i);
+ ui = 0;
+ ui = ~ui;
+ i = 0;
+ while (ui /= 10)
+ i++;
+ printf("#define UINT_DIG %d\n", i);
+ ul = 0;
+ ul = ~ul;
+ i = 0;
+ while (ul /= 10)
+ i++;
+ printf("#define ULONG_DIG %d\n", i);
+ if (sizeof(uq) > sizeof(ul))
+ {
+ uq = 0;
+ uq = ~uq;
+ i = 0;
+ while (uq /= 10)
+ i++;
+ printf("#define ULLONG_DIG %d\n", i);
+ printf("#define UINTMAX_DIG ULLONG_DIG\n");
+ }
+ else
+ printf("#define UINTMAX_DIG ULONG_DIG\n");
+ printf("\n");
+ w = 1;
+ do
+ {
+ pw = w;
+ w *= 2;
+ f = (_ast_intmax_t)w;
+ x = (_ast_intmax_t)f;
+ } while (w > pw && w == x);
+ w = (pw - 1) + pw;
+ u = ~0;
+ if (u > w)
+ u = w;
+ printf("#define FLT_ULONG_MAX %lu.0F\n", u);
+ if (sizeof(w) > sizeof(u))
+ {
+ printf("#define FLT_ULLONG_MAX %llu.0F\n", w);
+ printf("#define FLT_UINTMAX_MAX FLT_ULLONG_MAX\n");
+ }
+ else
+ {
+ printf("#define FLT_ULLONG_MAX FLT_ULONG_MAX\n");
+ printf("#define FLT_UINTMAX_MAX FLT_ULONG_MAX\n");
+ }
+ u /= 2;
+ w /= 2;
+ printf("#define FLT_LONG_MAX %lu.0F\n", u);
+ if (sizeof(w) > sizeof(u))
+ {
+ printf("#define FLT_LLONG_MAX %llu.0F\n", w);
+ printf("#define FLT_INTMAX_MAX FLT_LLONG_MAX\n");
+ }
+ else
+ {
+ printf("#define FLT_LLONG_MAX FLT_LONG_MAX\n");
+ printf("#define FLT_INTMAX_MAX FLT_LONG_MAX\n");
+ }
+ u++;
+ w++;
+ printf("#define FLT_LONG_MIN (-%lu.0F)\n", u);
+ if (sizeof(w) > sizeof(u))
+ {
+ printf("#define FLT_LLONG_MIN (-%llu.0F)\n", w);
+ printf("#define FLT_INTMAX_MIN FLT_LLONG_MIN\n");
+ }
+ else
+ {
+ printf("#define FLT_LLONG_MIN FLT_LONG_MIN\n");
+ printf("#define FLT_INTMAX_MIN FLT_LONG_MIN\n");
+ }
+ #ifdef FLT_DIG
+ s = FLT_DIG;
+ #else
+ f = pf = 1.0;
+ s = -1;
+ do
+ {
+ s++;
+ f *= 10.0;
+ } while (f != (f + pf));
+ #endif
+ #if defined(FLT_MIN) && defined(FLT_MIN_EXP)
+ i = FLT_MIN_EXP;
+ mf = FLT_MIN;
+ #else
+ i = 3;
+ f = pf = 1.0;
+ do
+ {
+ i--;
+ mf = pf;
+ pf = f;
+ f /= 2.0;
+ } while (f < pf);
+ #ifdef FLT_MIN_EXP
+ i = FLT_MIN_EXP;
+ #endif
+ #ifdef FLT_MIN
+ mf = FLT_MIN;
+ #endif
+ #endif
+ #ifndef FLT_DIG
+ printf("#ifndef FLT_DIG\n");
+ printf("#define FLT_DIG %d\n", s);
+ printf("#endif\n");
+ #endif
+ #ifndef FLT_MIN
+ printf("#ifndef FLT_MIN\n");
+ printf("#define FLT_MIN %.*E%s\n", s + 1, mf, fs);
+ printf("#endif\n");
+ #endif
+ #ifndef FLT_MIN_EXP
+ printf("#ifndef FLT_MIN_EXP\n");
+ printf("#define FLT_MIN_EXP (%d)\n", i);
+ printf("#endif\n");
+ #endif
+
+ #if defined(FLT_MAX) && defined(FLT_MAX_EXP)
+ i = FLT_MAX_EXP;
+ f = FLT_MAX;
+ #else
+ i = -1;
+ f = pf = 1.0;
+ do
+ {
+ i++;
+ mf = pf;
+ pf = f;
+ f *= 2.0;
+ } while (f > pf);
+ #ifdef FLT_MAX_EXP
+ i = FLT_MAX_EXP;
+ #endif
+ #ifdef FLT_MAX
+ f = FLT_MAX;
+ #endif
+ #endif
+ #ifdef FLT_MAX_EXP
+ i = FLT_MAX_EXP;
+ #else
+ f = 1;
+ do
+ {
+ f *= 2.0;
+ } while (mf == (mf + f));
+ f = (mf - f) * 2.0 + f;
+ #endif
+ xf = f;
+ #ifndef FLT_MAX
+ printf("#ifndef FLT_MAX\n");
+ printf("#define FLT_MAX %.*E%s\n", s + 1, f, fs);
+ printf("#endif\n");
+ #endif
+ #ifndef FLT_MAX_EXP
+ printf("#ifndef FLT_MAX_EXP\n");
+ printf("#define FLT_MAX_EXP %d\n", i);
+ printf("#endif\n");
+ #endif
+
+ #ifdef FLT_MIN_10_EXP
+ i = FLT_MIN_10_EXP;
+ #else
+ i = 2;
+ f = 1.0;
+ do
+ {
+ i--;
+ pf = f;
+ f /= 10.0;
+ } while (f < pf);
+ #endif
+ #ifndef FLT_MIN_10_EXP
+ printf("#ifndef FLT_MIN_10_EXP\n");
+ printf("#define FLT_MIN_10_EXP (%d)\n", i);
+ printf("#endif\n");
+ #endif
+
+ #ifdef FLT_MAX_10_EXP
+ i = FLT_MAX_10_EXP;
+ #else
+ i = -2;
+ f = 1.0;
+ do
+ {
+ i++;
+ pf = f;
+ f *= 10.0;
+ } while (f > pf);
+ #endif
+ #ifndef FLT_MAX_10_EXP
+ printf("#ifndef FLT_MAX_10_EXP\n");
+ printf("#define FLT_MAX_10_EXP %d\n", i);
+ printf("#endif\n");
+ #endif
+
+ printf("\n");
+ w = 1;
+ do
+ {
+ pw = w;
+ w *= 2;
+ d = (_ast_intmax_t)w;
+ x = (_ast_intmax_t)d;
+ } while (w > pw && w == x);
+ w = (pw - 1) + pw;
+ u = ~0;
+ if (u > w)
+ u = w;
+ printf("#define DBL_ULONG_MAX %lu.0\n", u);
+ if (sizeof(w) > sizeof(u))
+ {
+ printf("#define DBL_ULLONG_MAX %llu.0\n", w);
+ printf("#define DBL_UINTMAX_MAX DBL_ULLONG_MAX\n");
+ }
+ else
+ {
+ printf("#define DBL_ULLONG_MAX DBL_ULONG_MAX\n");
+ printf("#define DBL_UINTMAX_MAX DBL_ULONG_MAX\n");
+ }
+ u /= 2;
+ w /= 2;
+ printf("#define DBL_LONG_MAX %lu.0\n", u);
+ if (sizeof(w) > sizeof(u))
+ {
+ printf("#define DBL_LLONG_MAX %llu.0\n", w);
+ printf("#define DBL_INTMAX_MAX DBL_LLONG_MAX\n");
+ }
+ else
+ {
+ printf("#define DBL_LLONG_MAX DBL_LONG_MAX\n");
+ printf("#define DBL_INTMAX_MAX DBL_LONG_MAX\n");
+ }
+ u++;
+ w++;
+ printf("#define DBL_LONG_MIN (-%lu.0)\n", u);
+ if (sizeof(w) > sizeof(u))
+ {
+ printf("#define DBL_LLONG_MIN (-%llu.0)\n", w);
+ printf("#define DBL_INTMAX_MIN DBL_LLONG_MIN\n");
+ }
+ else
+ {
+ printf("#define DBL_LLONG_MIN DBL_LONG_MIN\n");
+ printf("#define DBL_INTMAX_MIN DBL_LONG_MIN\n");
+ }
+ #ifdef DBL_DIG
+ s = DBL_DIG;
+ #else
+ d = pd = 1.0;
+ s = -1;
+ do
+ {
+ s++;
+ d *= 10.0;
+ } while (d != (d + pd));
+ #endif
+ #if defined(DBL_MIN) && defined(DBL_MIN_EXP)
+ i = DBL_MIN_EXP;
+ md = DBL_MIN;
+ #else
+ i = 3;
+ d = pd = 1.0;
+ do
+ {
+ i--;
+ md = pd;
+ pd = d;
+ d /= 2.0;
+ } while (d < pd);
+ #ifdef DBL_MIN_EXP
+ i = DBL_MIN_EXP;
+ #endif
+ #ifdef DBL_MIN
+ md = DBL_MIN;
+ #endif
+ #endif
+ #ifndef DBL_DIG
+ printf("#ifndef DBL_DIG\n");
+ printf("#define DBL_DIG %d\n", s);
+ printf("#endif\n");
+ #endif
+ #ifndef DBL_MIN
+ printf("#ifndef DBL_MIN\n");
+ printf("#define DBL_MIN %.*E%s\n", s + 1, md, ds);
+ printf("#endif\n");
+ #endif
+ #ifndef DBL_MIN_EXP
+ printf("#ifndef DBL_MIN_EXP\n");
+ printf("#define DBL_MIN_EXP (%d)\n", i);
+ printf("#endif\n");
+ #endif
+
+ #if defined(DBL_MAX) && defined(DBL_MAX_EXP)
+ i = DBL_MAX_EXP;
+ d = DBL_MAX;
+ #else
+ i = -1;
+ d = pd = 1.0;
+ do
+ {
+ i++;
+ md = pd;
+ pd = d;
+ d *= 2.0;
+ } while (d > pd);
+ d = 1.0;
+ do
+ {
+ d *= 2.0;
+ } while (md == (md + d));
+ d = (md - d) * 2.0 + d;
+ #ifdef DBL_MAX_EXP
+ i = DBL_MAX_EXP;
+ #endif
+ #ifdef DBL_MAX
+ d = DBL_MAX;
+ #endif
+ #endif
+ #ifndef DBL_MAX
+ printf("#ifndef DBL_MAX\n");
+ printf("#define DBL_MAX %.*E%s\n", s + 1, d, ds);
+ printf("#endif\n");
+ #endif
+ #ifndef DBL_MAX_EXP
+ printf("#ifndef DBL_MAX_EXP\n");
+ printf("#define DBL_MAX_EXP %d\n", i);
+ printf("#endif\n");
+ #endif
+
+ #ifdef DBL_MIN_10_EXP
+ i = DBL_MIN_10_EXP;
+ #else
+ i = 2;
+ d = 1.0;
+ do
+ {
+ i--;
+ pd = d;
+ d /= 10.0;
+ } while (d < pd);
+ #endif
+ #ifndef DBL_MIN_10_EXP
+ printf("#ifndef DBL_MIN_10_EXP\n");
+ printf("#define DBL_MIN_10_EXP (%d)\n", i);
+ printf("#endif\n");
+ #endif
+
+ #ifdef DBL_MAX_10_EXP
+ i = DBL_MAX_10_EXP;
+ #else
+ i = -2;
+ d = 1.0;
+ do
+ {
+ i++;
+ pd = d;
+ d *= 10.0;
+ } while (d > pd);
+ #endif
+ #ifndef DBL_MAX_10_EXP
+ printf("#ifndef DBL_MAX_10_EXP\n");
+ printf("#define DBL_MAX_10_EXP %d\n", i);
+ printf("#endif\n");
+ #endif
+
+ #if !_ast_fltmax_double
+ printf("\n");
+ w = 1;
+ do
+ {
+ pw = w;
+ w *= 2;
+ l = (_ast_intmax_t)w;
+ x = (_ast_intmax_t)l;
+ } while (w > pw && w == x);
+ w = (pw - 1) + pw;
+ u = ~0;
+ if (u > w)
+ u = w;
+ printf("#define LDBL_ULONG_MAX %lu.0L\n", u);
+ if (sizeof(w) > sizeof(u))
+ {
+ printf("#define LDBL_ULLONG_MAX %llu.0L\n", w);
+ printf("#define LDBL_UINTMAX_MAX LDBL_ULLONG_MAX\n");
+ }
+ else
+ {
+ printf("#define LDBL_ULLONG_MAX LDBL_ULONG_MAX\n");
+ printf("#define LDBL_UINTMAX_MAX LDBL_ULONG_MAX\n");
+ }
+ u /= 2;
+ w /= 2;
+ printf("#define LDBL_LONG_MAX %lu.0L\n", u);
+ if (sizeof(w) > sizeof(u))
+ {
+ printf("#define LDBL_LLONG_MAX %llu.0L\n", w);
+ printf("#define LDBL_INTMAX_MAX LDBL_LLONG_MAX\n");
+ }
+ else
+ {
+ printf("#define LDBL_LLONG_MAX LDBL_LONG_MAX\n");
+ printf("#define LDBL_INTMAX_MAX LDBL_LONG_MAX\n");
+ }
+ u++;
+ w++;
+ printf("#define LDBL_LONG_MIN (-%lu.0L)\n", u);
+ if (sizeof(w) > sizeof(u))
+ {
+ printf("#define LDBL_LLONG_MIN (-%llu.0L)\n", w);
+ printf("#define LDBL_INTMAX_MIN LDBL_LLONG_MIN\n");
+ }
+ else
+ {
+ printf("#define LDBL_LLONG_MIN LDBL_LONG_MIN\n");
+ printf("#define LDBL_INTMAX_MIN LDBL_LONG_MIN\n");
+ }
+ #ifdef LDBL_DIG
+ s = LDBL_DIG;
+ #else
+ l = pl = 1.0L;
+ s = -1;
+ do
+ {
+ s++;
+ l *= 10.0L;
+ } while (l != (l + pl));
+ #endif
+ #if defined(LDBL_MIN) && defined(LDBL_MIN_EXP)
+ i = LDBL_MIN_EXP;
+ ml = LDBL_MIN;
+ #else
+ i = 3;
+ l = pl = 1.0L;
+ do
+ {
+ i--;
+ ml = pl;
+ pl = l;
+ l /= 2.0L;
+ } while (l < pl);
+ #ifdef LDBL_MIN_EXP
+ i = LDBL_MIN_EXP;
+ #endif
+ #ifdef LDBL_MIN
+ ml = LDBL_MIN;
+ #endif
+ #endif
+ #ifndef LDBL_DIG
+ printf("#ifndef LDBL_DIG\n");
+ printf("#define LDBL_DIG %d\n", s);
+ printf("#endif\n");
+ #endif
+ #ifndef LDBL_MIN
+ printf("#ifndef LDBL_MIN\n");
+ printf("#define LDBL_MIN %.*LE%s\n", s + 1, ml, ls);
+ printf("#endif\n");
+ #endif
+ #ifndef LDBL_MIN_EXP
+ printf("#ifndef LDBL_MIN_EXP\n");
+ printf("#define LDBL_MIN_EXP (%d)\n", i);
+ printf("#endif\n");
+ #endif
+
+ #if defined(LDBL_MAX) && defined(LDBL_MAX_EXP)
+ i = LDBL_MAX_EXP;
+ l = LDBL_MAX;
+ #else
+ i = -1;
+ l = pl = 1.0L;
+ do
+ {
+ i++;
+ ml = pl;
+ pl = l;
+ l *= 2.0L;
+ } while (l > pl);
+ l = 1.0L;
+ do
+ {
+ l *= 2.0L;
+ } while (ml == (ml + l));
+ l = (ml - l) * 2.0L + l;
+ #ifdef LDBL_MAX_EXP
+ i = LDBL_MAX_EXP;
+ #endif
+ #ifdef LDBL_MAX
+ l = LDBL_MAX;
+ #endif
+ #endif
+ #ifndef LDBL_MAX
+ printf("#ifndef LDBL_MAX\n");
+ printf("#define LDBL_MAX %.*LE%s\n", s + 1, l, ls);
+ printf("#endif\n");
+ #endif
+ #ifndef LDBL_MAX_EXP
+ printf("#ifndef LDBL_MAX_EXP\n");
+ printf("#define LDBL_MAX_EXP %d\n", i);
+ printf("#endif\n");
+ #endif
+
+ #ifdef LDBL_MIN_10_EXP
+ i = LDBL_MIN_10_EXP;
+ #else
+ i = 2;
+ l = 1.0L;
+ do
+ {
+ i--;
+ pl = l;
+ l /= 10.0L;
+ } while (l < pl);
+ #endif
+ #ifndef LDBL_MIN_10_EXP
+ printf("#ifndef LDBL_MIN_10_EXP\n");
+ printf("#define LDBL_MIN_10_EXP (%d)\n", i);
+ printf("#endif\n");
+ #endif
+
+ #ifdef LDBL_MAX_10_EXP
+ i = LDBL_MAX_10_EXP;
+ #else
+ i = -2;
+ l = 1.0L;
+ do
+ {
+ i++;
+ pl = l;
+ l *= 10.0L;
+ } while (l > pl);
+ #endif
+ #ifndef LDBL_MAX_10_EXP
+ printf("#ifndef LDBL_MAX_10_EXP\n");
+ printf("#define LDBL_MAX_10_EXP %d\n", i);
+ printf("#endif\n");
+ #endif
+ fp = "LDBL";
+ #else
+ fp = "DBL";
+ #endif
+
+ printf("\n");
+ printf("#define FLTMAX_UINTMAX_MAX %s_UINTMAX_MAX\n", fp);
+ printf("#define FLTMAX_INTMAX_MAX %s_INTMAX_MAX\n", fp);
+ printf("#define FLTMAX_INTMAX_MIN %s_INTMAX_MIN\n", fp);
+
+ #ifdef SIGFPE
+ if (!caught)
+ {
+ #if !__MVS__
+ f = xf;
+ f *= 2;
+ if (!f)
+ #endif
+ caught = 1;
+ }
+ if (caught)
+ printf("\n#define _ast_fltsig %d\n", SIGFPE);
+ #endif
+
+ printf("\n");
+ #if !_lib_frexp
+ printf("extern double frexp(double, int*);\n");
+ #endif
+ #if !_lib_frexpl
+ printf("extern _ast_fltmax_t frexpl(_ast_fltmax_t, int*);\n");
+ #endif
+ #if !_lib_ldexp
+ printf("extern double ldexp(double, int);\n");
+ #endif
+ #if !_lib_ldexpl
+ printf("extern _ast_fltmax_t ldexpl(_ast_fltmax_t, int);\n");
+ #endif
+
+ return 0;
+ }
+}end
+
+tst - note{ double exponent bitfoolery }end output{
+ #include "FEATURE/common"
+ #include <stdio.h>
+ typedef union _dbl_exp_u
+ {
+ unsigned _ast_int4_t e[sizeof(double) / 4];
+ double f;
+ } _ast_dbl_exp_t;
+ int
+ main()
+ {
+ int i;
+ int j;
+ unsigned _ast_int4_t e;
+ _ast_dbl_exp_t a;
+ _ast_dbl_exp_t b;
+ a.f = 1;
+ b.f = 2;
+ for (i = 0; i < sizeof(a.e) / sizeof(a.e[0]); i++)
+ if (e = a.e[i] ^ b.e[i])
+ {
+ for (j = i + 1; j < sizeof(a.e) / sizeof(a.e[0]); j++)
+ if (a.e[j] ^ b.e[j])
+ return 0;
+ printf("typedef union _ast_dbl_exp_u\n{\n\tuint32_t\t\te[sizeof(double)/4];\n\tdouble\t\t\tf;\n} _ast_dbl_exp_t;\n\n");
+ printf("#define _ast_dbl_exp_index %d\n", i);
+ for (i = 0; !(e & 1); e >>= 1, i++);
+ printf("#define _ast_dbl_exp_shift %d\n\n", i);
+ return 0;
+ }
+ return 0;
+ }
+}end
+
+tst - note{ long double exponent bitfoolery }end output{
+ #include "FEATURE/common"
+ #include <stdio.h>
+ typedef union _ast_fltmax_exp_u
+ {
+ unsigned _ast_int4_t e[sizeof(_ast_fltmax_t) / 4];
+ _ast_fltmax_t f;
+ } _ast_fltmax_exp_t;
+ int
+ main()
+ {
+ int i;
+ int j;
+ unsigned _ast_int4_t e;
+ _ast_fltmax_exp_t a;
+ _ast_fltmax_exp_t b;
+ a.f = 1;
+ b.f = 2;
+ for (i = 0; i < sizeof(a.e) / sizeof(a.e[0]); i++)
+ if (e = a.e[i] ^ b.e[i])
+ {
+ for (j = i + 1; j < sizeof(a.e) / sizeof(a.e[0]); j++)
+ if (a.e[j] ^ b.e[j])
+ return 0;
+ printf("typedef union _fltmax_exp_u\n{\n\tuint32_t\t\te[sizeof(_ast_fltmax_t)/4];\n\t_ast_fltmax_t\t\tf;\n} _ast_fltmax_exp_t;\n\n");
+ printf("#define _ast_fltmax_exp_index\t%d\n", i);
+ for (i = 0; !(e & 1); e >>= 1, i++);
+ printf("#define _ast_fltmax_exp_shift\t%d\n\n", i);
+ return 0;
+ }
+ return 0;
+ }
+}end
+
+tst - -DN=1 - -DN=2 note{ _ast_fltmax_t maximum integral type }end output{
+ #include <stdio.h>
+ int
+ main()
+ {
+ #if N == 1
+ unsigned long long m;
+ long double f = 123.456;
+
+ m = f;
+ if (!m || f == m)
+ return 1;
+ printf("#define _ast_flt_unsigned_max_t unsigned long long\n");
+ #else
+ printf("#define _ast_flt_unsigned_max_t unsigned long\n");
+ #endif
+ return 0;
+ }
+}end
+
+tst - -DSCAN=1 - -lm -DSTRTO=1 - -DMAC=1 - -DDIV=1 - -DEXP=1 - -DADD=1 - -DMPY=1 note{ INF and NAN memory representations }end output{
+ #if MAC
+ #define _AIX_COMPATIBILITY 1
+ #define _FP_MODE_VARIABLE 1
+ #endif
+ #include "FEATURE/common"
+ #include <stdio.h>
+ #include <sys/types.h>
+ #include <signal.h>
+ #if _hdr_float
+ #include <float.h>
+ #endif
+ #if _hdr_limits
+ #include <limits.h>
+ #endif
+ #if _hdr_math
+ #include <math.h>
+ #endif
+ #if _hdr_values
+ #include <values.h>
+ #endif
+ #if STRTO && _hdr_stdlib
+ #include <stdlib.h>
+ #endif
+ #if !defined(FLT_MAX) && defined(MAXFLOAT)
+ #define FLT_MAX MAXFLOAT
+ #endif
+ #if !defined(DBL_MAX) && defined(MAXDOUBLE)
+ #define DBL_MAX MAXDOUBLE
+ #endif
+ #if _ast_fltmax_double
+ #undef LDBL_MAX
+ #endif
+ static void
+ #if _STD_
+ list(const char* typ, const char* var, void* val, int siz)
+ #else
+ list(typ, var, val, siz)
+ char* typ;
+ char* var;
+ void* val;
+ int siz;
+ #endif
+ {
+ register unsigned char* u = (unsigned char*)val;
+ register unsigned char* e = u + siz;
+
+ printf("#define _ast_%s_%s_init\t0x%02x", typ, var, *u);
+ while (++u < e)
+ printf(",0x%02x", *u);
+ printf("\n");
+ }
+ int
+ main()
+ {
+ #if SCAN || STRTO
+ #undef NAN
+ #define NAN "NaN"
+ #undef INF
+ #define INF "INF"
+ {
+ float f;
+
+ #if SCAN
+ if (sscanf(NAN, "%g", &f) != 1)
+ return 1;
+ #else
+ f = atof(NAN);
+ #endif
+ list("flt", "nan", &f, sizeof(f));
+ #if SCAN
+ if (sscanf(INF, "%g", &f) != 1)
+ return 1;
+ #else
+ f = atof(INF);
+ #endif
+ list("flt", "inf", &f, sizeof(f));
+ }
+ {
+ double f;
+ #if STRTO
+ char* e;
+ #endif
+
+ #if SCAN
+ if (sscanf(NAN, "%lg", &f) != 1)
+ return 1;
+ #else
+ f = strtod(NAN, &e);
+ if (*e)
+ return 1;
+ #endif
+ list("dbl", "nan", &f, sizeof(f));
+ #if SCAN
+ if (sscanf(INF, "%lg", &f) != 1)
+ return 1;
+ #else
+ f = strtod(INF, &e);
+ if (*e)
+ return 1;
+ #endif
+ list("dbl", "inf", &f, sizeof(f));
+ }
+ #ifdef LDBL_MAX
+ {
+ long double f;
+ #if STRTO
+ char* e;
+ #endif
+
+ #if SCAN
+ if (sscanf(NAN, "%Lg", &f) != 1)
+ return 1;
+ #else
+ f = strtold(NAN, &e);
+ if (*e)
+ return 1;
+ #endif
+ list("ldbl", "nan", &f, sizeof(f));
+ #if SCAN
+ if (sscanf(INF, "%Lg", &f) != 1)
+ return 1;
+ #else
+ f = strtold(INF, &e);
+ if (*e)
+ return 1;
+ #endif
+ list("ldbl", "inf", &f, sizeof(f));
+ }
+ #endif
+ #else
+ #ifdef SIGFPE
+ signal(SIGFPE, SIG_IGN);
+ #endif
+ #ifdef FLT_MAX
+ {
+ float f = FLT_MAX;
+ #if DIV
+ float z = 0;
+
+ f = 0.0 / z;
+ if (!f)
+ return 1;
+ list("flt", "nan", &f, sizeof(f));
+ f = 1.0 / z;
+ list("flt", "inf", &f, sizeof(f));
+ #else
+ #if ADD
+ f += f;
+ #endif
+ #if EXP
+ f = exp(f);
+ #endif
+ #if MPY
+ f *= 2;
+ #endif
+ #if MAC
+ f = FLT_QNAN;
+ #endif
+ list("flt", "nan", &f, sizeof(f));
+ #if MAC
+ f = FLT_INFINITY;
+ #endif
+ list("flt", "inf", &f, sizeof(f));
+ #endif
+ }
+ #endif
+ #ifdef DBL_MAX
+ {
+ double f = DBL_MAX;
+ #if DIV
+ double z = 0;
+
+ f = 0.0 / z;
+ if (!f)
+ return 1;
+ list("dbl", "nan", &f, sizeof(f));
+ f = 1.0 / z;
+ list("dbl", "inf", &f, sizeof(f));
+ #else
+ #if ADD
+ f += f;
+ #endif
+ #if EXP
+ f = exp(f);
+ #endif
+ #if MPY
+ f *= 2;
+ #endif
+ #if MAC
+ f = DBL_QNAN;
+ #endif
+ list("dbl", "nan", &f, sizeof(f));
+ #if MAC
+ f = DBL_INFINITY;
+ #endif
+ list("dbl", "inf", &f, sizeof(f));
+ #endif
+ }
+ #endif
+ #ifdef LDBL_MAX
+ {
+ long double f = LDBL_MAX;
+ #if DIV
+ long double z = 0;
+
+ f = 0.0 / z;
+ if (!f)
+ return 1;
+ list("ldbl", "nan", &f, sizeof(f));
+ f = 1.0 / z;
+ list("ldbl", "inf", &f, sizeof(f));
+ #else
+ #if ADD
+ f += f;
+ #endif
+ #if EXP
+ f = exp(f);
+ #endif
+ #if MPY
+ f *= 2;
+ #endif
+ #if MAC
+ f = LDBL_QNAN;
+ #endif
+ list("ldbl", "nan", &f, sizeof(f));
+ #if MAC
+ f = LDBL_INFINITY;
+ #endif
+ list("ldbl", "inf", &f, sizeof(f));
+ #endif
+ }
+ #endif
+ #endif
+ return 0;
+ }
+}end
diff --git a/src/lib/libast/features/fs b/src/lib/libast/features/fs
new file mode 100644
index 0000000..3caeedb
--- /dev/null
+++ b/src/lib/libast/features/fs
@@ -0,0 +1,251 @@
+set prototyped
+lib _fxstat,__fxstat,_lxstat,__lxstat,_xmknod,__xmknod,_xstat,__xstat,lstat,mknod,sync sys/types.h sys/stat.h
+lib _fxstat64,__fxstat64,_lxstat64,__lxstat64,_xstat64,__xstat64 -D_LARGEFILE64_SOURCE sys/types.h sys/stat.h
+mac fstat,lstat,stat,mknod sys/types.h sys/stat.h
+
+lcl xstat -D_LARGEFILE64_SOURCE link{
+ #include <sys/types.h>
+ #include <sys/stat.h>
+ struct stat64 { int xxx; }; /* disable if stat64 available */
+ #if _STD_
+ extern int stat(const char* path, struct stat* st)
+ #else
+ int stat(path, st)
+ char* path;
+ struct stat* st;
+ #endif
+ {
+ #if _lib___xstat
+ return __xstat(_STAT_VER, path, st);
+ #else
+ return _xstat(_STAT_VER, path, st);
+ #endif
+ }
+ int
+ main()
+ {
+ struct stat st;
+ return stat(".",&st) < 0;
+ }
+}end
+
+lcl xstat64 -D_LARGEFILE64_SOURCE link{
+ #include <sys/types.h>
+ #include <sys/stat.h>
+ #if _STD_
+ extern int stat64(const char* path, struct stat64* st)
+ #else
+ int stat64(path, st)
+ char* path;
+ #endif
+ {
+ #if _lib___xstat64
+ return __xstat64(_STAT_VER, path, st);
+ #else
+ return _xstat64(_STAT_VER, path, st);
+ #endif
+ }
+ int
+ main()
+ {
+ struct stat64 st;
+ return stat64(".",&st) < 0;
+ }
+}end
+
+header sys/stat.h
+header sys/mkdev.h
+
+extern chmod int (const char*, mode_t)
+extern fstat int (int, struct stat*)
+extern lstat int (const char*, struct stat*)
+extern mkdir int (const char*, mode_t)
+extern mkfifo int (const char*, mode_t)
+extern mknod int (const char*, mode_t, dev_t)
+extern stat int (const char*, struct stat*)
+
+define FS_default "ufs"
+
+macro{
+ #include <sys/types.h>
+ #include <sys/stat.h>
+ #ifndef major
+ #include <sys/param.h>
+ #ifndef major
+ #include <sys/sysmacros.h>
+ #endif
+ <<"#if defined(__STDPP__directive) && defined(__STDPP__initial)">>
+ <<"__STDPP__directive pragma pp:initial">>
+ <<"#endif">>
+ <<"#ifndef major">>
+ #ifdef major
+ <<"#define major(x)">> major((x))
+ #else
+ #ifndef L_BITSMAJOR
+ #define L_BITSMAJOR 8
+ #endif
+ #ifndef L_BITSMINOR
+ #define L_BITSMINOR 8
+ #endif
+ #ifndef L_MAXMAJ
+ #define L_MAXMAJ ((1<<L_BITSMAJOR)-1)
+ #endif
+ #ifndef L_MAXMIN
+ #define L_MAXMIN ((1<<L_BITSMINOR)-1)
+ #endif
+ <<"#define major(x)">> ((int)(((unsigned)(x)>>L_BITSMINOR)&L_MAXMAJ))
+ #endif
+ <<"#endif">>
+ <<"#ifndef minor">>
+ #ifdef minor
+ <<"#define minor(x)">> minor((x))
+ #else
+ <<"#define minor(x)">> ((int)((x)&L_MAXMIN))
+ #endif
+ <<"#endif">>
+ <<"#ifndef makedev">>
+ #ifdef makedev
+ <<"#define makedev(x,y)">> makedev((x),(y))
+ #else
+ <<"#define makedev(x,y)">> ((dev_t)((((x)&0377)<<8)|((y)&0377)))
+ #endif
+ <<"#endif">>
+ #endif
+ <<"#if defined(__STDPP__directive) && defined(__STDPP__initial)">>
+ <<"__STDPP__directive pragma pp:noinitial">>
+ <<"#endif">>
+}end fail{
+ cat <<!
+ #ifndef major
+ #define major(x) ((int)(((unsigned)(x)>>8)&0377))
+ #endif
+ #ifndef minor
+ #define minor(x) ((int)((x)&0377))
+ #endif
+ #ifndef makedev
+ #define makedev(x,y) ((dev_t)((((x)&0377)<<8)|((y)&0377)))
+ #endif
+ !
+}end
+
+hdr mntent,mnttab stdio.h
+sys mntent,mnttab stdio.h
+sys fs_types,mount,statfs,statvfs,vfs,vmount sys/param.h sys/ucred.h
+
+mem mnttab.mt_dev,mnttab.mt_filsys,mnttab.mt_fstyp sys/types.h mnttab.h
+mem mntent.mnt_opts,w_mntent.mnt_opts,mnttab.mnt_opts sys/types.h stdio.h mntent.h sys/mntent.h
+mem mntent.mnt_opts,mnttab.mnt_opts stdio.h sys/types.h mnttab.h sys/mnttab.h
+mem stat.st_blocks,stat.st_blksize,stat.st_rdev sys/types.h sys/stat.h
+mem statfs.f_files,statfs.f_bavail sys/types.h - sys/statfs.h - sys/vfs.h - sys/param.h sys/mount.h
+mem statvfs.f_basetype,statvfs.f_frsize sys/types.h sys/statvfs.h
+
+ary f_reserved7 sys/types.h sys/statvfs.h note{ statvfs.f_reserved7 can double for statvfs.f_basetype }end compile{
+ int f(vp)struct statvfs* vp;{return vp->f_reserved7[0] = 1;}
+}end
+
+lib getfsstat,getmntent,getmntinfo,mntctl,mntopen,mntread,mntclose,setmntent
+lib w_getmntent
+lib statfs,statvfs
+
+lib statfs4 sys/types.h - sys/statfs.h - sys/vfs.h - sys/mount.h compile{
+ int f()
+ {
+ struct statfs fs;
+ return statfs("/",&fs,sizeof(fs),0);
+ }
+}end
+
+lib getmntinfo_statvfs note{ getmntinfo uses statvfs -- since when? }end compile{
+ #include <sys/types.h>
+ #include <sys/mount.h>
+ int
+ gmi(struct statvfs* fs)
+ {
+ fs->f_flag = 0;
+ return getmntinfo(fs, 0);
+ }
+}end
+
+lib getfsstat_statvfs note{ getfsstat uses statvfs -- just in case it is confused like getmntinfo }end compile{
+ #include <sys/types.h>
+ #include <sys/mount.h>
+ int
+ gfs(struct statvfs* fs)
+ {
+ fs->f_flag = 0;
+ return getfsstat(fs, sizeof(struct statvfs), MNT_WAIT);
+ }
+}end
+
+cat{
+ #if _sys_statvfs
+ #include <sys/statvfs.h>
+ #if !_mem_statvfs_f_basetype
+ #if _ary_f_reserved7
+ #define f_basetype f_reserved7
+ #endif
+ #endif
+ #else
+ #define _mem_f_basetype_statvfs 1
+ #define _mem_f_frsize_statvfs 1
+ struct statvfs
+ {
+ unsigned long f_bsize; /* fundamental file system block size */
+ unsigned long f_frsize; /* fragment size */
+ unsigned long f_blocks; /* total # of blocks of f_frsize on fs */
+ unsigned long f_bfree; /* total # of free blocks of f_frsize */
+ unsigned long f_bavail; /* # of free blocks avail to non-superuser */
+ unsigned long f_files; /* total # of file nodes (inodes) */
+ unsigned long f_ffree; /* total # of free file nodes */
+ unsigned long f_favail; /* # of free nodes avail to non-superuser */
+ unsigned long f_fsid; /* file system id (dev for now) */
+ char f_basetype[16]; /* target fs type name, null-terminated */
+ unsigned long f_flag; /* bit-mask of flags */
+ unsigned long f_namemax; /* maximum file name length */
+ char f_fstr[32]; /* filesystem-specific string */
+ unsigned long f_filler[16]; /* reserved for future expansion */
+ };
+ extern int fstatvfs(int, struct statvfs*);
+ extern int statvfs(const char*, struct statvfs*);
+ #endif
+ #if _typ_off64_t
+ #undef off_t
+ #define off_t off64_t
+ #endif
+ #if _lib_statvfs64 && !defined(statvfs)
+ #define statvfs statvfs64
+ #if !defined(__USE_LARGEFILE64)
+ extern int statvfs64(const char*, struct statvfs64*);
+ #endif
+ #endif
+ #if _lib_fstatvfs64 && !defined(fstatvfs)
+ #define fstatvfs fstatvfs64
+ #if !defined(__USE_LARGEFILE64)
+ extern int fstatvfs64(int, struct statvfs64*);
+ #endif
+ #endif
+}end
+
+str st_fstype sys/types.h sys/stat.h note{ stat.st_fstype is a string }end compile{
+ int f(st)struct stat* st;{return st->st_fstype[0];}
+}end
+
+int st_fstype sys/types.h sys/stat.h note{ stat.st_fstype is an int }end compile{
+ int f(st)struct stat* st;{return st->st_fstype = 1;}
+}end
+
+int st_spare1 sys/types.h sys/stat.h note{ stat.st_spare1 is an int }end compile{
+ int f(st)struct stat* st;{return st->st_spare1 = 1;}
+}end
+
+ary st_spare4 sys/types.h sys/stat.h note{ stat.st_spare4 is an array }end compile{
+ int f(st)struct stat* st;{return st->st_spare4[0] = 1;}
+}end
+
+ary st_extra sys/types.h sys/stat.h note{ stat.st_extra is an array }end compile{
+ int f(st)struct stat* st;{return st->st_extra[0] = 1;}
+}end
+
+ary st_pad4 sys/types.h sys/stat.h note{ stat.st_pad4 is an array }end compile{
+ int f(st)struct stat* st;{return st->st_pad4[0] = 1;}
+}end
diff --git a/src/lib/libast/features/hack b/src/lib/libast/features/hack
new file mode 100644
index 0000000..2be7af9
--- /dev/null
+++ b/src/lib/libast/features/hack
@@ -0,0 +1 @@
+hdr locale_attr
diff --git a/src/lib/libast/features/iconv b/src/lib/libast/features/iconv
new file mode 100644
index 0000000..92fd62f
--- /dev/null
+++ b/src/lib/libast/features/iconv
@@ -0,0 +1,116 @@
+set prototyped
+hdr iconv
+lib iconv_open,iconv_close,iconv iconv.h -liconv
+nxt iconv
+
+tst output{
+ #if !_lib_iconv_open
+ #define _undef_hdr_iconv 1
+ #undef _hdr_iconv
+ #endif
+ #if !_hdr_iconv
+ #define _undef_lib_iconv_open 1
+ #undef _lib_iconv_open
+ #endif
+ #if _hdr_iconv
+ #include <sys/types.h>
+ #include <iconv.h>
+ #endif
+
+ int
+ main()
+ {
+ char* lib;
+
+ printf("#include <ast_common.h>\n");
+ printf("#include <ccode.h>\n");
+ #if _undef_hdr_iconv
+ printf("#undef _hdr_iconv\n");
+ #endif
+ #if _undef_lib_iconv_open
+ printf("#undef _lib_iconv_open\n");
+ #endif
+ #if _hdr_iconv && defined(_nxt_iconv_str)
+ printf("#include <%s> /* the native iconv.h */\n", _nxt_iconv_str);
+ #endif
+ printf("\n");
+ printf("#define ICONV_VERSION 20110111L\n");
+ printf("\n");
+ printf("#define ICONV_FATAL 0x02\n");
+ printf("#define ICONV_OMIT 0x04\n");
+ printf("\n");
+ printf("#define CC_ICONV (-1)\n");
+ printf("#define CC_UCS (-2)\n");
+ printf("#define CC_SCU (-3)\n");
+ printf("#define CC_UTF (-4)\n");
+ printf("#define CC_UME (-5)\n");
+ printf("\n");
+ #if _lib_iconv_open
+ lib = "_ast_";
+ printf("#ifndef _ICONV_LIST_PRIVATE_\n");
+ printf("#undef iconv_t\n");
+ printf("#define iconv_t %siconv_t\n", lib);
+ printf("#undef iconv_f\n");
+ printf("#define iconv_f %siconv_f\n", lib);
+ printf("#undef iconv_list_t\n");
+ printf("#define iconv_list_t %siconv_list_t\n", lib);
+ printf("#undef iconv_open\n");
+ printf("#define iconv_open %siconv_open\n", lib);
+ printf("#undef iconv\n");
+ printf("#define iconv %siconv\n", lib);
+ printf("#undef iconv_close\n");
+ printf("#define iconv_close %siconv_close\n", lib);
+ printf("#undef iconv_list\n");
+ printf("#define iconv_list %siconv_list\n", lib);
+ printf("#undef iconv_move\n");
+ printf("#define iconv_move %siconv_move\n", lib);
+ printf("#undef iconv_name\n");
+ printf("#define iconv_name %siconv_name\n", lib);
+ printf("#undef iconv_write\n");
+ printf("#define iconv_write %siconv_write\n", lib);
+ printf("#endif\n");
+ #else
+ lib = "";
+ #endif
+ printf("\n");
+ printf("typedef int (*Iconv_error_f)(void*, void*, int, ...);\n");
+ printf("\n");
+ printf("typedef struct Iconv_disc_s\n");
+ printf("{\n");
+ printf(" uint32_t version;\n");
+ printf(" Iconv_error_f errorf;\n");
+ printf(" size_t errors;\n");
+ printf(" uint32_t flags;\n");
+ printf(" int fill;\n");
+ printf("} Iconv_disc_t;\n");
+ printf("\n");
+ printf("typedef Ccmap_t %siconv_list_t;\n", lib);
+ printf("typedef void* %siconv_t;\n", lib);
+ printf("typedef size_t (*%siconv_f)(%siconv_t, char**, size_t*, char**, size_t*);\n", lib, lib);
+ printf("\n");
+ printf("#define iconv_init(d,e) (memset(d,0,sizeof(*(d))),(d)->version=ICONV_VERSION,(d)->errorf=(Iconv_error_f)(e),(d)->fill=(-1))\n");
+ printf("\n");
+ printf("#if _BLD_ast && defined(__EXPORT__)\n");
+ printf("#define extern __EXPORT__\n");
+ printf("#endif\n");
+ printf("\n");
+ printf("extern %siconv_t %siconv_open(const char*, const char*);\n", lib, lib);
+ printf("extern size_t %siconv(%siconv_t, char**, size_t*, char**, size_t*);\n", lib, lib);
+ printf("extern int %siconv_close(%siconv_t);\n", lib, lib);
+ printf("extern %siconv_list_t* %siconv_list(%siconv_list_t*);\n", lib, lib, lib);
+ printf("extern int %siconv_name(const char*, char*, size_t);\n", lib);
+ printf("#if _SFIO_H\n");
+ printf("extern ssize_t %siconv_move(%siconv_t, Sfio_t*, Sfio_t*, size_t, Iconv_disc_t*);\n", lib, lib);
+ printf("extern ssize_t %siconv_write(%siconv_t, Sfio_t*, char**, size_t*, Iconv_disc_t*);\n", lib, lib);
+ printf("#else\n");
+ printf("#if _SFSTDIO_H\n");
+ printf("extern ssize_t %siconv_move(%siconv_t, FILE*, FILE*, size_t, Iconv_disc_t*);\n", lib, lib);
+ printf("extern ssize_t %siconv_write(%siconv_t, FILE*, char**, size_t*, Iconv_disc_t*);\n", lib, lib);
+ printf("#endif\n");
+ printf("#endif\n");
+ printf("\n");
+ printf("#undef extern\n");
+ printf("\n");
+ return 0;
+ }
+}end
diff --git a/src/lib/libast/features/isoc99 b/src/lib/libast/features/isoc99
new file mode 100644
index 0000000..e85c9f5
--- /dev/null
+++ b/src/lib/libast/features/isoc99
@@ -0,0 +1,13 @@
+if tst -D_ISOC99_SOURCE -lm note{ _ISOC99_SOURCE plays nice }end link{
+ #include <sys/types.h>
+ #include <sys/stat.h>
+ #include <stdlib.h>
+ #include <unistd.h>
+ #include <math.h>
+ int main() { return signbit(-0.0); }
+ }end {
+ #ifndef _ISOC99_SOURCE
+ #define _ISOC99_SOURCE 1
+ #endif
+ }
+endif
diff --git a/src/lib/libast/features/lib b/src/lib/libast/features/lib
new file mode 100644
index 0000000..763c91d
--- /dev/null
+++ b/src/lib/libast/features/lib
@@ -0,0 +1,664 @@
+ref -D_def_map_ast=1
+
+cmd universe
+
+hdr dirent,direntry,filio,fmtmsg,fnmatch,jioctl,libgen,limits
+hdr locale,ndir,nl_types,process,spawn,syslog,utime,vfork
+hdr wchar note{ <wchar.h> and isw*() really work }end execute{
+ #include <wchar.h>
+ int
+ main()
+ {
+ wchar_t w = 'a';
+ return iswalnum(w) == 0;
+ }
+}end
+hdr wctype wchar.h
+
+dat _tzname,tzname
+
+lib BSDsetpgrp
+lib _cleanup
+lib atexit,bcopy,bzero,catclose,catgets,catopen,confstr,dirread,dup2
+lib execlp,execve,execvp,execvpe
+lib fchmod,fcntl,fmtmsg,fnmatch,fork,fsync
+lib getconf,getdents,getdirentries,getdtablesize,getdate
+lib getgroups,gethostname,getlogin,getpagesize,getrlimit,getuniverse
+lib getopt,getsubopt,getopt_long,getopt_long_only
+lib glob,index,iswblank,iswctype,killpg,link,localeconv,madvise
+lib mbtowc,mbrtowc,memalign,memchr,memcpy,memdup,memmove,memset
+lib mkdir,mkfifo,mktemp,mktime
+lib mount,on_exit,onexit,opendir,pathconf
+lib readlink,remove,rename,rewinddir,rindex,rmdir,setlocale
+lib setpgid,setpgrp,setpgrp2,setreuid,setsid,setuid,sigaction
+lib sigprocmask,sigsetmask,sigunblock,sigvec,socketpair
+lib spawn,spawnve,spawnveg
+lib strchr,strcoll,strdup,strerror,strcasecmp,strncasecmp,strrchr,strstr
+lib strmode,strxfrm,strftime,swab,symlink,sysconf,sysinfo,syslog
+lib telldir,tmpnam,tzset,universe,unlink,utime,wctype
+lib ftruncate,truncate
+lib creat64,fstat64,fstatvfs64,ftruncate64 -D_LARGEFILE64_SOURCE
+lib lseek64,lstat64 -D_LARGEFILE64_SOURCE
+lib open64,readdir64,stat64,statvfs64,truncate64 -D_LARGEFILE64_SOURCE
+
+lib,npt strtod,strtold,strtol,strtoll,strtoul,strtoull stdlib.h
+lib,npt sigflag signal.h
+
+mem direct.d_reclen sys/types.h sys/dir.h
+mem dirent.d_fileno,dirent.d_ino,dirent.d_namlen,dirent.d_off,dirent.d_reclen,dirent.d_type sys/types.h dirent.h
+mem DIR sys/types.h - dirent.h - sys/dir.h
+mem DIR.dd_fd sys/types.h - dirent.h - sys/dir.h
+mem inheritance.pgroup spawn.h
+
+sys dir,filio,jioctl,localedef,ptem,resource
+sys socket,stream,systeminfo,universe,vfork
+
+typ off64_t -D_LARGEFILE64_SOURCE
+typ struct.dirent64 -D_LARGEFILE64_SOURCE dirent.h
+
+tst tst_errno note{ errno can be assigned }end link{
+ _BEGIN_EXTERNS_
+ #define error ______error
+ #define strerror ______strerror
+ #include <errno.h>
+ #undef error
+ #undef strerror
+ #ifndef errno
+ extern int errno;
+ #endif
+ error() { }
+ strerror() { }
+ _END_EXTERNS_
+ int main() { errno = 0; error(); strerror(); return 0; }
+}end
+
+tst lib_poll_fd_1 note{ fd is first arg to poll() }end execute{
+ #include <poll.h>
+ _BEGIN_EXTERNS_
+ extern int pipe _ARG_((int*));
+ _END_EXTERNS_
+ int
+ main()
+ { int rw[2];
+ struct pollfd fd;
+ if (pipe(rw) < 0) return 1;
+ fd.fd = rw[0];
+ fd.events = POLLIN;
+ fd.revents = 0;
+ if (poll(&fd, 1, 0) < 0 || fd.revents != 0) return 1;
+ if (write(rw[1], "x", 1) != 1) return 1;
+ if (poll(&fd, 1, 0) < 0 || fd.revents == 0) return 1;
+ return 0;
+ }
+}end
+
+tst lib_poll_fd_2 note{ fd is second arg to poll() }end execute{
+ #include <poll.h>
+ _BEGIN_EXTERNS_
+ extern int pipe _ARG_((int*));
+ _END_EXTERNS_
+ int
+ main()
+ { int rw[2];
+ struct pollfd fd;
+ if (pipe(rw) < 0) return 1;
+ fd.fd = rw[0];
+ fd.events = POLLIN;
+ fd.revents = 0;
+ return poll(1, &fd, 0) < 0;
+ if (poll(1, &fd, 0) < 0 || fd.revents != 0) return 1;
+ if (write(rw[1], "x", 1) != 1) return 1;
+ if (poll(1, &fd, 0) < 0 || fd.revents == 0) return 1;
+ return 0;
+ }
+}end
+
+exp _lib_poll _lib_poll_fd_1||_lib_poll_fd_2
+
+tst lib_poll_notimer note{ poll with no fds ignores timeout }end execute{
+ #include <sys/types.h>
+ #include <poll.h>
+ _BEGIN_EXTERNS_
+ extern time_t time _ARG_((time_t*));
+ _END_EXTERNS_
+ #define TIMEOUT 4
+ int
+ main()
+ {
+ unsigned long start;
+ unsigned long finish;
+ struct pollfd fd;
+ start = time((time_t*)0);
+ if (poll(&fd, 0, TIMEOUT * 1000) < 0)
+ return 0;
+ finish = time((time_t*)0);
+ return (finish - start) > (TIMEOUT / 2);
+ }
+}end
+
+tst lib_select note{ select() has standard 5 arg interface }end link{
+ #include <sys/types.h>
+ #include <sys/time.h>
+ #include <sys/socket.h>
+ int
+ main()
+ { struct timeval tmb;
+ fd_set rd;
+ FD_ZERO(&rd);
+ FD_SET(0,&rd);
+ tmb.tv_sec = 0;
+ tmb.tv_usec = 0;
+ select(1,&rd,(fd_set*)0,(fd_set*)0,&tmb);
+ return 0;
+ }
+}end
+
+tst pipe_rw note{ full duplex pipes }end execute{
+ _BEGIN_EXTERNS_
+ extern int pipe _ARG_((int*));
+ extern int read _ARG_((int, void*, int));
+ extern int strcmp _ARG_((const char*, const char*));
+ extern int write _ARG_((int, void*, int));
+ _END_EXTERNS_
+ int
+ main()
+ {
+ #if defined(__sgi) || defined(_sgi) || defined(sgi)
+ /* boot tuneable pipes force one way for bin compatibility */
+ return 1;
+ #else
+ static char test[] = "test\n";
+ int io[2];
+ char buf[sizeof(test)];
+ if (pipe(io)) return 1;
+ if (write(io[1], test, sizeof(test)) != sizeof(test)) return 1;
+ if (read(io[0], buf, sizeof(test)) != sizeof(test)) return 1;
+ if (strcmp(test, buf)) return 1;
+ if (write(io[0], test, sizeof(test)) != sizeof(test)) return 1;
+ if (read(io[1], buf, sizeof(test)) != sizeof(test)) return 1;
+ if (strcmp(test, buf)) return 1;
+ return 0;
+ #endif
+ }
+}end
+
+tst lib_vfork unistd.h stdlib.h vfork.h note{ vfork exists and it works }end execute{
+ #include <signal.h>
+ int
+ main(argc, argv)
+ int argc;
+ char** argv;
+ {
+ int status;
+ char* cmd[3];
+ if (argv[1])
+ _exit(signal(SIGHUP, SIG_DFL) != SIG_IGN);
+ signal(SIGHUP, SIG_IGN);
+ switch (vfork())
+ {
+ case -1:
+ _exit(1);
+ case 0:
+ cmd[0] = argv[0];
+ cmd[1] = "test";
+ cmd[2] = 0;
+ execv(cmd[0], cmd);
+ _exit(2);
+ }
+ status = 1;
+ _exit(wait(&status) < 0 || status != 0);
+ }
+}end
+
+tst real_vfork note{ vfork child shares data with parent }end execute{
+ _BEGIN_EXTERNS_
+ extern int _exit _ARG_((int));
+ extern int vfork _ARG_((void));
+ _END_EXTERNS_
+ int code;
+ int
+ main()
+ {
+ code = 1;
+ if (!vfork())
+ code = 0;
+ _exit(code);
+ }
+}end
+
+tst lib_posix_spawn unistd.h stdlib.h spawn.h -Dfork=______fork note{ posix_spawn exists and it works and its worth using }end status{
+ #include <sys/types.h>
+ #include <sys/stat.h>
+ #include <sys/wait.h>
+ #include <spawn.h>
+ #include <signal.h>
+ #include <fcntl.h>
+ #include <string.h>
+ #undef fork
+ /* if it uses fork() why bother? */
+ pid_t fork _ARG_((void)) { return -1; }
+ pid_t _fork _ARG_((void)) { return -1; }
+ pid_t __fork _ARG_((void)) { return -1; }
+ int
+ main(argc, argv)
+ int argc;
+ char** argv;
+ {
+ char* s;
+ pid_t pid;
+ posix_spawnattr_t attr;
+ int n;
+ int status;
+ char* cmd[3];
+ char tmp[1024];
+ if (argv[1])
+ _exit(signal(SIGHUP, SIG_DFL) != SIG_IGN);
+ signal(SIGHUP, SIG_IGN);
+ if (posix_spawnattr_init(&attr))
+ _exit(0);
+ if (posix_spawnattr_setpgroup(&attr, 0))
+ _exit(0);
+ if (posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETPGROUP))
+ _exit(0);
+ /* first try an a.out and verify that SIGHUP is ignored */
+ cmd[0] = argv[0];
+ cmd[1] = "test";
+ cmd[2] = 0;
+ if (posix_spawn(&pid, cmd[0], 0, &attr, cmd, 0))
+ _exit(0);
+ status = 1;
+ if (wait(&status) < 0 || status != 0)
+ _exit(0);
+ /* passing ENOEXEC to the shell is bogus */
+ n = strlen(cmd[0]);
+ if (n >= (sizeof(tmp) - 3))
+ _exit(0);
+ strcpy(tmp, cmd[0]);
+ tmp[n] = '.';
+ tmp[n+1] = 's';
+ tmp[n+2] = 'h';
+ tmp[n+3] = 0;
+ if (close(open(tmp, O_CREAT, S_IRWXU|S_IRWXG|S_IRWXO)) < 0 || chmod(tmp, S_IRWXU|S_IRWXG|S_IRWXO) < 0)
+ _exit(0);
+ cmd[0] = tmp;
+ n = 0;
+ pid = -1;
+ if (posix_spawn(&pid, cmd[0], 0, &attr, cmd, 0))
+ n = 2;
+ else
+ {
+ n = pid != -1 && waitpid(pid, &status, WNOHANG|WNOWAIT) == pid && ((status>>8)&0x7f) == 127;
+ wait(&status);
+ }
+ _exit(n);
+ }
+}end
+
+tst lib_spawn_mode unistd.h stdlib.h note{ first spawn arg is mode and it works }end execute{
+ #include <signal.h>
+ #include <process.h>
+ #ifndef P_NOWAIT
+ #define P_NOWAIT _P_NOWAIT
+ #endif
+ int
+ main(argc, argv)
+ int argc;
+ char** argv;
+ {
+ int status;
+ char* cmd[3];
+ if (argv[1])
+ _exit(signal(SIGHUP, SIG_DFL) != SIG_IGN);
+ signal(SIGHUP, SIG_IGN);
+ cmd[0] = argv[0];
+ cmd[1] = "test";
+ cmd[2] = 0;
+ if (spawnv(P_NOWAIT, cmd[0], cmd) < 0)
+ _exit(1);
+ status = 1;
+ _exit(wait(&status) < 0 || status != 0);
+ }
+}end
+
+tst stream_peek note{ ioctl(I_PEEK) works on pipe() }end execute{
+ #include <sys/types.h>
+ #include <unistd.h>
+ #include <stropts.h>
+ int
+ main()
+ { struct strpeek peek;
+ int fds[2];
+ char ctlbuf[32];
+ char databuf[32];
+ peek.flags = 0;
+ peek.ctlbuf.maxlen = peek.ctlbuf.len = sizeof(ctlbuf);
+ peek.ctlbuf.buf = ctlbuf;
+ peek.databuf.maxlen = peek.databuf.len = sizeof(databuf);
+ peek.databuf.buf = databuf;
+ pipe(fds);
+ return ioctl(fds[0],I_PEEK,&peek) < 0;
+ }
+}end
+
+tst socket_peek note{ recv(MSG_PEEK) works on socketpair() }end execute{
+ #include <unistd.h>
+ #include <sys/types.h>
+ #include <sys/socket.h>
+ int
+ main()
+ {
+ int i;
+ int fds[2];
+ char buf[128];
+
+ static char msg[] = "abcd";
+
+ if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds))
+ return 1;
+ if (write(fds[1], msg, sizeof(msg)) != sizeof(msg))
+ return 1;
+ if (recv(fds[0], buf, sizeof(buf), MSG_PEEK) != sizeof(msg))
+ return 1;
+ for (i = 0; i < sizeof(msg); i++)
+ if (buf[i] != msg[i])
+ return 1;
+ if (read(fds[0], buf, sizeof(msg)) != sizeof(msg))
+ return 1;
+ for (i = 0; i < sizeof(msg); i++)
+ if (buf[i] != msg[i])
+ return 1;
+ return 0;
+ }
+}end
+
+tst lib_memcmp string.h note{ standard memcmp interface that works }end execute{
+ /* sgi again -- we're sick of being their regression test */
+ #define L 8
+ char a[L] = { '0' };
+ char b[L] = { '1' };
+ int
+ main()
+ {
+ return memcmp(a, b, L) >= 0;
+ }
+}end
+
+tst lib_memccpy string.h unistd.h stdlib.h fcntl.h signal.h sys/types.h sys/stat.h sys/mman.h fcntl.h note{ standard memccpy interface that works }end execute{
+ #if _STD_
+ static void gotcha(int sig)
+ #else
+ static int gotcha(sig) int sig;
+ #endif
+ {
+ exit(1);
+ }
+ #ifdef MAP_PRIVATE
+ static const char x[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxN";
+ #if _STD_
+ static int indict_sgi_ia64_4Q_2004(int n)
+ #else
+ static int indict_sgi_ia64_4Q_2004(n) int n;
+ #endif
+ {
+ char* b;
+ char* s;
+ char* e;
+ char* t;
+ long m;
+ int d;
+ char u[1024];
+
+ static char p[32] = {'/','t','m','p','/','m','m'};
+
+ for (d = 7; d < 13; d++)
+ p[d] = 'X';
+ p[d] = 0;
+ if ((d = mkstemp(p)) < 0)
+ return 1;
+ remove(p);
+ for (m = 0; m < n; m++)
+ if (write(d, x, sizeof(x)-1) != sizeof(x)-1)
+ {
+ close(d);
+ return 1;
+ }
+ if (lseek(d, (off_t)0, SEEK_SET))
+ {
+ close(d);
+ return 1;
+ }
+ m = n * (sizeof(x)-1);
+ if (!(b = mmap((void*)0, m, PROT_READ|PROT_WRITE, MAP_PRIVATE, d, (off_t)0)))
+ {
+ close(d);
+ return 1;
+ }
+ for (e = (s = b) + m; s < e && (t = memccpy(u, s, 'N', (e-s) > sizeof(u) ? sizeof(u) : (e-s))); s += (t-u))
+ if ((t-u) != (sizeof(x)-1) || memcmp(u, s, t-u))
+ {
+ close(d);
+ return 1;
+ }
+ if (s < e)
+ {
+ close(d);
+ return 1;
+ }
+ close(d);
+ return 0;
+ }
+ #endif
+
+ int
+ main ()
+ {
+ char buf[1024];
+ #ifdef MAP_PRIVATE
+ char* srcbuf;
+ char* dstbuf;
+ int fd;
+ size_t siz;
+ int i;
+ #endif
+
+ #if defined(__ia64) || defined(__ia64__) || defined(__itanium__)
+ /*
+ * 0 faith that the itanium coders will ever get this right
+ * prove me wrong
+ */
+
+ return 1;
+ #endif
+
+ /*
+ * early mac osx failed here -- fixed 3Q 2001
+ */
+
+ if (memccpy(buf, "abc", 0, sizeof(buf)) != (buf + 4))
+ return 1;
+ #ifdef MAP_PRIVATE
+ siz = 64 * 1024;
+ if (!(dstbuf = malloc(2 * siz)))
+ return 0;
+ if ((fd = open("/dev/zero", O_RDWR)) < 0)
+ return 0;
+ if (!(srcbuf = (char*)mmap(NULL, siz, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0)))
+ return 0;
+ if (!mmap(srcbuf + siz, siz, PROT_NONE, MAP_PRIVATE, fd, 0))
+ return 0;
+ for (i = 0; i < siz; i++)
+ srcbuf[i] = 'x';
+ srcbuf[siz - 1] = 0;
+ alarm(10);
+ signal(SIGSEGV, gotcha);
+ signal(SIGBUS, gotcha);
+ signal(SIGALRM, gotcha);
+ /*
+ * sgi ia64 dumps here as of 3Q 2001
+ * bug acknowleged 1Q 2003
+ */
+ memccpy(dstbuf, srcbuf, 0, siz + 10);
+ alarm(0);
+ if (strcmp(srcbuf, dstbuf))
+ return 1;
+ if (indict_sgi_ia64_4Q_2004(1))
+ return 1;
+ if (indict_sgi_ia64_4Q_2004(257))
+ return 1;
+ #endif
+ return 0;
+ }
+}end
+
+tst lib_utime_now note{ utime works with 0 time vector }end execute{
+ #include <sys/types.h>
+ _BEGIN_EXTERNS_
+ extern int utime _ARG_((const char*, void*));
+ _END_EXTERNS_
+ int
+ main()
+ {
+ return utime(".", (void*)0) == -1;
+ }
+}end
+
+tst cross{
+ u=att
+ case `/bin/cat -s /dev/null/foo 2>&1` in
+ '') ;;
+ *) case `/bin/echo '\\t'` in
+ '\t') u=ucb ;;
+ esac
+ ;;
+ esac
+ echo "#define _UNIV_DEFAULT \"$u\" /* default universe name */"
+}end
+
+std cleanup note{ stuck with standard _cleanup }end noexecute{
+ _BEGIN_EXTERNS_
+ extern void exit _ARG_((int));
+ extern void _exit _ARG_((int));
+ extern void _cleanup();
+ void _cleanup() { _exit(0); }
+ _END_EXTERNS_
+ int main() { printf("cleanup\n"); exit(1); }
+}end
+
+std remove note{ stuck with standard remove() }end nostatic{
+ _BEGIN_EXTERNS_
+ extern int unlink _ARG_((const char*));
+ _END_EXTERNS_
+ #if _STD_
+ int remove(const char* path) { return 0; }
+ #else
+ int remove(path) char* path; { return 0; }
+ #endif
+ int main() { return unlink("foo"); }
+}end
+
+std signal note{ stuck with standard signal }end nolink{
+ _BEGIN_EXTERNS_
+ extern int abort();
+ int signal() { return 0; }
+ _END_EXTERNS_
+ int main() { signal(); abort(); return 0; }
+}end
+
+std strcoll note{ standard strcoll works }end execute{
+ #include <string.h>
+ #define S "hello world"
+ int
+ main()
+ {
+ char s[] = S;
+ char t[] = S;
+ return strcoll(s, t) || strcmp(s, t);
+ }
+}end
+
+std strtod stdlib.h note{ stuck with standard strtod }end nostatic{
+ _BEGIN_EXTERNS_
+ #if _STD_
+ double strtod(const char* s, char** e) { return 0.0; }
+ #else
+ double strtod(s, e) char* s; char** e; { return 0.0; }
+ #endif
+ _END_EXTERNS_
+ int main() { printf(""); return strtod("1",0) != 0; }
+}end
+
+std strtold stdlib.h note{ stuck with standard strtold }end nostatic{
+ _BEGIN_EXTERNS_
+ #if _STD_
+ long double strtold(const char* s, char** e) { return 0.0; }
+ #else
+ long double strtold(s, e) char* s; char** e; { return 0.0; }
+ #endif
+ _END_EXTERNS_
+ int main() { printf(""); return strtold("1",0) != 0; }
+}end
+
+std strtol note{ stuck with standard strtol }end nostatic{
+ _BEGIN_EXTERNS_
+ #if _STD_
+ extern long atol(const char*);
+ long strtol(const char* s, char** e, int b) { return 0; }
+ #else
+ extern long atol();
+ long strtol(s, e, b) char* s; char** e; int b; { return 0; }
+ #endif
+ _END_EXTERNS_
+ int main() { printf(""); return (atol("1") + strtol("1",(char**)0,0)) != 0; }
+}end
+
+tst - output{
+ int
+ main()
+ {
+ #if _UWIN
+ printf("\n");
+ printf("/* override some uwin feature tests */\n");
+ printf("#undef _lib_execlp\n");
+ printf("#undef _lib_execvp\n");
+ printf("#undef _lib_execvpe\n");
+ printf("#undef _lib_fork\n");
+ printf("#undef _std_string\n");
+ printf("#define _std_string 1\n");
+ printf("#undef _stream_peek\n");
+ printf("\n");
+ #endif
+
+ #if _lib_spawnveg || _lib_posix_spawn || _lib_spawn_mode || _lib_spawn && _hdr_spawn && _mem_pgroup_inheritance || _lib_vfork && _real_vfork
+ printf("#if !_AST_no_spawnveg\n");
+ printf("#define _use_spawnveg 1\n");
+ printf("#endif\n");
+ printf("\n");
+ #endif
+
+ return 0;
+ }
+
+}end
+
+tst no64 -D_LARGEFILE64_SOURCE note{ largefile 64 broken }end execute{
+ #include <sys/types.h>
+ #include <sys/stat.h>
+ int
+ main()
+ {
+ struct stat64 st;
+ return !stat64(".", &st) && st.st_mode && st.st_mtime;
+ }
+}end pass{
+ echo "/* can we at least agree that a successful return means success? */"
+ echo "#undef _lib_creat64"
+ echo "#undef _lib_fstat64"
+ echo "#undef _lib_fstatvfs64"
+ echo "#undef _lib_ftruncate64"
+ echo "#undef _lib_lseek64"
+ echo "#undef _lib_lstat64"
+ echo "#undef _lib_mmap64"
+ echo "#undef _lib_stat64"
+ echo "#undef _lib_statvfs64"
+ echo "#undef _lib_truncate64"
+}end
diff --git a/src/lib/libast/features/libpath.sh b/src/lib/libast/features/libpath.sh
new file mode 100644
index 0000000..b3809fd
--- /dev/null
+++ b/src/lib/libast/features/libpath.sh
@@ -0,0 +1,73 @@
+########################################################################
+# #
+# This software is part of the ast package #
+# Copyright (c) 1985-2011 AT&T Intellectual Property #
+# and is licensed under the #
+# Eclipse Public License, Version 1.0 #
+# by AT&T Intellectual Property #
+# #
+# A copy of the License is available at #
+# http://www.eclipse.org/org/documents/epl-v10.html #
+# (with md5 checksum b35adb5213ca9657e911e9befb180842) #
+# #
+# Information and Software Systems Research #
+# AT&T Research #
+# Florham Park NJ #
+# #
+# Glenn Fowler <gsf@research.att.com> #
+# David Korn <dgk@research.att.com> #
+# Phong Vo <kpv@research.att.com> #
+# #
+########################################################################
+ok=0
+for i in \
+ -x /lib/ld.so /lib/ld-*.so /usr/lib/ld.so /lib/rld \
+ -f /usr/shlib/libc.so /shlib/libc.so /usr/lib/libc.so \
+ -r /usr/shlib/libc.so /shlib/libc.so
+do case $i in
+ -*) op=$i; continue ;;
+ esac
+ if test $op $i
+ then ok=1
+ break
+ fi
+ set x $i.[0-9]*
+ if test $op $2
+ then ok=1
+ break
+ fi
+done
+if test "0" != "$ok"
+then libpath=lib:LD_LIBRARY_PATH
+ case `package` in
+ sgi.*) if test -d /lib32
+ then libpath="lib32:LD_LIBRARYN32_PATH:sgi.mips3|sgi.*-n32,$libpath"
+ fi
+ if test -d /lib64
+ then libpath="lib64:LD_LIBRARY64_PATH:sgi.mips[4-9]|sgi.*-64,$libpath"
+ fi
+ ;;
+ sol*.*) if test -d /lib/32
+ then libpath="lib/32:LD_LIBRARY_PATH_32,$libpath"
+ fi
+ if test -d /lib/64
+ then libpath="lib/64:LD_LIBRARY_PATH_64:sol.*64*,$libpath"
+ fi
+ ;;
+ esac
+elif test -x /lib/dld.sl
+then libpath=lib:SHLIB_PATH
+elif test -x /usr/lib/dyld
+then libpath=lib:DYLD_LIBRARY_PATH
+else case `package` in
+ ibm.*|mvs.*)
+ libpath=lib:LIBPATH
+ ;;
+ *) libpath=
+ ;;
+ esac
+fi
+case $libpath in
+'') libpath=bin ;;
+esac
+echo "#define CONF_LIBPATH \"$libpath\""
diff --git a/src/lib/libast/features/limits.c b/src/lib/libast/features/limits.c
new file mode 100644
index 0000000..c6e82df
--- /dev/null
+++ b/src/lib/libast/features/limits.c
@@ -0,0 +1,339 @@
+/***********************************************************************
+* *
+* This software is part of the ast package *
+* Copyright (c) 1985-2011 AT&T Intellectual Property *
+* and is licensed under the *
+* Eclipse Public License, Version 1.0 *
+* by AT&T Intellectual Property *
+* *
+* A copy of the License is available at *
+* http://www.eclipse.org/org/documents/epl-v10.html *
+* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
+* *
+* Information and Software Systems Research *
+* AT&T Research *
+* Florham Park NJ *
+* *
+* Glenn Fowler <gsf@research.att.com> *
+* David Korn <dgk@research.att.com> *
+* Phong Vo <kpv@research.att.com> *
+* *
+***********************************************************************/
+#pragma prototyped
+/*
+ * Glenn Fowler
+ * AT&T Research
+ *
+ * generate limits features
+ *
+ * FOPEN_MAX POSIX says ANSI defines it but it's not in ANSI
+ *
+ * NOTE: two's complement binary integral representation assumed
+ */
+
+#if defined(__STDPP__directive) && defined(__STDPP__hide)
+__STDPP__directive pragma pp:hide getpagesize getdtablesize
+#else
+#define getpagesize ______getpagesize
+#define getdtablesize ______getdtablesize
+#endif
+
+/*
+ * we'd like as many symbols as possible defined
+ * the standards push the vendors the other way
+ * but don't provide guard that lets everything through
+ * so each vendor adds their own guard
+ * many now include something like <standards.h> to
+ * get it straight in one place -- <sys/types.h> should
+ * kick that in
+ */
+
+#include "FEATURE/standards"
+#include "FEATURE/lib"
+
+#ifdef __sun
+#define _timespec timespec
+#endif
+
+#include <sys/types.h>
+
+#undef _SGIAPI
+#define _SGIAPI 1
+
+#if _hdr_limits
+#include <limits.h>
+#endif
+
+#undef _SGIAPI
+#define _SGIAPI 0
+
+#include "FEATURE/lib"
+#include "FEATURE/common"
+
+#if _hdr_unistd
+#include <unistd.h>
+#endif
+
+#include "FEATURE/param"
+
+#if defined(__STDPP__directive) && defined(__STDPP__hide)
+__STDPP__directive pragma pp:nohide getpagesize getdtablesize
+#else
+#undef getpagesize
+#undef getdtablesize
+#endif
+
+int main()
+{
+ char c;
+ unsigned char uc;
+ unsigned short us;
+ unsigned int ui;
+ unsigned long ul;
+ unsigned long val;
+#if _typ_uint64_t
+ uint64_t ull;
+ uint64_t vll;
+#endif
+
+ /*
+ * <limits.h> with *constant* valued macros
+ */
+
+ printf("\n");
+#ifndef CHAR_BIT
+ uc = 0;
+ uc = ~uc;
+ val = 1;
+ while (uc >>= 1) val++;
+ printf("#define CHAR_BIT %lu\n", val);
+#endif
+#ifndef MB_LEN_MAX
+ val = 1;
+ printf("#define MB_LEN_MAX %lu\n", val);
+#endif
+
+ c = 0;
+ c = ~c;
+ uc = 0;
+ uc = ~uc;
+ us = 0;
+ us = ~us;
+ ui = 0;
+ ui = ~ui;
+ ul = 0;
+ ul = ~ul;
+#if _typ_uint64_t
+ ull = 0;
+ ull = ~ull;
+#endif
+
+#ifndef UCHAR_MAX
+ val = uc;
+ printf("#if defined(__STDC__)\n");
+ printf("#define UCHAR_MAX %luU\n", val);
+ printf("#else\n");
+ printf("#define UCHAR_MAX %lu\n", val);
+ printf("#endif\n");
+#endif
+
+#ifndef SCHAR_MIN
+ val = (unsigned char)(uc >> 1) + 1;
+ printf("#define SCHAR_MIN (-%lu)\n", val);
+#endif
+
+#ifndef SCHAR_MAX
+ val = (unsigned char)(uc >> 1);
+ printf("#define SCHAR_MAX %lu\n", val);
+#endif
+
+ if (c < 0)
+ {
+#ifndef CHAR_MIN
+ printf("#define CHAR_MIN SCHAR_MIN\n");
+#endif
+
+#ifndef CHAR_MAX
+ printf("#define CHAR_MAX SCHAR_MAX\n");
+#endif
+ }
+ else
+ {
+#ifndef CHAR_MIN
+ printf("#define CHAR_MIN 0\n");
+#endif
+
+#ifndef CHAR_MAX
+ printf("#define CHAR_MAX UCHAR_MAX\n");
+#endif
+ }
+
+#ifndef USHRT_MAX
+ val = us;
+ printf("#if defined(__STDC__)\n");
+ printf("#define USHRT_MAX %luU\n", val);
+ printf("#else\n");
+ printf("#define USHRT_MAX %lu\n", val);
+ printf("#endif\n");
+#endif
+
+#ifndef SHRT_MIN
+ val = (unsigned short)(us >> 1) + 1;
+ printf("#define SHRT_MIN (-%lu)\n", val);
+#endif
+
+#ifndef SHRT_MAX
+ val = (unsigned short)(us >> 1);
+ printf("#define SHRT_MAX %lu\n", val);
+#endif
+
+ if (ui == us)
+ {
+#ifndef UINT_MAX
+ printf("#define UINT_MAX USHRT_MAX\n");
+#endif
+
+#ifndef INT_MIN
+ printf("#define INT_MIN SHRT_MIN\n");
+#endif
+
+#ifndef INT_MAX
+ printf("#define INT_MAX SHRT_MAX\n");
+#endif
+ }
+ else
+ {
+#ifndef UINT_MAX
+ val = ui;
+ printf("#if defined(__STDC__)\n");
+ printf("#define UINT_MAX %luU\n", val);
+ printf("#else\n");
+ printf("#define UINT_MAX %lu\n", val);
+ printf("#endif\n");
+#endif
+
+#ifndef INT_MIN
+ val = (unsigned int)(ui >> 1) + 1;
+ if (ui == ul) printf("#define INT_MIN (-%lu-1)\n", val - 1);
+ else printf("#define INT_MIN (-%lu)\n", val);
+#endif
+
+#ifndef INT_MAX
+ val = (unsigned int)(ui >> 1);
+ printf("#define INT_MAX %lu\n", val);
+#endif
+ }
+
+ if (ul == ui)
+ {
+#ifndef ULONG_MAX
+ printf("#define ULONG_MAX UINT_MAX\n");
+#endif
+
+#ifndef LONG_MIN
+ printf("#define LONG_MIN INT_MIN\n");
+#endif
+
+#ifndef LONG_MAX
+ printf("#define LONG_MAX INT_MAX\n");
+#endif
+ }
+ else
+ {
+#ifndef ULONG_MAX
+ val = ul;
+ printf("#if defined(__STDC__)\n");
+ printf("#define ULONG_MAX %luLU\n", val);
+ printf("#else\n");
+ printf("#define ULONG_MAX %lu\n", val);
+ printf("#endif\n");
+#endif
+
+#ifndef LONG_MIN
+ val = (unsigned long)(ul >> 1) + 1;
+ printf("#define LONG_MIN (-%luL-1L)\n", val - 1);
+#endif
+
+#ifndef LONG_MAX
+ val = (unsigned long)(ul >> 1);
+ printf("#define LONG_MAX %luL\n", val);
+#endif
+ }
+
+#if _typ_uint64_t && !_ast_intmax_long
+ if (ull == ul)
+ {
+#ifndef ULLONG_MAX
+ printf("#define ULLONG_MAX ULONG_MAX\n");
+#endif
+
+#ifndef LLONG_MIN
+ printf("#define LLONG_MIN LONG_MIN\n");
+#endif
+
+#ifndef LLONG_MAX
+ printf("#define LLONG_MAX LONG_MAX\n");
+#endif
+ }
+ else
+ {
+#ifndef ULLONG_MAX
+ vll = ull;
+ printf("#ifndef ULLONG_MAX\n");
+ printf("#if defined(__STDC__) && _ast_LL\n");
+ printf("#define ULLONG_MAX %lluULL\n", vll);
+ printf("#else\n");
+ printf("#define ULLONG_MAX %llu\n", vll);
+ printf("#endif\n");
+ printf("#endif\n");
+#endif
+
+#ifndef LLONG_MIN
+ vll = (uint64_t)(ull >> 1) + 1;
+ printf("#ifndef LLONG_MIN\n");
+ printf("#if defined(__STDC__) && _ast_LL\n");
+ printf("#define LLONG_MIN (-%lluLL-1LL)\n", vll - 1);
+ printf("#else\n");
+ printf("#define LLONG_MIN (-%llu-1)\n", vll - 1);
+ printf("#endif\n");
+ printf("#endif\n");
+#endif
+
+#ifndef LLONG_MAX
+ vll = (uint64_t)(ull >> 1);
+ printf("#ifndef LLONG_MAX\n");
+ printf("#if defined(__STDC__) && _ast_LL\n");
+ printf("#define LLONG_MAX %lluLL\n", vll);
+ printf("#else\n");
+ printf("#define LLONG_MAX %llu\n", vll);
+ printf("#endif\n");
+ printf("#endif\n");
+#endif
+ }
+#endif
+
+ printf("\n");
+#ifdef _UWIN
+ printf("#ifdef _UWIN\n");
+ printf("#ifndef DBL_DIG\n");
+ printf("#define DBL_DIG 15\n");
+ printf("#endif\n");
+ printf("#ifndef DBL_MAX\n");
+ printf("#define DBL_MAX 1.7976931348623158e+308\n");
+ printf("#endif\n");
+ printf("#ifndef FLT_DIG\n");
+ printf("#define FLT_DIG 6\n");
+ printf("#endif\n");
+ printf("#ifndef FLT_MAX\n");
+ printf("#define FLT_MAX 3.402823466e+38F\n");
+ printf("#endif\n");
+ printf("#endif\n");
+ printf("\n");
+#endif
+
+#include "conflim.h"
+
+ printf("\n");
+
+ return 0;
+}
diff --git a/src/lib/libast/features/locale b/src/lib/libast/features/locale
new file mode 100644
index 0000000..ffd1988
--- /dev/null
+++ b/src/lib/libast/features/locale
@@ -0,0 +1,28 @@
+tst - note{ canonical UTF-8 name }end run{
+ ifs=$IFS
+ str=
+ sys=
+ for i in `PATH=/bin:/usr/bin:$PATH locale -a | grep -i '^[^C].*\.UTF[-8]*$'`
+ do IFS=.
+ set '' $i
+ IFS=$ifs
+ case $3 in
+ UTF-8) str=$3
+ break
+ ;;
+ *) if $SHELL -c "LC_CTYPE=$2.UTF-8 PATH=/bin:/usr/bin:$PATH locale LC_CTYPE | grep -i utf.*8" >/dev/null 2>&1
+ then str=UTF-8
+ break
+ fi
+ ;;
+ esac
+ sys=$3
+ done
+ case $str in
+ '') str=$sys ;;
+ esac
+ case $str in
+ '') echo "#define _locale_utf8_str 0" ;;
+ *) echo "#define _locale_utf8_str \"$str\"" ;;
+ esac
+}end
diff --git a/src/lib/libast/features/map.c b/src/lib/libast/features/map.c
new file mode 100644
index 0000000..52c35aa
--- /dev/null
+++ b/src/lib/libast/features/map.c
@@ -0,0 +1,565 @@
+/***********************************************************************
+* *
+* This software is part of the ast package *
+* Copyright (c) 1985-2011 AT&T Intellectual Property *
+* and is licensed under the *
+* Eclipse Public License, Version 1.0 *
+* by AT&T Intellectual Property *
+* *
+* A copy of the License is available at *
+* http://www.eclipse.org/org/documents/epl-v10.html *
+* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
+* *
+* Information and Software Systems Research *
+* AT&T Research *
+* Florham Park NJ *
+* *
+* Glenn Fowler <gsf@research.att.com> *
+* David Korn <dgk@research.att.com> *
+* Phong Vo <kpv@research.att.com> *
+* *
+***********************************************************************/
+#pragma prototyped
+
+/*
+ * some systems may pull in <ast_common.h> and its <ast_map.h>
+ * which we are in the process of generating ... this prevents it
+ */
+
+#define _def_map_ast 1
+
+#include "FEATURE/lib"
+#include "FEATURE/mmap"
+#include "FEATURE/options"
+#include "FEATURE/vmalloc"
+#include "FEATURE/eaccess"
+#include "FEATURE/api"
+
+#if _opt_map_libc && !defined(_map_libc)
+#define _map_libc 1
+#endif
+
+int
+main()
+{
+ printf("#pragma prototyped\n");
+ printf("\n");
+ printf("/*\n");
+ printf(" * prototypes provided for standard interfaces hijacked\n");
+ printf(" * by ast and mapped to _ast_* but already prototyped\n");
+ printf(" * unmapped in native headers included by <ast_std.h>\n");
+ printf(" */\n");
+ printf("\n");
+ printf("#if _BLD_ast && defined(__EXPORT__)\n");
+ printf("#define extern __EXPORT__\n");
+ printf("#endif\n");
+ printf("\n");
+#if __MVS__
+#undef _map_libc
+#define _map_libc 1
+ printf("\n");
+ printf("/* mvs.390 libc.dll routines can't be intercepted by user dlls */\n");
+ printf("#undef _mem_dd_fd_DIR\n");
+ printf("#undef _typ_long_double\n");
+#endif
+#if _map_libc
+#undef _map_malloc
+#define _map_malloc 1
+ printf("\n");
+ printf("#define _map_libc 1\n");
+ printf("#undef basename\n");
+ printf("#define basename _ast_basename\n");
+ printf("#undef dirname\n");
+ printf("#define dirname _ast_dirname\n");
+#if !_lib_eaccess
+ printf("#undef eaccess\n");
+ printf("#define eaccess _ast_eaccess\n");
+#endif
+#if !_lib_execvpe
+ printf("#undef execvpe\n");
+ printf("#define execvpe _ast_execvpe\n");
+ printf("extern int execvpe(const char*, char* const[], char* const[]);\n");
+#endif
+ printf("#undef fnmatch\n");
+ printf("#define fnmatch _ast_fnmatch\n");
+ printf("#undef fts_children\n");
+ printf("#define fts_children _ast_fts_children\n");
+ printf("#undef fts_close\n");
+ printf("#define fts_close _ast_fts_close\n");
+ printf("#undef fts_flags\n");
+ printf("#define fts_flags _ast_fts_flags\n");
+ printf("#undef fts_notify\n");
+ printf("#define fts_notify _ast_fts_notify\n");
+ printf("#undef fts_open\n");
+ printf("#define fts_open _ast_fts_open\n");
+ printf("#undef fts_read\n");
+ printf("#define fts_read _ast_fts_read\n");
+ printf("#undef fts_set\n");
+ printf("#define fts_set _ast_fts_set\n");
+ printf("#undef ftw\n");
+ printf("#define ftw _ast_ftw\n");
+ printf("#undef ftwalk\n");
+ printf("#define ftwalk _ast_ftwalk\n");
+ printf("#undef ftwflags\n");
+ printf("#define ftwflags _ast_ftwflags\n");
+#if !_WINIX
+ printf("#undef getcwd\n");
+ printf("#define getcwd _ast_getcwd\n");
+ printf("extern char* getcwd(char*, size_t);\n");
+#endif
+ printf("#undef getdate\n");
+ printf("#define getdate _ast_getdate\n");
+#if _lib_getopt || _lib_getsubopt || _lib_getopt_long || _lib_getopt_long_only
+ printf("#undef getopt\n");
+ printf("#define getopt _ast_getopt\n");
+ printf("#undef getsubopt\n");
+ printf("#define getsubopt _ast_getsubopt\n");
+ printf("#undef getopt_long\n");
+ printf("#define getopt_long _ast_getopt_long\n");
+ printf("#undef getopt_long_only\n");
+ printf("#define getopt_long_only _ast_getopt_long_only\n");
+ printf("#undef optopt\n");
+ printf("#define optopt _ast_optopt\n");
+ printf("#undef optarg\n");
+ printf("#define optarg _ast_optarg\n");
+ printf("#undef optind\n");
+ printf("#define optind _ast_optind\n");
+ printf("#undef opterr\n");
+ printf("#define opterr _ast_opterr\n");
+#endif
+ printf("#undef getwd\n");
+ printf("#define getwd _ast_getwd\n");
+ printf("extern char* getwd(char*);\n");
+ printf("#undef glob\n");
+ printf("#define glob _ast_glob\n");
+ printf("#undef globfree\n");
+ printf("#define globfree _ast_globfree\n");
+ printf("#undef memdup\n");
+ printf("#define memdup _ast_memdup\n");
+ printf("#undef memfatal\n");
+ printf("#define memfatal _ast_memfatal\n");
+ printf("#undef memhash\n");
+ printf("#define memhash _ast_memhash\n");
+ printf("#undef memsum\n");
+ printf("#define memsum _ast_memsum\n");
+ printf("#undef mkstemp\n");
+ printf("#define mkstemp _ast_mkstemp\n");
+ printf("extern int mkstemp(char*);\n");
+ printf("#undef mktemp\n");
+ printf("#define mktemp _ast_mktemp\n");
+ printf("extern char* mktemp(char*);\n");
+ printf("#undef mktime\n");
+ printf("#define mktime _ast_mktime\n");
+ printf("#undef nftw\n");
+ printf("#define nftw _ast_nftw\n");
+ printf("#undef optctx\n");
+ printf("#define optctx _ast_optctx\n");
+ printf("#undef optesc\n");
+ printf("#define optesc _ast_optesc\n");
+ printf("#undef optget\n");
+ printf("#define optget _ast_optget\n");
+ printf("#undef opthelp\n");
+ printf("#define opthelp _ast_opthelp\n");
+ printf("#undef optjoin\n");
+ printf("#define optjoin _ast_optjoin\n");
+ printf("#undef optstr\n");
+ printf("#define optstr _ast_optstr\n");
+ printf("#undef optusage\n");
+ printf("#define optusage _ast_optusage\n");
+ printf("#undef pathaccess\n");
+ printf("#define pathaccess _ast_pathaccess\n");
+ printf("#undef pathbin\n");
+ printf("#define pathbin _ast_pathbin\n");
+ printf("#undef pathcanon\n");
+ printf("#define pathcanon _ast_pathcanon\n");
+ printf("#undef pathcat\n");
+ printf("#define pathcat _ast_pathcat\n");
+ printf("#undef pathcd\n");
+ printf("#define pathcd _ast_pathcd\n");
+ printf("#undef pathcheck\n");
+ printf("#define pathcheck _ast_pathcheck\n");
+ printf("#undef pathexists\n");
+ printf("#define pathexists _ast_pathexists\n");
+ printf("#undef pathfind\n");
+ printf("#define pathfind _ast_pathfind\n");
+ printf("#undef pathgetlink\n");
+ printf("#define pathgetlink _ast_pathgetlink\n");
+ printf("#undef pathinclude\n");
+ printf("#define pathinclude _ast_pathinclude\n");
+ printf("#undef pathkey\n");
+ printf("#define pathkey _ast_pathkey\n");
+ printf("#undef pathnative\n");
+ printf("#define pathnative _ast_pathnative\n");
+ printf("#undef pathpath\n");
+ printf("#define pathpath _ast_pathpath\n");
+ printf("#undef pathposix\n");
+ printf("#define pathposix _ast_pathposix\n");
+ printf("#undef pathprobe\n");
+ printf("#define pathprobe _ast_pathprobe\n");
+ printf("#undef pathprog\n");
+ printf("#define pathprog _ast_pathprog\n");
+ printf("#undef pathrepl\n");
+ printf("#define pathrepl _ast_pathrepl\n");
+ printf("#undef pathsetlink\n");
+ printf("#define pathsetlink _ast_pathsetlink\n");
+ printf("#undef pathshell\n");
+ printf("#define pathshell _ast_pathshell\n");
+ printf("#undef pathstat\n");
+ printf("#define pathstat _ast_pathstat\n");
+ printf("#undef pathtemp\n");
+ printf("#define pathtemp _ast_pathtemp\n");
+ printf("#undef pathtmp\n");
+ printf("#define pathtmp _ast_pathtmp\n");
+ printf("#undef procclose\n");
+ printf("#define procclose _ast_procclose\n");
+ printf("#undef procfree\n");
+ printf("#define procfree _ast_procfree\n");
+ printf("#undef procopen\n");
+ printf("#define procopen _ast_procopen\n");
+ printf("#undef procrun\n");
+ printf("#define procrun _ast_procrun\n");
+ printf("#undef putenv\n");
+ printf("#define putenv _ast_putenv\n");
+ printf("#undef re_comp\n");
+ printf("#define re_comp _ast_re_comp\n");
+ printf("#undef re_exec\n");
+ printf("#define re_exec _ast_re_exec\n");
+ printf("#undef realpath\n");
+ printf("#define realpath _ast_realpath\n");
+ printf("extern char* realpath(const char*, char*);\n");
+ printf("#undef regaddclass\n");
+ printf("#define regaddclass _ast_regaddclass\n");
+ printf("#undef regalloc\n");
+ printf("#define regalloc _ast_regalloc\n");
+ printf("#undef regcache\n");
+ printf("#define regcache _ast_regcache\n");
+ printf("#undef regclass\n");
+ printf("#define regclass _ast_regclass\n");
+ printf("#undef regcmp\n");
+ printf("#define regcmp _ast_regcmp\n");
+ printf("#undef regcollate\n");
+ printf("#define regcollate _ast_regcollate\n");
+ printf("#undef regcomb\n");
+ printf("#define regcomb _ast_regcomb\n");
+ printf("#undef regcomp\n");
+ printf("#define regcomp _ast_regcomp\n");
+ printf("#undef regdecomp\n");
+ printf("#define regdecomp _ast_regdecomp\n");
+ printf("#undef regdup\n");
+ printf("#define regdup _ast_regdup\n");
+ printf("#undef regerror\n");
+ printf("#define regerror _ast_regerror\n");
+ printf("#undef regex\n");
+ printf("#define regex _ast_regex\n");
+ printf("#undef regexec\n");
+ printf("#define regexec _ast_regexec\n");
+ printf("#undef regfatal\n");
+ printf("#define regfatal _ast_regfatal\n");
+ printf("#undef regfatalpat\n");
+ printf("#define regfatalpat _ast_regfatalpat\n");
+ printf("#undef regfree\n");
+ printf("#define regfree _ast_regfree\n");
+ printf("#undef regncomp\n");
+ printf("#define regncomp _ast_regncomp\n");
+ printf("#undef regnexec\n");
+ printf("#define regnexec _ast_regnexec\n");
+ printf("#undef regrecord\n");
+ printf("#define regrecord _ast_regrecord\n");
+ printf("#undef regrexec\n");
+ printf("#define regrexec _ast_regrexec\n");
+ printf("#undef regstat\n");
+ printf("#define regstat _ast_regstat\n");
+ printf("#undef regsub\n");
+ printf("#define regsub _ast_regsub\n");
+ printf("#undef regsubcomp\n");
+ printf("#define regsubcomp _ast_regsubcomp\n");
+ printf("#undef regsubexec\n");
+ printf("#define regsubexec _ast_regsubexec\n");
+ printf("#undef regsubflags\n");
+ printf("#define regsubflags _ast_regsubflags\n");
+ printf("#undef regsubfree\n");
+ printf("#define regsubfree _ast_regsubfree\n");
+ printf("#undef remove\n");
+ printf("#define remove _ast_remove\n");
+ printf("extern int remove(const char*);\n");
+ printf("#undef resolvepath\n");
+ printf("#define resolvepath _ast_resolvepath\n");
+ printf("extern int resolvepath(const char*, char*, size_t);\n");
+ printf("#undef setenv\n");
+ printf("#define setenv _ast_setenv\n");
+ printf("extern int setenv(const char*, const char*, int);\n");
+ printf("#undef setenviron\n");
+ printf("#define setenviron _ast_setenviron\n");
+ printf("#undef sigcritical\n");
+ printf("#define sigcritical _ast_sigcritical\n");
+ printf("#undef signal\n");
+ printf("#define signal _ast_signal\n");
+ printf("#undef sigunblock\n");
+ printf("#define sigunblock _ast_sigunblock\n");
+ printf("#undef stracmp\n");
+ printf("#define stracmp _ast_stracmp\n");
+ printf("#undef strcopy\n");
+ printf("#define strcopy _ast_strcopy\n");
+ printf("#undef strelapsed\n");
+ printf("#define strelapsed _ast_strelapsed\n");
+ printf("#undef stresc\n");
+ printf("#define stresc _ast_stresc\n");
+ printf("#undef streval\n");
+ printf("#define streval _ast_streval\n");
+ printf("#undef strexpr\n");
+ printf("#define strexpr _ast_strexpr\n");
+ printf("#undef strftime\n");
+ printf("#define strftime _ast_strftime\n");
+ printf("#undef strgid\n");
+ printf("#define strgid _ast_strgid\n");
+ printf("#undef strgrpmatch\n");
+ printf("#define strgrpmatch _ast_strgrpmatch\n");
+ printf("#undef strhash\n");
+ printf("#define strhash _ast_strhash\n");
+ printf("#undef strkey\n");
+ printf("#define strkey _ast_strkey\n");
+ printf("#undef strlcat\n");
+ printf("#define strlcat _ast_strlcat\n");
+ printf("extern size_t strlcat(char*, const char*, size_t);\n");
+ printf("#undef strlcpy\n");
+ printf("#define strlcpy _ast_strlcpy\n");
+ printf("extern size_t strlcpy(char*, const char*, size_t);\n");
+ printf("#undef strlook\n");
+ printf("#define strlook _ast_strlook\n");
+ printf("#undef strmatch\n");
+ printf("#define strmatch _ast_strmatch\n");
+#endif
+#if _map_libc || _lib_strmode
+ printf("#undef strmode\n");
+ printf("#define strmode _ast_strmode\n");
+#endif
+#if _map_libc
+ printf("#undef strnacmp\n");
+ printf("#define strnacmp _ast_strnacmp\n");
+ printf("#undef strncopy\n");
+ printf("#define strncopy _ast_strncopy\n");
+ printf("#undef strntod\n");
+ printf("#define strntod _ast_strntod\n");
+ printf("#undef strntol\n");
+ printf("#define strntol _ast_strntol\n");
+ printf("#undef strntold\n");
+ printf("#define strntold _ast_strntold\n");
+ printf("#undef strntoll\n");
+ printf("#define strntoll _ast_strntoll\n");
+ printf("#undef strntoul\n");
+ printf("#define strntoul _ast_strntoul\n");
+ printf("#undef strntoull\n");
+ printf("#define strntoull _ast_strntoull\n");
+ printf("#undef stropt\n");
+ printf("#define stropt _ast_stropt\n");
+ printf("#undef strperm\n");
+ printf("#define strperm _ast_strperm\n");
+ printf("#undef strpsearch\n");
+ printf("#define strpsearch _ast_strpsearch\n");
+#if !_lib_strptime
+ printf("#undef strptime\n");
+ printf("#define strptime _ast_strptime\n");
+#endif
+ printf("#undef strsearch\n");
+ printf("#define strsearch _ast_strsearch\n");
+ printf("#undef strsort\n");
+ printf("#define strsort _ast_strsort\n");
+ printf("#undef strsubmatch\n");
+ printf("#define strsubmatch _ast_strsubmatch\n");
+ printf("#undef strsum\n");
+ printf("#define strsum _ast_strsum\n");
+ printf("#undef strtape\n");
+ printf("#define strtape _ast_strtape\n");
+ printf("#undef strtoip4\n");
+ printf("#define strtoip4 _ast_strtoip4\n");
+ printf("#undef strton\n");
+ printf("#define strton _ast_strton\n");
+ printf("#undef strtonll\n");
+ printf("#define strtonll _ast_strtonll\n");
+ printf("#undef struid\n");
+ printf("#define struid _ast_struid\n");
+ printf("#undef struniq\n");
+ printf("#define struniq _ast_struniq\n");
+ printf("#undef system\n");
+ printf("#define system _ast_system\n");
+ printf("extern int system(const char*);\n");
+ printf("#undef tempnam\n");
+ printf("#define tempnam _ast_tempnam\n");
+ printf("extern char* tempnam(const char*, const char*);\n");
+ printf("#undef tmpnam\n");
+ printf("#define tmpnam _ast_tmpnam\n");
+ printf("extern char* tmpnam(char*);\n");
+ printf("#undef touch\n");
+ printf("#define touch _ast_touch\n");
+ printf("#undef wordexp\n");
+ printf("#define wordexp _ast_wordexp\n");
+ printf("#undef wordfree\n");
+ printf("#define wordfree _ast_wordfree\n");
+ printf("#undef unsetenv\n");
+ printf("#define unsetenv _ast_unsetenv\n");
+#endif
+#if _std_malloc
+ printf("\n");
+ printf("/* no local malloc override */\n");
+ printf("#define _std_malloc 1\n");
+#else
+#if _map_malloc
+ printf("\n");
+ printf("/* cannot override local malloc */\n");
+ printf("#define _map_malloc 1\n");
+ printf("#undef calloc\n");
+ printf("#define calloc _ast_calloc\n");
+ printf("extern void* calloc(size_t, size_t);\n");
+ printf("#undef cfree\n");
+ printf("#define cfree _ast_cfree\n");
+ printf("extern void cfree(void*);\n");
+ printf("#undef free\n");
+ printf("#define free _ast_free\n");
+ printf("extern void free(void*);\n");
+#if _lib_mallinfo
+ printf("#undef mallinfo\n");
+ printf("#define mallinfo _ast_mallinfo\n");
+#endif
+ printf("#undef malloc\n");
+ printf("#define malloc _ast_malloc\n");
+ printf("extern void* malloc(size_t);\n");
+#if _lib_mallopt
+ printf("#undef mallopt\n");
+ printf("#define mallopt _ast_mallopt\n");
+#endif
+#if _lib_memalign
+ printf("#undef memalign\n");
+ printf("#define memalign _ast_memalign\n");
+ printf("extern void* memalign(size_t, size_t);\n");
+#endif
+#if _lib_mstats
+ printf("#undef mstats\n");
+ printf("#define mstats _ast_mstats\n");
+#endif
+#if _lib_pvalloc
+ printf("#undef pvalloc\n");
+ printf("#define pvalloc _ast_pvalloc\n");
+#endif
+ printf("#undef realloc\n");
+ printf("#define realloc _ast_realloc\n");
+ printf("extern void* realloc(void*, size_t);\n");
+ printf("#undef strdup\n");
+ printf("#define strdup _ast_strdup\n");
+ printf("extern char* strdup(const char*);\n");
+#if _lib_valloc
+ printf("#undef valloc\n");
+ printf("#define valloc _ast_valloc\n");
+ printf("extern void* valloc(size_t);\n");
+#endif
+#endif
+#endif
+
+ /*
+ * overriding <stdlib.h> strto*() is problematic to say the least
+ */
+
+#if _map_libc || _std_strtol
+#if !__CYGWIN__
+ printf("#undef strtol\n");
+ printf("#define strtol _ast_strtol\n");
+ printf("#undef strtoul\n");
+ printf("#define strtoul _ast_strtoul\n");
+#endif
+ printf("#undef strtoll\n");
+ printf("#define strtoll _ast_strtoll\n");
+ printf("#undef strtoull\n");
+ printf("#define strtoull _ast_strtoull\n");
+#endif
+#if _map_libc || _std_strtod
+ printf("#undef strtod\n");
+ printf("#define strtod _ast_strtod\n");
+#endif
+#if _map_libc || _std_strtold
+ printf("#undef strtold\n");
+ printf("#define strtold _ast_strtold\n");
+#endif
+#if !__CYGWIN__
+#if _npt_strtol || _map_libc || _std_strtol
+#if _npt_strtol && !_map_libc && !_std_strtol
+ printf("#ifndef _ISOC99_SOURCE\n");
+#endif
+ printf("extern long strtol(const char*, char**, int);\n");
+#if _npt_strtol && !_map_libc && !_std_strtol
+ printf("#endif\n");
+#endif
+#endif
+#if _npt_strtoul || _map_libc || _std_strtol
+#if _npt_strtoul && !_map_libc && !_std_strtol
+ printf("#ifndef _ISOC99_SOURCE\n");
+#endif
+ printf("extern unsigned long strtoul(const char*, char**, int);\n");
+#if _npt_strtoul && !_map_libc && !_std_strtol
+ printf("#endif\n");
+#endif
+#endif
+#endif
+#if _npt_strtod || _map_libc || _std_strtod
+#if _npt_strtod && !_map_libc && !_std_strtod
+ printf("#ifndef _ISOC99_SOURCE\n");
+#endif
+ printf("extern double strtod(const char*, char**);\n");
+#if _npt_strtod && !_map_libc && !_std_strtod
+ printf("#endif\n");
+#endif
+#endif
+ printf("#if !_UWIN\n");
+ printf("#undef extern\n");
+ printf("#endif\n");
+#if _npt_strtold || _map_libc || _std_strtold
+#if _npt_strtold && !_map_libc && !_std_strtold
+ printf("#ifndef _ISOC99_SOURCE\n");
+#endif
+ printf("extern _ast_fltmax_t strtold(const char*, char**);\n");
+#if _npt_strtold && !_map_libc && !_std_strtold
+ printf("#endif\n");
+#endif
+#endif
+ printf("#undef extern\n");
+#if _npt_strtoll || _map_libc || _std_strtol
+#if _npt_strtoll && !_map_libc && !_std_strtol
+ printf("#ifndef _ISOC99_SOURCE\n");
+#endif
+ printf("extern _ast_intmax_t strtoll(const char*, char**, int);\n");
+#if _npt_strtoll && !_map_libc && !_std_strtol
+ printf("#endif\n");
+#endif
+#endif
+#if _npt_strtoull || _map_libc || _std_strtol
+#if _npt_strtoull && !_map_libc && !_std_strtol
+ printf("#ifndef _ISOC99_SOURCE\n");
+#endif
+ printf("extern unsigned _ast_intmax_t strtoull(const char*, char**, int);\n");
+#if _npt_strtoull && !_map_libc && !_std_strtoul
+ printf("#endif\n");
+#endif
+#endif
+
+ /*
+ * finally some features/api mediation
+ */
+
+#if defined(_API_ast_MAP) && _map_libc
+ {
+ register const char* s;
+ register const char* t;
+
+ static const char map[] = _API_ast_MAP;
+
+ printf("\n");
+ t = map;
+ do
+ {
+ for (s = t; *t && *t != ' '; t++);
+ printf("#define %-.*s _ast_%-.*s\n", t - s, s, t - s, s);
+ } while (*t++);
+ }
+#endif
+ printf("\n");
+ printf("#undef extern\n");
+ return 0;
+}
diff --git a/src/lib/libast/features/mmap b/src/lib/libast/features/mmap
new file mode 100644
index 0000000..41ac44e
--- /dev/null
+++ b/src/lib/libast/features/mmap
@@ -0,0 +1,342 @@
+ref -D_def_map_ast=1
+
+sys mman
+
+tst lib_mmap note{ standard mmap interface that works }end execute{
+ #include <unistd.h>
+ #include <fcntl.h>
+ #include <sys/types.h>
+ #include <sys/mman.h>
+ #include <sys/stat.h>
+ #include <sys/times.h>
+
+ #define MAPSIZE (64*1024)
+ #define BUFSIZE (8*1024)
+ #define WRITE (64)
+
+ #define Failed(file) (remove(file),1)
+
+ int
+ #if _STD_
+ main(int argc, char** argv)
+ #else
+ main(argc,argv)
+ int argc;
+ char** argv;
+ #endif
+ {
+ caddr_t mm;
+ char *t, *u, *f;
+ int i, fd, okfixed;
+ char file[1024], buf[MAPSIZE];
+ struct tms stm, etm;
+ clock_t rdtm, mmtm;
+
+ /* create data file in a local fs if possible */
+ t = file;
+ if (access(f = "/tmp", 0) == 0 ||
+ access(f = "/usr/tmp", 0) == 0)
+ {
+ while (*t = *f++)
+ t++;
+ *t++ = '/';
+ }
+ u = t;
+ f = argv[0];
+ while (*t = *f++)
+ if (*t == '/')
+ t = u;
+ else if (*t != '.')
+ t++;
+ *t++ = '.'; *t++ = 'D'; *t = 0;
+ if ((fd = open(file, O_CREAT|O_TRUNC|O_WRONLY, 0666)) < 0)
+ return 1;
+
+ for (i = 0; i < sizeof(buf); ++i)
+ buf[i] = '0' + (i%10);
+ for (i = 0; i < WRITE; ++i)
+ if (write(fd,buf,sizeof(buf)) != sizeof(buf))
+ return Failed(file);
+ close(fd);
+
+ /* see if can overwrite fixed map */
+ #ifndef MAP_VARIABLE
+ #define MAP_VARIABLE 0
+ #endif
+ if ((fd = open(file, O_RDWR)) < 0)
+ return Failed(file);
+
+ mm = mmap((caddr_t)0, sizeof(buf), (PROT_READ|PROT_WRITE),
+ (MAP_PRIVATE|MAP_VARIABLE), fd, 0);
+ if(mm == (caddr_t)0 || mm == (caddr_t)(-1))
+ return Failed(file);
+ mm = mmap(mm, sizeof(buf), (PROT_READ|PROT_WRITE),
+ (MAP_PRIVATE|MAP_FIXED), fd, 0);
+ okfixed = (mm == (caddr_t)0 || mm == (caddr_t)(-1)) ? 0 : 1;
+ munmap(mm, sizeof(buf));
+ close(fd);
+
+ /* read time */
+ if((fd = open(file, O_RDWR)) < 0)
+ return Failed(file);
+ times(&stm);
+ for (i = 0; i < WRITE; ++i)
+ if (read(fd,buf,BUFSIZE) != BUFSIZE)
+ return Failed(file);
+ times(&etm);
+ close(fd);
+ rdtm = (etm.tms_utime-stm.tms_utime) + (etm.tms_stime-stm.tms_stime);
+
+ /* mmap time */
+ if ((fd = open(file, O_RDWR)) < 0)
+ return Failed(file);
+ times(&stm);
+ for(i = 0, mm = (caddr_t)0; i < WRITE; ++i)
+ { if(okfixed)
+ { mm = (caddr_t)mmap(mm, MAPSIZE,
+ (PROT_READ|PROT_WRITE),
+ (MAP_PRIVATE | (mm ? MAP_FIXED : MAP_VARIABLE)),
+ fd, i*MAPSIZE );
+ }
+ else
+ { if(mm)
+ munmap(mm, MAPSIZE);
+ mm = (caddr_t)mmap((caddr_t)0, MAPSIZE,
+ (PROT_READ|PROT_WRITE),
+ (MAP_PRIVATE|MAP_VARIABLE),
+ fd, i*MAPSIZE );
+ }
+ if(mm == (caddr_t)(-1) || mm == (caddr_t)0)
+ return Failed(file);
+ }
+ times(&etm);
+ close(fd);
+ remove(file);
+ mmtm = (etm.tms_utime-stm.tms_utime) + (etm.tms_stime-stm.tms_stime);
+
+ return rdtm+60 < mmtm ? 1 : 0;
+ }
+}end
+
+tst lib_mmap64 -D_LARGEFILE64_SOURCE note{ mmap64 interface and implementation work }end execute{
+ #if !_lib_mmap
+ (
+ #endif
+
+ #include <unistd.h>
+ #include <fcntl.h>
+ #include <sys/types.h>
+ #include <sys/mman.h>
+ #include <sys/stat.h>
+
+ int
+ main()
+ {
+ off64_t off;
+ int fd;
+ int n;
+ char* s;
+ struct stat64 st;
+ char file[32] = {'/','t','m','p','/','m','m','X','X','X','X','X','X'};
+
+ /* hey, stubs are supposed to fail! */
+ if (stat64(".", &st) || !st.st_mode || !st.st_mtime)
+ return 1;
+ if (!mktemp(file) || (fd = open64(file, O_CREAT|O_WRONLY, 0600)) < 0)
+ {
+ remove(file);
+ return 1;
+ }
+ off = (1<<8);
+ off *= off;
+ if (lseek64(fd, off, SEEK_SET) != off)
+ {
+ remove(file);
+ return 1;
+ }
+ n = strlen(file) + 1;
+ if (write(fd, file, n) != n)
+ {
+ remove(file);
+ return 1;
+ }
+ if (close(fd) < 0 || (fd = open64(file, O_RDWR)) < 0)
+ {
+ remove(file);
+ return 1;
+ }
+ if (!(s = mmap64((caddr_t)0, (size_t)n, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, off)))
+ {
+ remove(file);
+ return 1;
+ }
+ if (strcmp(s, file))
+ {
+ remove(file);
+ return 1;
+ }
+ close(fd);
+ remove(file);
+ return 0;
+ }
+}end
+
+tst mmap_anon note{ use mmap MAP_ANON to get raw memory }end execute{
+ #if !_lib_mmap
+ (
+ #endif
+ #include <unistd.h>
+ #include <fcntl.h>
+ #include <sys/types.h>
+ #include <sys/mman.h>
+ #if defined(MAP_ANONYMOUS) && !defined(MAP_ANON)
+ #define MAP_ANON MAP_ANONYMOUS
+ #endif
+ int
+ main()
+ { void *addr;
+ addr = mmap(0,1024*1024,PROT_READ|PROT_WRITE,MAP_ANON|MAP_PRIVATE,-1,0);
+ return (addr && addr != (void*)(-1)) ? 0 : 1;
+ }
+}end
+
+tst mmap_devzero note{ use mmap on /dev/zero to get raw memory }end execute{
+ #if !_lib_mmap
+ (
+ #endif
+ #include <unistd.h>
+ #include <fcntl.h>
+ #include <sys/types.h>
+ #include <sys/mman.h>
+ int
+ main()
+ { int fd;
+ void *addr;
+ if((fd = open("/dev/zero", O_RDWR)) < 0)
+ return 1;
+ addr = mmap(0,1024*1024,PROT_READ|PROT_WRITE,MAP_PRIVATE,fd,0);
+ return (addr && addr != (void*)(-1)) ? 0 : 1;
+ }
+}end
+
+tst note{ mmap is worth using }end output{
+ #if !_lib_mmap
+ (
+ #endif
+ #include <unistd.h>
+ #include <fcntl.h>
+ #include <sys/types.h>
+ #include <sys/mman.h>
+ #include <sys/stat.h>
+ #include <sys/times.h>
+
+ #define MAPSIZE (64*1024)
+ #define BUFSIZE (MAPSIZE/8)
+ #define WRITE (64)
+ #define RUN (64)
+
+ #define Failed(file) (remove(file),1)
+
+ int
+ #if _STD_
+ main(int argc, char** argv)
+ #else
+ main(argc,argv)
+ int argc;
+ char** argv;
+ #endif
+ {
+ caddr_t mm;
+ char *t, *f;
+ int i, fd, k, run;
+ char file[1024], buf[MAPSIZE];
+ struct tms stm, etm;
+ clock_t rdtm, mmtm;
+
+ /* create data file */
+ f = argv[0]; t = file;
+ while (*t = *f++)
+ t++;
+ *t++ = '.'; *t++ = 'D'; *t = 0;
+ if ((fd = open(file, O_CREAT|O_TRUNC|O_WRONLY, 0666)) < 0)
+ return 1;
+
+ for (i = 0; i < sizeof(buf); ++i)
+ buf[i] = '0' + (i%10);
+ for (i = 0; i < WRITE; ++i)
+ if (write(fd,buf,sizeof(buf)) != sizeof(buf))
+ return Failed(file);
+ close(fd);
+
+ /* read time */
+ times(&stm);
+ for(run = 0; run < RUN; ++run)
+ { if((fd = open(file, O_RDWR)) < 0)
+ return Failed(file);
+ for (i = 0; i < WRITE; ++i)
+ { for(k = 0; k < MAPSIZE; k += BUFSIZE)
+ if (read(fd,buf,BUFSIZE) != BUFSIZE)
+ return Failed(file);
+ }
+ close(fd);
+ }
+ times(&etm);
+ rdtm = (etm.tms_utime-stm.tms_utime) + (etm.tms_stime-stm.tms_stime);
+
+ /* mmap time */
+ times(&stm);
+ for(run = 0; run < RUN; ++run)
+ { if ((fd = open(file, O_RDWR)) < 0)
+ return Failed(file);
+ for(i = 0, mm = (caddr_t)0; i < WRITE; ++i)
+ { if(mm)
+ munmap(mm, MAPSIZE);
+ mm = (caddr_t)mmap((caddr_t)0, MAPSIZE,
+ (PROT_READ|PROT_WRITE),
+ MAP_PRIVATE, fd, i*MAPSIZE );
+ if(mm == (caddr_t)(-1) || mm == (caddr_t)0)
+ return Failed(file);
+
+ /* the memcpy is < BUFSIZE to simulate the
+ fact that functions like sfreserve/sfgetr do
+ not do buffer copying.
+ */
+ t = (char*)mm;
+ for(k = 0; k < MAPSIZE; k += BUFSIZE, t += BUFSIZE)
+ memcpy(buf,t,(3*BUFSIZE)/4);
+ }
+ close(fd);
+ }
+ times(&etm);
+ mmtm = (etm.tms_utime-stm.tms_utime) + (etm.tms_stime-stm.tms_stime);
+
+ remove(file);
+
+ if(4*mmtm <= 3*rdtm)
+ printf("#define _mmap_worthy 2 /* mmap is great */\n");
+ else if(4*mmtm <= 5*rdtm)
+ printf("#define _mmap_worthy 1 /* mmap is good */\n");
+
+ else
+ return 1;
+ return 0;
+ }
+}end
+
+cat{
+
+ /* some systems get it wrong but escape concise detection */
+ #ifndef _NO_MMAP
+ #if __CYGWIN__
+ #define _NO_MMAP 1
+ #endif
+ #endif
+
+ #if _NO_MMAP
+ #undef _lib_mmap
+ #undef _lib_mmap64
+ #undef _mmap_anon
+ #undef _mmap_devzero
+ #undef _mmap_worthy
+ #endif
+}end
diff --git a/src/lib/libast/features/mode.c b/src/lib/libast/features/mode.c
new file mode 100644
index 0000000..68b5e68
--- /dev/null
+++ b/src/lib/libast/features/mode.c
@@ -0,0 +1,218 @@
+/***********************************************************************
+* *
+* This software is part of the ast package *
+* Copyright (c) 1985-2011 AT&T Intellectual Property *
+* and is licensed under the *
+* Eclipse Public License, Version 1.0 *
+* by AT&T Intellectual Property *
+* *
+* A copy of the License is available at *
+* http://www.eclipse.org/org/documents/epl-v10.html *
+* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
+* *
+* Information and Software Systems Research *
+* AT&T Research *
+* Florham Park NJ *
+* *
+* Glenn Fowler <gsf@research.att.com> *
+* David Korn <dgk@research.att.com> *
+* Phong Vo <kpv@research.att.com> *
+* *
+***********************************************************************/
+#pragma prototyped
+/*
+ * Glenn Fowler
+ * AT&T Research
+ *
+ * generate mode features
+ */
+
+#include "limits.h"
+
+#include "FEATURE/param"
+
+#include <modecanon.h>
+
+int
+main()
+{
+ int n;
+ int idperm;
+ int idtype;
+
+ idperm = idtype = 1;
+#ifndef S_ITYPE
+#ifdef S_IFMT
+ printf("#define S_ITYPE(m) ((m)&S_IFMT)\n");
+#else
+ printf("#define S_ITYPE(m) ((m)&~S_IPERM)\n");
+#endif
+#endif
+#ifdef S_ISBLK
+ if (!S_ISBLK(X_IFBLK)) idtype = 0;
+#else
+#ifdef S_IFBLK
+ printf("#define S_ISBLK(m) (S_ITYPE(m)==S_IFBLK)\n");
+#else
+ printf("#define S_ISBLK(m) 0\n");
+#endif
+#endif
+#ifdef S_ISCHR
+ if (!S_ISCHR(X_IFCHR)) idtype = 0;
+#else
+#ifdef S_IFCHR
+ printf("#define S_ISCHR(m) (S_ITYPE(m)==S_IFCHR)\n");
+#else
+ printf("#define S_ISCHR(m) 0\n");
+#endif
+#endif
+#ifdef S_ISCTG
+ if (!S_ISCTG(X_IFCTG)) idtype = 0;
+#else
+#ifdef S_IFCTG
+ printf("#define S_ISCTG(m) (S_ITYPE(m)==S_IFCTG)\n");
+#endif
+#endif
+#ifdef S_ISDIR
+ if (!S_ISDIR(X_IFDIR)) idtype = 0;
+#else
+#ifdef S_IFDIR
+ printf("#define S_ISDIR(m) (S_ITYPE(m)==S_IFDIR)\n");
+#else
+ printf("#define S_ISDIR(m) 0\n");
+#endif
+#endif
+#ifdef S_ISFIFO
+ if (!S_ISFIFO(X_IFIFO)) idtype = 0;
+#else
+#ifdef S_IFIFO
+ printf("#define S_ISFIFO(m) (S_ITYPE(m)==S_IFIFO)\n");
+#else
+ printf("#define S_ISFIFO(m) 0\n");
+#endif
+#endif
+#ifdef S_ISLNK
+ if (!S_ISLNK(X_IFLNK)) idtype = 0;
+#else
+#ifdef S_IFLNK
+ printf("#define S_ISLNK(m) (S_ITYPE(m)==S_IFLNK)\n");
+#else
+ printf("#define S_ISLNK(m) 0\n");
+#endif
+#endif
+#ifdef S_ISREG
+ if (!S_ISREG(X_IFREG)) idtype = 0;
+#else
+#ifdef S_IFREG
+ printf("#define S_ISREG(m) (S_ITYPE(m)==S_IFREG)\n");
+#else
+ printf("#define S_ISREG(m) 0\n");
+#endif
+#endif
+#ifdef S_ISSOCK
+ if (!S_ISSOCK(X_IFSOCK)) idtype = 0;
+#else
+#ifdef S_IFSOCK
+ printf("#define S_ISSOCK(m) (S_ITYPE(m)==S_IFSOCK)\n");
+#endif
+#endif
+ printf("\n");
+#ifndef S_IPERM
+ printf("#define S_IPERM (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO)\n");
+#endif
+#ifndef S_ISUID
+ printf("#define S_ISUID 0%04o\n", X_ISUID);
+#else
+ if (S_ISUID != X_ISUID) idperm = 0;
+#endif
+#ifndef S_ISGID
+ printf("#define S_ISGID 0%04o\n", X_ISGID);
+#else
+ if (S_ISGID != X_ISGID) idperm = 0;
+#endif
+#ifndef S_ISVTX
+ printf("#define S_ISVTX 0%04o\n", X_ISVTX);
+#else
+ if (S_ISVTX != X_ISVTX) idperm = 0;
+#endif
+#ifndef S_IRUSR
+ printf("#define S_IRUSR 0%04o\n", X_IRUSR);
+#else
+ if (S_IRUSR != X_IRUSR) idperm = 0;
+#endif
+#ifndef S_IWUSR
+ printf("#define S_IWUSR 0%04o\n", X_IWUSR);
+#else
+ if (S_IWUSR != X_IWUSR) idperm = 0;
+#endif
+#ifndef S_IXUSR
+ printf("#define S_IXUSR 0%04o\n", X_IXUSR);
+#else
+ if (S_IXUSR != X_IXUSR) idperm = 0;
+#endif
+#ifndef S_IRGRP
+ printf("#define S_IRGRP 0%04o\n", X_IRGRP);
+#else
+ if (S_IRGRP != X_IRGRP) idperm = 0;
+#endif
+#ifndef S_IWGRP
+ printf("#define S_IWGRP 0%04o\n", X_IWGRP);
+#else
+ if (S_IWGRP != X_IWGRP) idperm = 0;
+#endif
+#ifndef S_IXGRP
+ printf("#define S_IXGRP 0%04o\n", X_IXGRP);
+#else
+ if (S_IXGRP != X_IXGRP) idperm = 0;
+#endif
+#ifndef S_IROTH
+ printf("#define S_IROTH 0%04o\n", X_IROTH);
+#else
+ if (S_IROTH != X_IROTH) idperm = 0;
+#endif
+#ifndef S_IWOTH
+ printf("#define S_IWOTH 0%04o\n", X_IWOTH);
+#else
+ if (S_IWOTH != X_IWOTH) idperm = 0;
+#endif
+#ifndef S_IXOTH
+ printf("#define S_IXOTH 0%04o\n", X_IXOTH);
+#else
+ if (S_IXOTH != X_IXOTH) idperm = 0;
+#endif
+#ifndef S_IRWXU
+ printf("#define S_IRWXU (S_IRUSR|S_IWUSR|S_IXUSR)\n");
+#endif
+#ifndef S_IRWXG
+ printf("#define S_IRWXG (S_IRGRP|S_IWGRP|S_IXGRP)\n");
+#endif
+#ifndef S_IRWXO
+ printf("#define S_IRWXO (S_IROTH|S_IWOTH|S_IXOTH)\n");
+#endif
+ printf("\n");
+ if (idperm) printf("#define _S_IDPERM 1\n");
+ if (idtype) printf("#define _S_IDTYPE 1\n");
+ printf("\n");
+#ifdef BUFFERSIZE
+ n = BUFFERSIZE;
+#else
+#ifdef MAXBSIZE
+ n = MAXBSIZE;
+#else
+#ifdef SBUFSIZE
+ n = SBUFSIZE;
+#else
+#ifdef BUFSIZ
+ n = BUFSIZ;
+#else
+ if (sizeof(char*) > 4) n = 8192;
+ else if (sizeof(char*) < 4) n = 512;
+ else n = 4096;
+#endif
+#endif
+#endif
+#endif
+ printf("#define BUFFERSIZE %u\n", n);
+ printf("\n");
+ return 0;
+}
diff --git a/src/lib/libast/features/ndbm b/src/lib/libast/features/ndbm
new file mode 100644
index 0000000..d12d15c
--- /dev/null
+++ b/src/lib/libast/features/ndbm
@@ -0,0 +1,29 @@
+if tst -ldb note{ sleepycat ndbm compatibility }end link{
+ #define DB_DBM_HSEARCH 1
+ #include <db.h>
+ int main()
+ {
+ DBM* dbm = 0;
+ dbm_close(dbm);
+ return 0;
+ }
+ }end {
+ #ifndef DB_DBM_HSEARCH
+ #define DB_DBM_HSEARCH 1
+ #include <db.h>
+ #endif
+ #define _use_ndbm 1
+ }
+elif hdr gdbm-ndbm {
+ #include <gdbm-ndbm.h>
+ #define _use_ndbm 1
+}
+elif hdr gdbm/ndbm {
+ #include <gdbm/ndbm.h>
+ #define _use_ndbm 1
+}
+elif hdr ndbm {
+ #include <ndbm.h>
+ #define _use_ndbm 1
+}
+endif
diff --git a/src/lib/libast/features/nl_types b/src/lib/libast/features/nl_types
new file mode 100644
index 0000000..02cae3e
--- /dev/null
+++ b/src/lib/libast/features/nl_types
@@ -0,0 +1,64 @@
+set prototyped
+lib catopen,nl_langinfo
+hdr nl_types,langinfo
+nxt nl_types
+
+tst output{
+ #if !_lib_catopen
+ #undef _hdr_nl_types
+ #endif
+ #include "FEATURE/limits"
+ #if _hdr_nl_types
+ #include <nl_types.h>
+ #endif
+
+ int
+ main()
+ {
+ printf("#include <limits.h>\n");
+ #if _hdr_nl_types && defined(_nxt_nl_types_str)
+ printf("#include <%s> /* the native nl_types.h */\n", _nxt_nl_types_str);
+ #endif
+ printf("\n");
+ #ifndef NL_SETMAX
+ printf("#undef NL_SETMAX\n");
+ printf("#define NL_SETMAX 1023\n");
+ #endif
+ #ifndef NL_MSGMAX
+ printf("#undef NL_MSGMAX\n");
+ printf("#define NL_MSGMAX 32767\n");
+ #endif
+ #ifndef NL_SETD
+ printf("#undef NL_SETD\n");
+ printf("#define NL_SETD 1\n");
+ #endif
+ #ifndef NL_CAT_LOCALE
+ printf("#undef NL_CAT_LOCALE\n");
+ printf("#define NL_CAT_LOCALE 1\n");
+ #endif
+ #if _lib_catopen
+ printf("#undef nl_catd\n");
+ printf("#define nl_catd _ast_nl_catd\n");
+ printf("#undef catopen\n");
+ printf("#define catopen _ast_catopen\n");
+ printf("#undef catgets\n");
+ printf("#define catgets _ast_catgets\n");
+ printf("#undef catclose\n");
+ printf("#define catclose _ast_catclose\n");
+ #endif
+ printf("\n");
+ printf("typedef void* nl_catd;\n");
+ printf("\n");
+ printf("#if _BLD_ast && defined(__EXPORT__)\n");
+ printf("#define extern __EXPORT__\n");
+ printf("#endif\n");
+ printf("\n");
+ printf("extern nl_catd catopen(const char*, int);\n");
+ printf("extern char* catgets(nl_catd, int, int, const char*);\n");
+ printf("extern int catclose(nl_catd);\n");
+ printf("\n");
+ printf("#undef extern\n");
+ printf("\n");
+ return 0;
+ }
+}end
diff --git a/src/lib/libast/features/omitted b/src/lib/libast/features/omitted
new file mode 100644
index 0000000..1e4eca4
--- /dev/null
+++ b/src/lib/libast/features/omitted
@@ -0,0 +1,110 @@
+tst note{ check for win32 .exe botches }end output{
+ #include <unistd.h>
+ #include <fcntl.h>
+ #include <sys/types.h>
+ #include <sys/stat.h>
+ static int
+ cp(const char* from, const char* to)
+ {
+ ssize_t n;
+ int fd;
+ int td;
+ struct stat fs;
+ char buf[1024];
+
+ if ((fd = _open(from, O_RDONLY|O_BINARY)) < 0)
+ return -1;
+ if (_fstat(fd, &fs) || (td = _open(to, O_CREAT|O_WRONLY|O_TRUNC|O_BINARY, fs.st_mode & 0777)) < 0)
+ {
+ _close(fd);
+ return -1;
+ }
+ while ((n = _read(fd, buf, sizeof(buf))) > 0 && _write(td, buf, n) == n);
+ _close(fd);
+ _close(td);
+ return n ? -1 : 0;
+ }
+ int
+ main(int argc, char** argv)
+ {
+ int fd;
+ int fix;
+ struct stat st;
+ char buf[256];
+
+ snprintf(buf, sizeof(buf), "rm -rf /tmp/iff-%d", getpid());
+ if (_mkdir(buf+7, 0755))
+ return 1;
+ if (_chdir(buf+7))
+ return 1;
+ if (cp("/bin/cat.exe", "foo.exe"))
+ return 1;
+ fix = 0;
+ if (_access("foo", X_OK))
+ fix++,printf("#define _win32_botch_access 1\n");
+ if (_chmod("foo", 0755))
+ fix++,printf("#define _win32_botch_chmod 1\n");
+ if (cp("/bin/cat", "bam") || _access("bam.exe", X_OK))
+ fix++,printf("#define _win32_botch_copy 1\n");
+ if (_getpagesize() != 64 * 1024)
+ fix++,printf("#define _win32_botch_getpagesize 1\n");
+ #if !__EMX__
+ if (_link("foo", "bar") || _access("bar.exe", X_OK))
+ fix++,printf("#define _win32_botch_link 1\n");
+ else
+ #endif
+ cp("foo.exe", "bar.exe");
+ if ((fd = _open("foo", O_RDONLY)) < 0)
+ fix++,printf("#define _win32_botch_open 1\n");
+ else
+ _close(fd);
+ if (_pathconf("huh", _PC_NAME_MAX) >= 0)
+ fix++,printf("#define _win32_botch_pathconf 1\n");
+ if (_rename("foo", "aha") || _access("aha.exe", X_OK))
+ fix++,printf("#define _win32_botch_rename 1\n");
+ else
+ _rename("foo.exe", "aha.exe");
+ if (_stat("bar", &st))
+ {
+ fix++,printf("#define _win32_botch_stat 1\n");
+ if (sizeof(st.st_ino) == 8)
+ printf("#define _stat _stat64\n");
+ }
+ if (_truncate("aha", 0))
+ fix++,printf("#define _win32_botch_truncate 1\n");
+ if (_unlink("bar"))
+ fix++,printf("#define _win32_botch_unlink 1\n");
+ if (_utime("aha", 0))
+ fix++,printf("#define _win32_botch_utime 1\n");
+ if (fix)
+ {
+ printf("#define _win32_botch_execve 1\n");
+ printf("#define _win32_botch 1\n");
+ }
+ _chdir("/tmp");
+ system(buf);
+ return 0;
+ }
+}end
+
+tst win32_botch_alarm note{ win32 alarm(2) return botched }end noexecute{
+ #include <signal.h>
+ #include <unistd.h>
+ #include <time.h>
+
+ static int sigalrm = 0;
+
+ static void
+ handler(int sig)
+ {
+ sigalrm++;
+ }
+ int
+ main(int argc, char** argv)
+ {
+ signal(SIGALRM, handler);
+ alarm(2);
+ pause();
+ return sigalrm != 1 || alarm(0) != 0;
+ }
+}end
diff --git a/src/lib/libast/features/options b/src/lib/libast/features/options
new file mode 100644
index 0000000..500bd63
--- /dev/null
+++ b/src/lib/libast/features/options
@@ -0,0 +1 @@
+opt map-libc
diff --git a/src/lib/libast/features/param.sh b/src/lib/libast/features/param.sh
new file mode 100644
index 0000000..7d4a856
--- /dev/null
+++ b/src/lib/libast/features/param.sh
@@ -0,0 +1,47 @@
+########################################################################
+# #
+# This software is part of the ast package #
+# Copyright (c) 1985-2011 AT&T Intellectual Property #
+# and is licensed under the #
+# Eclipse Public License, Version 1.0 #
+# by AT&T Intellectual Property #
+# #
+# A copy of the License is available at #
+# http://www.eclipse.org/org/documents/epl-v10.html #
+# (with md5 checksum b35adb5213ca9657e911e9befb180842) #
+# #
+# Information and Software Systems Research #
+# AT&T Research #
+# Florham Park NJ #
+# #
+# Glenn Fowler <gsf@research.att.com> #
+# David Korn <dgk@research.att.com> #
+# Phong Vo <kpv@research.att.com> #
+# #
+########################################################################
+: generate "<sys/param.h> + <sys/types.h> + <sys/stat.h>" include sequence
+case $# in
+0) ;;
+*) eval $1
+ shift
+ ;;
+esac
+for i in "#include <sys/param.h>" "#include <sys/param.h>
+#ifndef S_IFDIR
+#include <sys/stat.h>
+#endif" "#include <sys/param.h>
+#ifndef S_IFDIR
+#include <sys/types.h>
+#include <sys/stat.h>
+#endif" "#ifndef S_IFDIR
+#include <sys/types.h>
+#include <sys/stat.h>
+#endif"
+do echo "$i
+struct stat V_stat_V;
+F_stat_F() { V_stat_V.st_mode = 0; }" > $tmp.c
+ if $cc -c $tmp.c >/dev/null
+ then echo "$i"
+ break
+ fi
+done
diff --git a/src/lib/libast/features/preroot.sh b/src/lib/libast/features/preroot.sh
new file mode 100644
index 0000000..40ac2fc
--- /dev/null
+++ b/src/lib/libast/features/preroot.sh
@@ -0,0 +1,46 @@
+########################################################################
+# #
+# This software is part of the ast package #
+# Copyright (c) 1985-2011 AT&T Intellectual Property #
+# and is licensed under the #
+# Eclipse Public License, Version 1.0 #
+# by AT&T Intellectual Property #
+# #
+# A copy of the License is available at #
+# http://www.eclipse.org/org/documents/epl-v10.html #
+# (with md5 checksum b35adb5213ca9657e911e9befb180842) #
+# #
+# Information and Software Systems Research #
+# AT&T Research #
+# Florham Park NJ #
+# #
+# Glenn Fowler <gsf@research.att.com> #
+# David Korn <dgk@research.att.com> #
+# Phong Vo <kpv@research.att.com> #
+# #
+########################################################################
+: generate preroot features
+case $# in
+0) ;;
+*) eval $1
+ shift
+ ;;
+esac
+if /etc/preroot / /bin/echo >/dev/null
+then cat <<!
+#pragma prototyped
+
+#define FS_PREROOT 1 /* preroot enabled */
+#define PR_BASE "CCS" /* preroot base env var */
+#define PR_COMMAND "/etc/preroot" /* the preroot command */
+#define PR_REAL "/dev/.." /* real root pathname */
+#define PR_SILENT "CCSQUIET" /* no command trace */
+
+extern char* getpreroot(char*, const char*);
+extern int ispreroot(const char*);
+extern int realopen(const char*, int, int);
+extern void setpreroot(char**, const char*);
+
+!
+else echo "/* preroot not enabled */"
+fi
diff --git a/src/lib/libast/features/prog b/src/lib/libast/features/prog
new file mode 100644
index 0000000..365ce88
--- /dev/null
+++ b/src/lib/libast/features/prog
@@ -0,0 +1,12 @@
+lib getexecname,_NSGetExecutablePath
+
+tst run{
+ for p in /proc/self/exe /proc/self/path/a.out
+ do if test -e $p
+ then echo "#define _PROC_PROG \"$p\""
+ break
+ fi
+ done
+}end
+
+_hdr_macho_o_dyld = hdr mach-o/dyld
diff --git a/src/lib/libast/features/sfinit.c b/src/lib/libast/features/sfinit.c
new file mode 100644
index 0000000..ccd0527
--- /dev/null
+++ b/src/lib/libast/features/sfinit.c
@@ -0,0 +1,94 @@
+/***********************************************************************
+* *
+* This software is part of the ast package *
+* Copyright (c) 1985-2011 AT&T Intellectual Property *
+* and is licensed under the *
+* Eclipse Public License, Version 1.0 *
+* by AT&T Intellectual Property *
+* *
+* A copy of the License is available at *
+* http://www.eclipse.org/org/documents/epl-v10.html *
+* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
+* *
+* Information and Software Systems Research *
+* AT&T Research *
+* Florham Park NJ *
+* *
+* Glenn Fowler <gsf@research.att.com> *
+* David Korn <dgk@research.att.com> *
+* Phong Vo <kpv@research.att.com> *
+* *
+***********************************************************************/
+/*
+ * generate sfio _Sftable static initializers
+ */
+
+#include "FEATURE/common"
+#include "FEATURE/float"
+
+int
+main()
+{
+ register int i;
+#if _ast_fltmax_double
+ char* fs = "";
+ char* ds = "";
+ char* ls = "";
+#else
+ char* fs = "F";
+ char* ds = "";
+ char* ls = "L";
+#endif
+
+ printf("\nstatic const float sf_flt_pow10[] =\n{\n");
+ for (i = 0; i <= FLT_MAX_10_EXP; i++)
+ printf("\t1E%d%s,\n", i, fs);
+ printf("};\n");
+ printf("\nstatic const double sf_dbl_pow10[] =\n{\n");
+ for (i = 0; i <= DBL_MAX_10_EXP; i++)
+ printf("\t1E%d%s,\n", i, ds);
+ printf("};\n");
+#if !_ast_fltmax_double
+ printf("\nstatic const _ast_fltmax_t sf_ldbl_pow10[] =\n{\n");
+ for (i = 0; i <= LDBL_MAX_10_EXP; i++)
+ printf("\t1E%d%s,\n", i, ls);
+ printf("};\n");
+#endif
+ printf("\nSftab_t _Sftable =\n{\n");
+ printf("\t{ 1E1%s, 1E2%s, 1E4%s, 1E8%s, 1E16%s, 1E32%s },\n", ls, ls, ls, ls, ls, ls);
+ printf("\t{ 1E-1%s, 1E-2%s, 1E-4%s, 1E-8%s, 1E-16%s, 1E-32%s },\n", ls, ls, ls, ls, ls, ls);
+ printf("\t{ '0','0', '0','1', '0','2', '0','3', '0','4',\n");
+ printf("\t '0','5', '0','6', '0','7', '0','8', '0','9',\n");
+ printf("\t '1','0', '1','1', '1','2', '1','3', '1','4',\n");
+ printf("\t '1','5', '1','6', '1','7', '1','8', '1','9',\n");
+ printf("\t '2','0', '2','1', '2','2', '2','3', '2','4',\n");
+ printf("\t '2','5', '2','6', '2','7', '2','8', '2','9',\n");
+ printf("\t '3','0', '3','1', '3','2', '3','3', '3','4',\n");
+ printf("\t '3','5', '3','6', '3','7', '3','8', '3','9',\n");
+ printf("\t '4','0', '4','1', '4','2', '4','3', '4','4',\n");
+ printf("\t '4','5', '4','6', '4','7', '4','8', '4','9',\n");
+ printf("\t '5','0', '5','1', '5','2', '5','3', '5','4',\n");
+ printf("\t '5','5', '5','6', '5','7', '5','8', '5','9',\n");
+ printf("\t '6','0', '6','1', '6','2', '6','3', '6','4',\n");
+ printf("\t '6','5', '6','6', '6','7', '6','8', '6','9',\n");
+ printf("\t '7','0', '7','1', '7','2', '7','3', '7','4',\n");
+ printf("\t '7','5', '7','6', '7','7', '7','8', '7','9',\n");
+ printf("\t '8','0', '8','1', '8','2', '8','3', '8','4',\n");
+ printf("\t '8','5', '8','6', '8','7', '8','8', '8','9',\n");
+ printf("\t '9','0', '9','1', '9','2', '9','3', '9','4',\n");
+ printf("\t '9','5', '9','6', '9','7', '9','8', '9','9',\n");
+ printf("\t},\n");
+ printf("\t\"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@_\",\n");
+ printf("\tsfcvinit, 0,\n");
+ printf("\tsffmtpos,\n");
+ printf("\tsffmtint,\n");
+ printf("\t(float*)&sf_flt_pow10[0],\n");
+ printf("\t(double*)&sf_dbl_pow10[0],\n");
+#if _ast_fltmax_double
+ printf("\t0,\n");
+#else
+ printf("\t(_ast_fltmax_t*)&sf_ldbl_pow10[0],\n");
+#endif
+ printf("};\n");
+ return 0;
+}
diff --git a/src/lib/libast/features/sfio b/src/lib/libast/features/sfio
new file mode 100644
index 0000000..901935a
--- /dev/null
+++ b/src/lib/libast/features/sfio
@@ -0,0 +1,170 @@
+ref -D_def_map_ast=1
+hdr float,floatingpoint,math,values
+sys filio,ioctl
+lib qfrexp,qldexp
+key signed
+
+tst - note{ number of bits in pointer }end output{
+ #include <stdio.h>
+ int
+ main()
+ {
+ printf("#define _ptr_bits %d\n", sizeof(char*) * 8);
+ return 0;
+ }
+}end
+
+tst tmp_rmfail note{ open files cannot be removed }end execute{
+ #include <string.h>
+ #include <time.h>
+ int
+ main()
+ {
+ #if !_UWIN
+ int n;
+ char* s;
+ FILE* fr;
+ FILE* fw;
+ char file[16];
+ static char data[] = "0123456789";
+ s = file;
+ *s++ = '1';
+ *s++ = 'F';
+ *s++ = 'F';
+ *s++ = '3';
+ n = (int)time(0);
+ *s++ = (n & 0xF) + 'A';
+ *s++ = ((n >> 4) & 0xF) + 'A';
+ *s++ = ((n >> 8) & 0xF) + 'A';
+ *s++ = ((n >> 12) & 0xF) + 'A';
+ *s++ = '.';
+ *s++ = 'T';
+ *s++ = 'M';
+ *s++ = 'P';
+ *s = 0;
+ remove(file);
+ if (!(fw = fopen(file, "w")))
+ return 0;
+ if (!(fr = fopen(file, "r")))
+ {
+ fclose(fw);
+ remove(file);
+ return 0;
+ }
+ if (remove(file) < 0)
+ {
+ fclose(fr);
+ fclose(fw);
+ remove(file);
+ return 0;
+ }
+ if (fwrite(data, sizeof(data), 1, fw) != 1)
+ return 0;
+ fclose(fw);
+ if (fread(file, sizeof(data), 1, fr) != 1)
+ return 0;
+ fclose(fr);
+ if (strcmp(file, data) != 0)
+ return 0;
+ #endif
+ return 1;
+ }
+}end
+
+more void_int note{ voidptr is larger than int }end execute{
+ int
+ main()
+ {
+ return sizeof(char*) > sizeof(int) ? 0 : 1;
+ }
+}end
+
+more long_int note{ long is larger than int }end execute{
+ int
+ main()
+ {
+ return sizeof(long) > sizeof(int) ? 0 : 1;
+ }
+}end
+
+tst vax_asm note{ register layout ok for vax string operations }end execute{
+ int
+ main()
+ {
+ #ifndef vax
+ return absurd = -1;
+ #else
+ register int r11, r10, r9, r8, r7, r6;
+ r11 = r10 = r9 = r8 = r7 = r6 = -1;
+ asm("clrw r11");
+ asm("clrw r10");
+ asm("clrw r9");
+ asm("clrw r8");
+ asm("clrw r7");
+ asm("clrw r6");
+ if(sizeof(int) != sizeof(char*) || r11 || r10 || r9 || r8 || r7 || r6 )
+ return -1;
+ return 0;
+ #endif
+ }
+}end
+
+tst lib_cvt note{ native floating point conversions ok }end link{
+ _BEGIN_EXTERNS_
+ extern char* ecvt _ARG_((double, int, int*, int*));
+ extern char* fcvt _ARG_((double, int, int*, int*));
+ extern double strtod _ARG_((const char*, char**));
+ _END_EXTERNS_
+ int
+ main()
+ {
+ ecvt(0.0, 0, 0, 0);
+ fcvt(0.0, 0, 0, 0);
+ strtod(0, 0);
+ return 0;
+ }
+}end
+
+tst xopen_stdio note{ Stdio fseek/fflush are X/Open-compliant }end execute{
+ #define Failed(file) (unlink(file),1)
+ int
+ main(argc, argv)
+ int argc;
+ char** argv;
+ { FILE *f1, *f2;
+ char file[1024], buf[1024], *f, *t;
+ int i, fd;
+
+ /* create file */
+ for(f = argv[0], t = file; (*t = *f++) != 0; )
+ t++;
+ *t++ = '.'; *t++ = 'D'; *t++ = 0;
+ if((fd = creat(file,0666)) < 0)
+ return 1;
+
+ for (i = 0; i < sizeof(buf); ++i)
+ buf[i] = '0' + (i%10);
+ for (i = 0; i < 16; ++i)
+ if (write(fd,buf,sizeof(buf)) != sizeof(buf))
+ return Failed(file);
+ close(fd);
+
+ if(!(f1 = fopen(file,"r+")) ||
+ (fd = dup(fileno(f1))) < 0 ||
+ !(f2 = fdopen(fd,"r+")) )
+ return Failed(file);
+
+ if(fread(buf, 1, 7, f2) != 7 || ftell(f2) != 7)
+ return Failed(file);
+
+ if(fseek(f1, 1010, 0) < 0 || ftell(f1) != 1010)
+ return Failed(file);
+
+ fflush(f2); /* this should set the seek location to 1010 */
+ if(ftell(f2) != 1010)
+ return Failed(file);
+
+ unlink(file);
+ return 0;
+ }
+}end
diff --git a/src/lib/libast/features/sig.sh b/src/lib/libast/features/sig.sh
new file mode 100644
index 0000000..706372b
--- /dev/null
+++ b/src/lib/libast/features/sig.sh
@@ -0,0 +1,132 @@
+########################################################################
+# #
+# This software is part of the ast package #
+# Copyright (c) 1985-2011 AT&T Intellectual Property #
+# and is licensed under the #
+# Eclipse Public License, Version 1.0 #
+# by AT&T Intellectual Property #
+# #
+# A copy of the License is available at #
+# http://www.eclipse.org/org/documents/epl-v10.html #
+# (with md5 checksum b35adb5213ca9657e911e9befb180842) #
+# #
+# Information and Software Systems Research #
+# AT&T Research #
+# Florham Park NJ #
+# #
+# Glenn Fowler <gsf@research.att.com> #
+# David Korn <dgk@research.att.com> #
+# Phong Vo <kpv@research.att.com> #
+# #
+########################################################################
+: generate sig features
+case $# in
+0) ;;
+*) eval $1
+ shift
+ ;;
+esac
+echo "#include <signal.h>
+int xxx;" > $tmp.c
+$cc -c $tmp.c >/dev/null 2>$tmp.e
+echo "#pragma prototyped
+#define sig_info _sig_info_
+
+#if defined(__STDPP__directive) && defined(__STDPP__hide)
+__STDPP__directive pragma pp:hide kill killpg
+#else
+#define kill ______kill
+#define killpg ______killpg
+#endif
+#include <signal.h>
+#if defined(__STDPP__directive) && defined(__STDPP__hide)
+__STDPP__directive pragma pp:nohide kill killpg
+#else
+#undef kill
+#undef killpg
+#endif
+#ifndef sigmask
+#define sigmask(s) (1<<((s)-1))
+#endif"
+echo "#include <signal.h>
+#ifdef TYPE
+#if defined(__STDC__) || defined(__cplusplus) || defined(c_plusplus)
+typedef TYPE (*Sig_handler_t)(ARG);
+#else
+typedef TYPE (*Sig_handler_t)();
+#endif
+#endif
+Sig_handler_t f()
+{
+ Sig_handler_t handler;
+ handler = signal(1, SIG_IGN);
+ return(handler);
+}" > $tmp.c
+if $cc -c $tmp.c >/dev/null
+then :
+else e=`wc -l $tmp.e`
+ i1= j1=
+ for i in void int
+ do for j in int,... ... int
+ do $cc -c -DTYPE=$i -DARG=$j $tmp.c >/dev/null 2>$tmp.e || continue
+ case `wc -l $tmp.e` in
+ $e) i1= j1=; break 2 ;;
+ esac
+ case $i1 in
+ "") i1=$i j1=$j ;;
+ esac
+ done
+ done
+ case $i1 in
+ ?*) i=$i1 j=$j1 ;;
+ esac
+ echo "typedef $i (*Sig_handler_t)($j);"
+fi
+echo '
+
+#define Handler_t Sig_handler_t
+
+#define SIG_REG_PENDING (-1)
+#define SIG_REG_POP 0
+#define SIG_REG_EXEC 00001
+#define SIG_REG_PROC 00002
+#define SIG_REG_TERM 00004
+#define SIG_REG_ALL 00777
+#define SIG_REG_SET 01000
+
+typedef struct
+{
+ char** name;
+ char** text;
+ int sigmax;
+} Sig_info_t;
+
+extern int kill(pid_t, int);
+extern int killpg(pid_t, int);
+
+#if _BLD_ast && defined(__EXPORT__)
+#define extern extern __EXPORT__
+#endif
+#if !_BLD_ast && defined(__IMPORT__)
+#define extern extern __IMPORT__
+#endif
+
+extern Sig_info_t sig_info;
+
+#undef extern
+
+#if _lib_sigflag && _npt_sigflag
+extern int sigflag(int, int, int);
+#endif
+
+#if _BLD_ast && defined(__EXPORT__)
+#define extern __EXPORT__
+#endif
+
+#if !_lib_sigflag
+extern int sigflag(int, int, int);
+#endif
+extern int sigcritical(int);
+extern int sigunblock(int);
+
+#undef extern'
diff --git a/src/lib/libast/features/siglist b/src/lib/libast/features/siglist
new file mode 100644
index 0000000..37d1bf0
--- /dev/null
+++ b/src/lib/libast/features/siglist
@@ -0,0 +1,14 @@
+lib strsignal string.h signal.h
+
+tst - run{
+ for sig in `/bin/kill -l 2>/dev/null`
+ do case $sig in
+ *[!A-Za-z0-9_]*|*MIN|*MAX)
+ ;;
+ *) echo "#if defined(SIG$sig) && !defined(HAD_SIG$sig)"
+ echo "0,\"$sig\",SIG$sig,"
+ echo "#endif"
+ ;;
+ esac
+ done
+}end
diff --git a/src/lib/libast/features/signal.c b/src/lib/libast/features/signal.c
new file mode 100644
index 0000000..07c9b4b
--- /dev/null
+++ b/src/lib/libast/features/signal.c
@@ -0,0 +1,371 @@
+/***********************************************************************
+* *
+* This software is part of the ast package *
+* Copyright (c) 1985-2011 AT&T Intellectual Property *
+* and is licensed under the *
+* Eclipse Public License, Version 1.0 *
+* by AT&T Intellectual Property *
+* *
+* A copy of the License is available at *
+* http://www.eclipse.org/org/documents/epl-v10.html *
+* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
+* *
+* Information and Software Systems Research *
+* AT&T Research *
+* Florham Park NJ *
+* *
+* Glenn Fowler <gsf@research.att.com> *
+* David Korn <dgk@research.att.com> *
+* Phong Vo <kpv@research.att.com> *
+* *
+***********************************************************************/
+#pragma prototyped
+/*
+ * Glenn Fowler
+ * AT&T Research
+ *
+ * generate signal features
+ */
+
+#include "FEATURE/standards"
+
+#define strsignal ______strsignal
+
+#include <signal.h>
+
+#undef strsignal
+
+struct _m_
+{
+ char* text;
+ char* name;
+ int value;
+};
+
+#define elementsof(x) (sizeof(x)/sizeof(x[0]))
+
+static struct _m_ map[] =
+{
+#ifdef SIGABRT
+#define HAD_SIGABRT 1
+"Abort", "ABRT", SIGABRT,
+#endif
+#ifdef SIGAIO
+#define HAD_SIGAIO 1
+"Asynchronous I/O", "AIO", SIGAIO,
+#endif
+#ifdef SIGALRM
+#define HAD_SIGALRM 1
+"Alarm call", "ALRM", SIGALRM,
+#endif
+#ifdef SIGAPOLLO
+#define HAD_SIGAPOLLO 1
+"Apollo", "APOLLO", SIGAPOLLO,
+#endif
+#ifdef SIGBUS
+#define HAD_SIGBUS 1
+"Bus error", "BUS", SIGBUS,
+#endif
+#ifdef SIGCHLD
+#define HAD_SIGCHLD 1
+"Child status change", "CHLD", SIGCHLD,
+#endif
+#ifdef SIGCLD
+#define HAD_SIGCLD 1
+"Death of child", "CLD", SIGCLD,
+#endif
+#ifdef SIGCONT
+#define HAD_SIGCONT 1
+"Stopped process continued", "CONT", SIGCONT,
+#endif
+#ifdef SIGDANGER
+#define HAD_SIGDANGER 1
+"System crash soon", "DANGER", SIGDANGER,
+#endif
+#ifdef SIGDEBUG
+#define HAD_SIGDEBUG 1
+"Debug trap", "DEBUG", SIGDEBUG,
+#endif
+#ifdef SIGDIL
+#define HAD_SIGDIL 1
+"DIL trap", "DIL", SIGDIL,
+#endif
+#ifdef SIGEMT
+#define HAD_SIGEMT 1
+"EMT trap", "EMT", SIGEMT,
+#endif
+#ifdef SIGERR
+#define HAD_SIGERR 1
+"ERR trap", "ERR", SIGERR,
+#endif
+#ifdef SIGEXIT
+#define HAD_SIGEXIT 1
+"Exit", "EXIT", SIGEXIT,
+#endif
+#ifdef SIGFPE
+#define HAD_SIGFPE 1
+"Floating exception", "FPE", SIGFPE,
+#endif
+#ifdef SIGFREEZE
+#define HAD_SIGFREEZE 1
+"CPR freeze", "FREEZE", SIGFREEZE,
+#endif
+#ifdef SIGHUP
+#define HAD_SIGHUP 1
+"Hangup", "HUP", SIGHUP,
+#endif
+#ifdef SIGILL
+#define HAD_SIGILL 1
+"Illegal instruction", "ILL", SIGILL,
+#endif
+#ifdef SIGINT
+#define HAD_SIGINT 1
+"Interrupt", "INT", SIGINT,
+#endif
+#ifdef SIGIO
+#define HAD_SIGIO 1
+"IO possible", "IO", SIGIO,
+#endif
+#ifdef SIGIOT
+#define HAD_SIGIOT 1
+"IOT trap", "IOT", SIGIOT,
+#endif
+#ifdef SIGKILL
+#define HAD_SIGKILL 1
+"Killed", "KILL", SIGKILL,
+#endif
+#ifdef SIGLAB
+#define HAD_SIGLAB 1
+"Security label changed", "LAB", SIGLAB,
+#endif
+#ifdef SIGLOST
+#define HAD_SIGLOST 1
+"Resources lost", "LOST", SIGLOST,
+#endif
+#ifdef SIGLWP
+#define HAD_SIGLWP 1
+"Thread event", "LWP", SIGLWP,
+#endif
+#ifdef SIGMIGRATE
+#define HAD_SIGMIGRATE 1
+"Migrate process", "MIGRATE", SIGMIGRATE,
+#endif
+#ifdef SIGPHONE
+#define HAD_SIGPHONE 1
+"Phone status change", "PHONE", SIGPHONE,
+#endif
+#ifdef SIGPIPE
+#define HAD_SIGPIPE 1
+"Broken pipe", "PIPE", SIGPIPE,
+#endif
+#ifdef SIGPOLL
+#define HAD_SIGPOLL 1
+"Poll event", "POLL", SIGPOLL,
+#endif
+#ifdef SIGPROF
+#define HAD_SIGPROF 1
+"Profile timer alarm", "PROF", SIGPROF,
+#endif
+#ifdef SIGPWR
+#define HAD_SIGPWR 1
+"Power fail", "PWR", SIGPWR,
+#endif
+#ifdef SIGQUIT
+#define HAD_SIGQUIT 1
+"Quit", "QUIT", SIGQUIT,
+#endif
+#ifdef SIGSEGV
+#define HAD_SIGSEGV 1
+"Memory fault", "SEGV", SIGSEGV,
+#endif
+#ifdef SIGSOUND
+#define HAD_SIGSOUND 1
+"Sound completed", "SOUND", SIGSOUND,
+#endif
+#ifdef SIGSSTOP
+#define HAD_SIGSSTOP 1
+"Sendable stop", "SSTOP", SIGSSTOP,
+#endif
+#ifdef gould
+#define HAD_gould 1
+"Stack overflow", "STKOV", 28,
+#endif
+#ifdef SIGSTOP
+#define HAD_SIGSTOP 1
+"Stopped (signal)", "STOP", SIGSTOP,
+#endif
+#ifdef SIGSYS
+#define HAD_SIGSYS 1
+"Bad system call", "SYS", SIGSYS,
+#endif
+#ifdef SIGTERM
+#define HAD_SIGTERM 1
+"Terminated", "TERM", SIGTERM,
+#endif
+#ifdef SIGTHAW
+#define HAD_SIGTHAW 1
+"CPR thaw", "THAW", SIGTHAW,
+#endif
+#ifdef SIGTINT
+#define HAD_SIGTINT 1
+"Interrupt (terminal)", "TINT", SIGTINT,
+#endif
+#ifdef SIGTRAP
+#define HAD_SIGTRAP 1
+"Trace trap", "TRAP", SIGTRAP,
+#endif
+#ifdef SIGTSTP
+#define HAD_SIGTSTP 1
+"Stopped", "TSTP", SIGTSTP,
+#endif
+#ifdef SIGTTIN
+#define HAD_SIGTTIN 1
+"Stopped (tty input)", "TTIN", SIGTTIN,
+#endif
+#ifdef SIGTTOU
+#define HAD_SIGTTOU 1
+"Stopped (tty output)", "TTOU", SIGTTOU,
+#endif
+#ifdef SIGURG
+#define HAD_SIGURG 1
+"Urgent IO", "URG", SIGURG,
+#endif
+#ifdef SIGUSR1
+#define HAD_SIGUSR1 1
+"User signal 1", "USR1", SIGUSR1,
+#endif
+#ifdef SIGUSR2
+#define HAD_SIGUSR2 1
+"User signal 2", "USR2", SIGUSR2,
+#endif
+#ifdef SIGVTALRM
+#define HAD_SIGVTALRM 1
+"Virtual timer alarm", "VTALRM", SIGVTALRM,
+#endif
+#ifdef SIGWAITING
+#define HAD_SIGWAITING 1
+"All threads blocked", "WAITING", SIGWAITING,
+#endif
+#ifdef SIGWINCH
+#define HAD_SIGWINCH 1
+"Window change", "WINCH", SIGWINCH,
+#endif
+#ifdef SIGWIND
+#define HAD_SIGWIND 1
+"Window change", "WIND", SIGWIND,
+#endif
+#ifdef SIGWINDOW
+#define HAD_SIGWINDOW 1
+"Window change", "WINDOW", SIGWINDOW,
+#endif
+#ifdef SIGXCPU
+#define HAD_SIGXCPU 1
+"CPU time limit", "XCPU", SIGXCPU,
+#endif
+#ifdef SIGXFSZ
+#define HAD_SIGXFSZ 1
+"File size limit", "XFSZ", SIGXFSZ,
+#endif
+#include "FEATURE/siglist"
+0
+};
+
+#define RANGE_MIN (1<<14)
+#define RANGE_MAX (1<<13)
+#define RANGE_RT (1<<12)
+
+#define RANGE_SIG (~(RANGE_MIN|RANGE_MAX|RANGE_RT))
+
+static int mapindex[1024];
+
+#if _lib_strsignal
+extern char* strsignal(int);
+#endif
+
+int
+main()
+{
+ register int i;
+ register int j;
+ register int k;
+ int m;
+ int n;
+#if _lib_strsignal
+ char* s;
+#endif
+
+ k = 0;
+ for (i = 0; map[i].name; i++)
+ if ((j = map[i].value) > 0 && j < elementsof(mapindex) && !mapindex[j])
+ {
+ if (j > k)
+ k = j;
+ mapindex[j] = i;
+ }
+#ifdef SIGRTMIN
+ i = SIGRTMIN;
+#ifdef SIGRTMAX
+ j = SIGRTMAX;
+#else
+ j = i;
+#endif
+ if (j >= elementsof(mapindex))
+ j = elementsof(mapindex) - 1;
+ if (i <= j && i > 0 && i < elementsof(mapindex) && j > 0 && j < elementsof(mapindex))
+ {
+ if (j > k)
+ k = j;
+ mapindex[i] = RANGE_MIN | RANGE_RT;
+ n = 1;
+ while (++i < j)
+ mapindex[i] = RANGE_RT | n++;
+ mapindex[j] = RANGE_MAX | RANGE_RT | n;
+ }
+#endif
+ printf("#pragma prototyped\n");
+ printf("#define SIG_MAX %d\n", k);
+ printf("\n");
+ printf("static const char* const sig_name[] =\n");
+ printf("{\n");
+ for (i = 0; i <= k; i++)
+ if (!(j = mapindex[i]))
+ printf(" \"%d\",\n", i);
+ else if (j & RANGE_RT)
+ {
+ if (j & RANGE_MIN)
+ printf(" \"RTMIN\",\n");
+ else if (j & RANGE_MAX)
+ printf(" \"RTMAX\",\n");
+ else
+ {
+ m = j & RANGE_SIG;
+ if (m > n / 2)
+ printf(" \"RTMAX-%d\",\n", n - m);
+ else
+ printf(" \"RTMIN+%d\",\n", m);
+ }
+ }
+ else
+ printf(" \"%s\",\n", map[j].name);
+ printf(" 0\n");
+ printf("};\n");
+ printf("\n");
+ printf("static const char* const sig_text[] =\n");
+ printf("{\n");
+ for (i = 0; i <= k; i++)
+ if (!(j = mapindex[i]))
+ printf(" \"Signal %d\",\n", i);
+ else if (j & RANGE_RT)
+ printf(" \"Realtime priority %d%s\",\n", j & RANGE_SIG, (j & RANGE_MIN) ? " (lo)" : (j & RANGE_MAX) ? " (hi)" : "");
+ else if (map[j].text)
+ printf(" \"%s\",\n", map[j].text);
+#if _lib_strsignal
+ else if (s = strsignal(i))
+ printf(" \"%s\",\n", s);
+#endif
+ else
+ printf(" \"Signal %d\",\n", i);
+ printf(" 0\n");
+ printf("};\n");
+ return 0;
+}
diff --git a/src/lib/libast/features/sizeof b/src/lib/libast/features/sizeof
new file mode 100644
index 0000000..06c8707
--- /dev/null
+++ b/src/lib/libast/features/sizeof
@@ -0,0 +1,13 @@
+tst - note{ sizeof(integral-type) }end output{
+ #include "FEATURE/common"
+ int
+ main()
+ {
+ printf("#define _ast_sizeof_char %d\n", sizeof(char));
+ printf("#define _ast_sizeof_short %d\n", sizeof(short));
+ printf("#define _ast_sizeof_int %d\n", sizeof(int));
+ printf("#define _ast_sizeof_long %d\n", sizeof(long));
+ printf("#define _ast_sizeof_intmax_t %d\n", sizeof(_ast_intmax_t));
+ return 0;
+ }
+}end
diff --git a/src/lib/libast/features/standards b/src/lib/libast/features/standards
new file mode 100644
index 0000000..adee277
--- /dev/null
+++ b/src/lib/libast/features/standards
@@ -0,0 +1,153 @@
+set stdio
+if tst note{ _ALL_SOURCE & _ISOC99_SOURCE & _POSIX_SOURCE & _POSIX_C_SOURCE & _XOPEN_SOURCE & __EXTENSIONS__ works }end compile{
+ #define _ALL_SOURCE 1
+ #define _ISOC99_SOURCE 1
+ #define _POSIX_SOURCE 1
+ #define _POSIX_C_SOURCE 21000101L
+ #define _XOPEN_SOURCE 9900
+ #define _GNU_SOURCE 1
+ #define __EXTENSIONS__ 1
+ #include <sys/types.h>
+ #include <sys/stat.h>
+ #include <stdlib.h>
+ #include <unistd.h>
+ }end {
+ #ifndef _ALL_SOURCE
+ #define _ALL_SOURCE 1
+ #endif
+ #ifndef _ISOC99_SOURCE
+ #define _ISOC99_SOURCE 1
+ #endif
+ #ifndef _POSIX_SOURCE
+ #define _POSIX_SOURCE 1
+ #endif
+ #ifndef _POSIX_C_SOURCE
+ #define _POSIX_C_SOURCE 21000101L
+ #endif
+ #ifndef _XOPEN_SOURCE
+ #define _XOPEN_SOURCE 9900
+ #endif
+ #ifndef _GNU_SOURCE
+ #define _GNU_SOURCE 1
+ #endif
+ #ifndef __EXTENSIONS__
+ #define __EXTENSIONS__ 1
+ #endif
+ }
+elif tst note{ _ALL_SOURCE & _ISOC99_SOURCE & _POSIX_SOURCE & _XOPEN_SOURCE & __EXTENSIONS__ works }end compile{
+ #define _ALL_SOURCE 1
+ #define _ISOC99_SOURCE 1
+ #define _POSIX_SOURCE 1
+ #define _XOPEN_SOURCE 9900
+ #define _GNU_SOURCE 1
+ #define __EXTENSIONS__ 1
+ #include <sys/types.h>
+ #include <sys/stat.h>
+ #include <stdlib.h>
+ #include <unistd.h>
+ }end {
+ #ifndef _ALL_SOURCE
+ #define _ALL_SOURCE 1
+ #endif
+ #ifndef _ISOC99_SOURCE
+ #define _ISOC99_SOURCE 1
+ #endif
+ #ifndef _POSIX_SOURCE
+ #define _POSIX_SOURCE 1
+ #endif
+ #ifndef _XOPEN_SOURCE
+ #define _XOPEN_SOURCE 9900
+ #endif
+ #ifndef _GNU_SOURCE
+ #define _GNU_SOURCE 1
+ #endif
+ #ifndef __EXTENSIONS__
+ #define __EXTENSIONS__ 1
+ #endif
+ }
+elif tst note{ _ISOC99_SOURCE & _POSIX_SOURCE & _POSIX_C_SOURCE & _XOPEN_SOURCE & __EXTENSIONS__ works }end compile{
+ #define _ISOC99_SOURCE 1
+ #define _POSIX_SOURCE 1
+ #define _POSIX_C_SOURCE 21000101L
+ #define _XOPEN_SOURCE 9900
+ #define _GNU_SOURCE 1
+ #define __EXTENSIONS__ 1
+ #include <sys/types.h>
+ #include <sys/stat.h>
+ #include <stdlib.h>
+ #include <unistd.h>
+ }end {
+ #ifndef _ISOC99_SOURCE
+ #define _ISOC99_SOURCE 1
+ #endif
+ #ifndef _POSIX_SOURCE
+ #define _POSIX_SOURCE 1
+ #endif
+ #ifndef _POSIX_C_SOURCE
+ #define _POSIX_C_SOURCE 21000101L
+ #endif
+ #ifndef _XOPEN_SOURCE
+ #define _XOPEN_SOURCE 9900
+ #endif
+ #ifndef _GNU_SOURCE
+ #define _GNU_SOURCE 1
+ #endif
+ #ifndef __EXTENSIONS__
+ #define __EXTENSIONS__ 1
+ #endif
+ }
+elif tst note{ _POSIX_SOURCE & _XOPEN_SOURCE & __EXTENSIONS__ works }end compile{
+ #define _POSIX_SOURCE 1
+ #define _XOPEN_SOURCE 1
+ #define __EXTENSIONS__ 1
+ #include <sys/types.h>
+ #include <sys/stat.h>
+ #include <stdlib.h>
+ #include <unistd.h>
+ }end {
+ #ifndef _POSIX_SOURCE
+ #define _POSIX_SOURCE 1
+ #endif
+ #ifndef _XOPEN_SOURCE
+ #define _XOPEN_SOURCE 1
+ #endif
+ #ifndef __EXTENSIONS__
+ #define __EXTENSIONS__ 1
+ #endif
+ }
+elif tst note{ _XOPEN_SOURCE & __EXTENSIONS__ works }end compile{
+ #define _XOPEN_SOURCE 1
+ #define __EXTENSIONS__ 1
+ #include <sys/types.h>
+ #include <sys/stat.h>
+ #include <stdlib.h>
+ #include <unistd.h>
+ }end {
+ #ifndef _XOPEN_SOURCE
+ #define _XOPEN_SOURCE 1
+ #endif
+ #ifndef __EXTENSIONS__
+ #define __EXTENSIONS__ 1
+ #endif
+ }
+elif tst note{ _XOPEN_SOURCE works }end compile{
+ #define _XOPEN_SOURCE 1
+ #include <sys/types.h>
+ #include <sys/stat.h>
+ #include <stdlib.h>
+ #include <unistd.h>
+ }end {
+ #ifndef _XOPEN_SOURCE
+ #define _XOPEN_SOURCE 1
+ #endif
+ }
+else tst note{ __EXTENSIONS__ works }end compile{
+ #define __EXTENSIONS__ 1
+ #include <sys/types.h>
+ #include <sys/stat.h>
+ }end {
+ #ifndef __EXTENSIONS__
+ #define __EXTENSIONS__ 1
+ #endif
+ }
+endif
diff --git a/src/lib/libast/features/stdio b/src/lib/libast/features/stdio
new file mode 100644
index 0000000..b323893
--- /dev/null
+++ b/src/lib/libast/features/stdio
@@ -0,0 +1,568 @@
+set prototyped
+ref -D_def_map_ast=1
+iff SFSTDIO
+cat{
+ #define __FILE_typedef 1
+ #define _FILE_DEFINED 1
+ #define _FILE_defined 1
+ #define _FILEDEFED 1
+
+ #ifndef __FILE_TAG
+ #define __FILE_TAG _sfio_s
+ #endif
+
+ #undef FILE
+ #undef _FILE
+ #undef fpos_t
+ #undef fpos64_t
+
+ typedef struct _sfio_s _sfio_FILE;
+
+ #define FILE _sfio_FILE
+ #define _FILE FILE
+
+ #if !defined(__FILE) && !__CYGWIN__
+ #undef __FILE
+ #define __FILE FILE
+ #endif
+
+ #if defined(_AST_H) || defined(_SFIO_H)
+
+ #define BUFSIZ SF_BUFSIZE
+
+ #else
+
+ #ifndef BUFSIZ
+ #define BUFSIZ 8192
+ #endif
+
+ #ifndef EOF
+ #define EOF (-1)
+ #endif
+
+ #ifndef NULL
+ #define NULL 0
+ #endif
+
+ #ifndef SEEK_SET
+ #define SEEK_SET 0
+ #define SEEK_CUR 1
+ #define SEEK_END 2
+ #endif
+
+ #include <ast_std.h>
+
+ #include <sfio_s.h>
+
+ #if __cplusplus
+ #define _sf_(f) (f)
+ #else
+ #define _sf_(f) ((struct _sfio_s*)(f))
+ #endif
+
+ #define _SF_EOF 0000200
+ #define _SF_ERROR 0000400
+
+ #endif
+
+ #ifdef _NO_LARGEFILE64_SOURCE
+ #undef _LARGEFILE64_SOURCE
+ #endif
+
+ #ifdef _LARGEFILE64_SOURCE
+ #undef off_t
+ #endif
+
+ #define fpos_t _ast_fpos_t
+ #if _typ_int64_t
+ #define fpos64_t _ast_fpos_t
+ #endif
+
+ typedef struct _ast_fpos_s
+ {
+ intmax_t _sf_offset;
+ unsigned char _sf_state[64 - sizeof(intmax_t)];
+ } _ast_fpos_t;
+
+ #define _base _data
+ #define _ptr _next
+ #define _IOFBF 0
+ #define _IONBF 1
+ #define _IOLBF 2
+
+ #if defined(__cplusplus) && defined(__THROW) && !defined(_UWIN)
+
+ #undef FILE
+ #define FILE FILE
+ typedef struct _sfio_s FILE;
+
+ #undef strerror
+ extern char* strerror(int) __THROW;
+
+ extern int _doprnt(const char*, va_list, FILE*);
+ extern int _doscan(FILE*, const char*, va_list);
+ extern int asprintf(char**, const char*, ...);
+ extern int clearerr(FILE*);
+ extern int fclose(FILE*);
+ extern FILE* fdopen(int, const char*);
+ extern int feof(FILE*);
+ extern int ferror(FILE*);
+ extern int fflush(FILE*);
+ extern int fgetc(FILE*);
+ extern int fgetpos(FILE*, fpos_t*);
+ extern char* fgets(char*, int, FILE*);
+ extern int fileno(FILE*);
+ extern FILE* fopen(const char*, const char*);
+ extern int fprintf(FILE*, const char*, ...);
+ extern int fpurge(FILE*);
+ extern int fputc(int, FILE*);
+ extern int fputs(const char*, FILE*);
+ extern size_t fread(void*, size_t, size_t, FILE*);
+ extern FILE* freopen(const char*, const char*, FILE*);
+ extern int fscanf(FILE*, const char*, ...);
+ extern int fseek(FILE*, long, int);
+ extern int fseeko(FILE*, off_t, int);
+ extern int fsetpos(FILE*, const fpos_t*);
+ extern long ftell(FILE*);
+ extern off_t ftello(FILE*);
+ extern size_t fwrite(const void*, size_t, size_t, FILE*);
+ extern int getc(FILE*);
+ extern int getchar(void);
+ extern char* gets(char*);
+ extern int getw(FILE*);
+ extern int pclose(FILE*);
+ extern FILE* popen(const char*, const char*);
+ extern int printf(const char*, ...);
+ extern int putc(int, FILE*);
+ extern int putchar(int);
+ extern int puts(const char*);
+ extern int putw(int, FILE*);
+ extern void rewind(FILE*);
+ extern int scanf(const char*, ...);
+ extern void setbuf(FILE*, char*);
+ extern int setbuffer(FILE*, char*, int);
+ extern int setlinebuf(FILE*);
+ extern int setvbuf(FILE*, char*, int, size_t);
+ extern int snprintf(char*, int, const char*, ...);
+ extern int sprintf(char*, const char*, ...);
+ extern int sscanf(const char*, const char*, ...);
+ extern FILE* tmpfile(void);
+ extern int ungetc(int, FILE*);
+ extern int vasprintf(char**, const char*, va_list);
+ extern int vfprintf(FILE*, const char*, va_list);
+ extern int vfscanf(FILE*, const char*, va_list);
+ extern int vprintf(const char*, va_list);
+ extern int vscanf(const char*, va_list);
+ extern int vsnprintf(char*, int, const char*, va_list);
+ extern int vsprintf(char*, const char*, va_list);
+ extern int vsscanf(const char*, const char*, va_list);
+
+ #if _typ_int64_t
+
+ extern int fgetpos64(FILE*, fpos64_t*);
+ extern int fsetpos64(FILE*, const fpos64_t*);
+ extern int fseek64(FILE*, int64_t, int);
+ extern int fseeko64(FILE*, int64_t, int);
+ extern int64_t ftell64(FILE*);
+ extern int64_t ftello64(FILE*);
+
+ #endif
+
+ extern void clearerr_unlocked(FILE*);
+ extern int feof_unlocked(FILE*);
+ extern int ferror_unlocked(FILE*);
+ extern int fflush_unlocked(FILE*);
+ extern int fgetc_unlocked(FILE*);
+ extern char* fgets_unlocked(char*, int, FILE*);
+ extern int fileno_unlocked(FILE*);
+ extern int fputc_unlocked(int, FILE*);
+ extern int fputs_unlocked(char*, FILE*);
+ extern size_t fread_unlocked(void*, size_t, size_t, FILE*);
+ extern size_t fwrite_unlocked(void*, size_t, size_t, FILE*);
+ extern int getc_unlocked(FILE*);
+ extern int getchar_unlocked(void);
+ extern int putc_unlocked(int, FILE*);
+ extern int putchar_unlocked(int);
+
+ extern void flockfile(FILE*);
+ extern int ftrylockfile(FILE*);
+ extern void funlockfile(FILE*);
+
+ #ifdef _USE_GNU
+
+ extern int fcloseall(void);
+ extern FILE* fmemopen(void*, size_t, const char*);
+ extern ssize_t __getdelim(char**, size_t*, int, FILE*);
+ extern ssize_t getdelim(char**, size_t*, int, FILE*);
+ extern ssize_t getline(char**, size_t*, FILE*);
+
+ #endif
+
+ #endif
+}end
+output{
+ #include <stdio.h>
+ #ifndef FILENAME_MAX
+ #ifndef NAME_MAX
+ #ifndef _POSIX_NAME_MAX
+ #define _POSIX_NAME_MAX 14
+ #endif
+ #define NAME_MAX _POSIX_NAME_MAX
+ #endif
+ #define FILENAME_MAX NAME_MAX
+ #endif
+ #ifndef FOPEN_MAX
+ #ifdef STREAM_MAX
+ #define FOPEN_MAX STREAM_MAX
+ #else
+ #ifndef OPEN_MAX
+ #ifndef _POSIX_OPEN_MAX
+ #define _POSIX_OPEN_MAX 20
+ #endif
+ #define OPEN_MAX _POSIX_OPEN_MAX
+ #endif
+ #define FOPEN_MAX OPEN_MAX
+ #endif
+ #endif
+ #ifndef TMP_MAX
+ #define TMP_MAX 33520641
+ #endif
+ int
+ main()
+ {
+ printf("#ifndef FILENAME_MAX\n");
+ printf("#define FILENAME_MAX %d\n", FILENAME_MAX);
+ printf("#endif\n");
+ printf("#ifndef FOPEN_MAX\n");
+ printf("#define FOPEN_MAX %d\n", FOPEN_MAX);
+ printf("#endif\n");
+ printf("#ifndef TMP_MAX\n");
+ printf("#define TMP_MAX %d\n", TMP_MAX);
+ printf("#endif\n");
+ #if !_UWIN
+ printf("\n");
+ printf("#define _doprnt _ast_doprnt\n");
+ printf("#define _doscan _ast_doscan\n");
+ printf("#define asprintf _ast_asprintf\n");
+ printf("#define clearerr _ast_clearerr\n");
+ printf("#define fclose _ast_fclose\n");
+ printf("#define fdopen _ast_fdopen\n");
+ printf("#define fflush _ast_fflush\n");
+ printf("#define fgetc _ast_fgetc\n");
+ printf("#define fgetpos _ast_fgetpos\n");
+ printf("#define fgetpos64 _ast_fgetpos64\n");
+ printf("#define fgets _ast_fgets\n");
+ printf("#define fopen _ast_fopen\n");
+ printf("#define fprintf _ast_fprintf\n");
+ printf("#define fpurge _ast_fpurge\n");
+ printf("#define fputs _ast_fputs\n");
+ printf("#define fread _ast_fread\n");
+ printf("#define freopen _ast_freopen\n");
+ printf("#define fscanf _ast_fscanf\n");
+ printf("#define fseek _ast_fseek\n");
+ printf("#define fseek64 _ast_fseek64\n");
+ printf("#define fseeko _ast_fseeko\n");
+ printf("#define fseeko64 _ast_fseeko64\n");
+ printf("#define fsetpos _ast_fsetpos\n");
+ printf("#define fsetpos64 _ast_fsetpos64\n");
+ printf("#define ftell _ast_ftell\n");
+ printf("#define ftell64 _ast_ftell64\n");
+ printf("#define ftello _ast_ftello\n");
+ printf("#define ftello64 _ast_ftello64\n");
+ printf("#define fwrite _ast_fwrite\n");
+ printf("#define gets _ast_gets\n");
+ printf("#define getw _ast_getw\n");
+ printf("#define pclose _ast_pclose\n");
+ printf("#define popen _ast_popen\n");
+ printf("#define printf _ast_printf\n");
+ printf("#define puts _ast_puts\n");
+ printf("#define putw _ast_putw\n");
+ printf("#define rewind _ast_rewind\n");
+ printf("#define scanf _ast_scanf\n");
+ printf("#define setbuf _ast_setbuf\n");
+ printf("#undef setbuffer\n");
+ printf("#define setbuffer _ast_setbuffer\n");
+ printf("#define setlinebuf _ast_setlinebuf\n");
+ printf("#define setvbuf _ast_setvbuf\n");
+ printf("#define snprintf _ast_snprintf\n");
+ printf("#define sprintf _ast_sprintf\n");
+ printf("#define sscanf _ast_sscanf\n");
+ printf("#define tmpfile _ast_tmpfile\n");
+ printf("#define ungetc _ast_ungetc\n");
+ printf("#define vasprintf _ast_vasprintf\n");
+ printf("#define vfprintf _ast_vfprintf\n");
+ printf("#define vfscanf _ast_vfscanf\n");
+ printf("#define vprintf _ast_vprintf\n");
+ printf("#define vscanf _ast_vscanf\n");
+ printf("#define vsnprintf _ast_vsnprintf\n");
+ printf("#define vsprintf _ast_vsprintf\n");
+ printf("#define vsscanf _ast_vsscanf\n");
+
+ printf("#define fcloseall _ast_fcloseall\n");
+ printf("#define _filbuf _ast__filbuf\n");
+ printf("#define fmemopen _ast_fmemopen\n");
+ printf("#define __getdelim _ast___getdelim\n");
+ printf("#define getdelim _ast_getdelim\n");
+ printf("#define getline _ast_getline\n");
+
+ printf("#define clearerr_unlocked _ast_clearerr_unlocked\n");
+ printf("#define feof_unlocked _ast_feof_unlocked\n");
+ printf("#define ferror_unlocked _ast_ferror_unlocked\n");
+ printf("#define fflush_unlocked _ast_fflush_unlocked\n");
+ printf("#define fgetc_unlocked _ast_fgetc_unlocked\n");
+ printf("#define fgets_unlocked _ast_fgets_unlocked\n");
+ printf("#define fileno_unlocked _ast_fileno_unlocked\n");
+ printf("#define fputc_unlocked _ast_fputc_unlocked\n");
+ printf("#define fputs_unlocked _ast_fputs_unlocked\n");
+ printf("#define fread_unlocked _ast_fread_unlocked\n");
+ printf("#define fwrite_unlocked _ast_fwrite_unlocked\n");
+ printf("#define getc_unlocked _ast_getc_unlocked\n");
+ printf("#define getchar_unlocked _ast_getchar_unlocked\n");
+ printf("#define putc_unlocked _ast_putc_unlocked\n");
+ printf("#define putchar_unlocked _ast_putchar_unlocked\n");
+
+ printf("#define flockfile _ast_flockfile\n");
+ printf("#define ftrylockfile _ast_ftrylockfile\n");
+ printf("#define funlockfile _ast_funlockfile\n");
+
+ printf("\n");
+ #endif
+ return 0;
+ }
+}end
+macro{
+ <<"#if defined(__STDPP__directive) && defined(__STDPP__initial)">>
+ <<"__STDPP__directive pragma pp:initial">>
+ <<"#endif">>
+ <<"#ifndef P_tmpdir">>
+ #ifndef P_tmpdir
+ #define P_tmpdir "/usr/tmp/"
+ #endif
+ <<"#define P_tmpdir">> P_tmpdir <<"/*NOCATLITERAL*/">>
+ <<"#endif">>
+ <<"#ifndef L_ctermid">>
+ #ifndef L_ctermid
+ #define L_ctermid 9
+ #endif
+ <<"#define L_ctermid">> L_ctermid
+ <<"#endif">>
+ <<"#ifndef L_tmpnam">>
+ #ifndef L_tmpnam
+ #define L_tmpnam (sizeof(P_tmpdir)+15)
+ #endif
+ <<"#define L_tmpnam">> L_tmpnam
+ <<"#endif">>
+ <<"#if defined(__STDPP__directive) && defined(__STDPP__initial)">>
+ <<"__STDPP__directive pragma pp:noinitial">>
+ <<"#endif">>
+}end
+cat{
+ #if defined(__cplusplus) && defined(__THROW)
+ extern char* ctermid(char*) __THROW;
+ #else
+ extern char* ctermid(char*);
+ #endif
+ extern char* tmpnam(char*);
+ extern char* tempnam(const char*, const char*);
+ extern void perror(const char*);
+ #ifndef _AST_STD_H
+ #ifndef remove
+ extern int remove(const char*);
+ #endif
+ #ifndef rename
+ extern int rename(const char*, const char*);
+ #endif
+ #endif
+
+ #undef extern
+
+ #if _BLD_ast && defined(__EXPORT__)
+ #define extern __EXPORT__
+ #endif
+
+ extern int _doprnt(const char*, va_list, FILE*);
+ extern int _doscan(FILE*, const char*, va_list);
+ extern int asprintf(char**, const char*, ...);
+ extern int clearerr(FILE*);
+ extern int fclose(FILE*);
+ extern FILE* fdopen(int, const char*);
+ extern int feof(FILE*);
+ extern int ferror(FILE*);
+ extern int fflush(FILE*);
+ extern int fgetc(FILE*);
+ extern int fgetpos(FILE*, fpos_t*);
+ extern char* fgets(char*, int, FILE*);
+ extern int fileno(FILE*);
+ extern FILE* fopen(const char*, const char*);
+ extern int fprintf(FILE*, const char*, ...);
+ extern int fpurge(FILE*);
+ extern int fputc(int, FILE*);
+ extern int fputs(const char*, FILE*);
+ extern size_t fread(void*, size_t, size_t, FILE*);
+ extern FILE* freopen(const char*, const char*, FILE*);
+ extern int fscanf(FILE*, const char*, ...);
+ extern int fseek(FILE*, long, int);
+ extern int fseeko(FILE*, off_t, int);
+ extern int fsetpos(FILE*, const fpos_t*);
+ extern long ftell(FILE*);
+ extern off_t ftello(FILE*);
+ extern size_t fwrite(const void*, size_t, size_t, FILE*);
+ extern int getc(FILE*);
+ extern int getchar(void);
+ extern char* gets(char*);
+ extern int getw(FILE*);
+ extern int pclose(FILE*);
+ extern FILE* popen(const char*, const char*);
+ extern int printf(const char*, ...);
+ extern int putc(int, FILE*);
+ extern int putchar(int);
+ extern int puts(const char*);
+ extern int putw(int, FILE*);
+ extern void rewind(FILE*);
+ extern int scanf(const char*, ...);
+ extern void setbuf(FILE*, char*);
+ extern int setbuffer(FILE*, char*, int);
+ extern int setlinebuf(FILE*);
+ extern int setvbuf(FILE*, char*, int, size_t);
+ extern int snprintf(char*, int, const char*, ...);
+ extern int sprintf(char*, const char*, ...);
+ extern int sscanf(const char*, const char*, ...);
+ extern FILE* tmpfile(void);
+ extern int ungetc(int, FILE*);
+ extern int vasprintf(char**, const char*, va_list);
+ extern int vfprintf(FILE*, const char*, va_list);
+ extern int vfscanf(FILE*, const char*, va_list);
+ extern int vprintf(const char*, va_list);
+ extern int vscanf(const char*, va_list);
+ extern int vsnprintf(char*, int, const char*, va_list);
+ extern int vsprintf(char*, const char*, va_list);
+ extern int vsscanf(const char*, const char*, va_list);
+
+ #if _typ_int64_t
+
+ extern int fgetpos64(FILE*, fpos64_t*);
+ extern int fsetpos64(FILE*, const fpos64_t*);
+ extern int fseek64(FILE*, int64_t, int);
+ extern int fseeko64(FILE*, int64_t, int);
+ extern int64_t ftell64(FILE*);
+ extern int64_t ftello64(FILE*);
+
+ #ifdef _LARGEFILE64_SOURCE
+
+ #undef fpos_t
+ #undef off_t
+ #undef fgetpos
+ #undef fsetpos
+ #undef fseek
+ #undef fseeko
+ #undef ftell
+ #undef ftello
+
+ #define fpos_t fpos64_t
+ #if _typ_off64_t
+ #define off_t off64_t
+ #else
+ #define off_t int64_t
+ #endif
+
+ #define fgetpos fgetpos64
+ #define fsetpos fsetpos64
+ #define fseek fseek64
+ #define fseeko fseeko64
+ #define ftell ftell64
+ #define ftello ftello64
+
+ #endif
+
+ #endif
+
+ extern void clearerr_unlocked(FILE*);
+ extern int feof_unlocked(FILE*);
+ extern int ferror_unlocked(FILE*);
+ extern int fflush_unlocked(FILE*);
+ extern int fgetc_unlocked(FILE*);
+ extern char* fgets_unlocked(char*, int, FILE*);
+ extern int fileno_unlocked(FILE*);
+ extern int fputc_unlocked(int, FILE*);
+ extern int fputs_unlocked(char*, FILE*);
+ extern size_t fread_unlocked(void*, size_t, size_t, FILE*);
+ extern size_t fwrite_unlocked(void*, size_t, size_t, FILE*);
+ extern int getc_unlocked(FILE*);
+ extern int getchar_unlocked(void);
+ extern int putc_unlocked(int, FILE*);
+ extern int putchar_unlocked(int);
+
+ #ifdef _USE_GNU
+
+ extern int fcloseall(void);
+ extern FILE* fmemopen(void*, size_t, const char*);
+ extern ssize_t __getdelim(char**, size_t*, int, FILE*);
+ extern ssize_t getdelim(char**, size_t*, int, FILE*);
+ extern ssize_t getline(char**, size_t*, FILE*);
+
+ #endif
+
+ #undef extern
+
+ #if _BLD_DLL && _DLL_INDIRECT_DATA
+
+ #define stdin ((FILE*)_ast_dll->_ast_stdin)
+ #define stdout ((FILE*)_ast_dll->_ast_stdout)
+ #define stderr ((FILE*)_ast_dll->_ast_stderr)
+
+ #else
+
+ #define stdin (&_Sfstdin)
+ #define stdout (&_Sfstdout)
+ #define stderr (&_Sfstderr)
+
+ #endif
+
+ #if defined(_AST_H) || defined(_SFIO_H)
+
+ #define feof(f) sfeof(f)
+ #define ferror(f) sferror(f)
+ #define fileno(f) sffileno(f)
+ #define fputc(c,f) sfputc(f,c)
+ #define getc(f) sfgetc(f)
+ #define getchar() sfgetc(sfstdin)
+ #define putc(c,f) sfputc(f,c)
+ #define putchar(c) sfputc(sfstdout,c)
+
+ #else
+
+ #if !_UWIN
+ #if _BLD_ast && defined(__EXPORT__)
+ #define extern extern __EXPORT__
+ #endif
+ #if !_BLD_ast && defined(__IMPORT__)
+ #define extern extern __IMPORT__
+ #endif
+ #endif
+
+ extern FILE _Sfstdin;
+ extern FILE _Sfstdout;
+ extern FILE _Sfstderr;
+
+ #undef extern
+
+ #define feof(f) (_sf_(f)->_flags&_SF_EOF)
+ #define ferror(f) (_sf_(f)->_flags&_SF_ERROR)
+ #define fileno(f) (_sf_(f)->_file)
+ #define fputc(c,f) (_sf_(f)->_next>=_sf_(f)->_endw?_sfflsbuf(_sf_(f),(int)((unsigned char)(c))):(int)(*_sf_(f)->_next++=(unsigned char)(c)))
+ #define getc(f) (_sf_(f)->_next>=_sf_(f)->_endr?_sffilbuf(_sf_(f),0):(int)(*_sf_(f)->_next++))
+ #define getchar() getc(stdin)
+ #define putc(c,f) fputc(c,f)
+ #define putchar(c) fputc(c,stdout)
+
+ #if _BLD_ast && defined(__EXPORT__)
+ #define extern __EXPORT__
+ #endif
+
+ extern int _sffilbuf(FILE*, int);
+ extern int _sfflsbuf(FILE*, int);
+
+ #undef extern
+
+ #endif
+}end
diff --git a/src/lib/libast/features/sys b/src/lib/libast/features/sys
new file mode 100644
index 0000000..87ad1e5
--- /dev/null
+++ b/src/lib/libast/features/sys
@@ -0,0 +1,272 @@
+set prototyped
+iff AST_SYS
+ref -D_def_map_ast
+
+print #if __mips == 2 && !defined(_NO_LARGEFILE64_SOURCE)
+print #define _NO_LARGEFILE64_SOURCE 1
+print #endif
+print #if !defined(_NO_LARGEFILE64_SOURCE) && _typ_off64_t && _lib_lseek64 && _lib_stat64
+print #if !defined(_LARGEFILE64_SOURCE)
+print #define _LARGEFILE64_SOURCE 1
+print #endif
+print #if !defined(_LARGEFILE_SOURCE)
+print #define _LARGEFILE_SOURCE 1
+print #endif
+print #else
+print #undef _LARGEFILE64_SOURCE
+print #undef _LARGEFILE_SOURCE
+print #undef _typ_off64_t
+print #undef _typ_struct_dirent64
+print #undef _lib_creat64
+print #undef _lib_fstat64
+print #undef _lib_fstatvfs64
+print #undef _lib_ftruncate64
+print #undef _lib_lseek64
+print #undef _lib_lstat64
+print #undef _lib_mmap64
+print #undef _lib_open64
+print #undef _lib_readdir64
+print #undef _lib_stat64
+print #undef _lib_statvfs64
+print #undef _lib_truncate64
+print #endif
+
+print #if defined(__STDC__) && !defined(__USE_FIXED_PROTOTYPES__)
+print #define __USE_FIXED_PROTOTYPES__ 1 /* kick gcc out of the past */
+print #endif
+
+header stdlib.h
+header stddef.h
+header sys/types.h
+header stdint.h
+header inttypes.h
+header string.h
+header unistd.h
+header limits.h
+header fcntl.h
+header locale.h
+
+typ dev_t,nlink_t fail{
+ echo "#ifndef $m"
+ echo "#define $m 1"
+ echo "typedef short $v;"
+ echo "#endif"
+}end
+typ gid_t,mode_t,uid_t fail{
+ echo "#ifndef $m"
+ echo "#define $m 1"
+ echo "typedef unsigned short $v;"
+ echo "#endif"
+}end
+typ wchar_t stdio.h wchar.h fail{
+ echo "#ifndef $m"
+ echo "#define $m 1"
+ echo "typedef unsigned short $v;"
+ echo "#endif"
+}end
+typ pid_t,ssize_t fail{
+ echo "#ifndef $m"
+ echo "#define $m 1"
+ echo "typedef int $v;"
+ echo "#endif"
+}end
+typ wint_t stdio.h wchar.h fail{
+ echo "#ifndef $m"
+ echo "#define $m 1"
+ echo "typedef int $v;"
+ echo "#endif"
+}end
+typ socklen_t sys/socket.h fail{
+ echo "#ifndef $m"
+ echo "#define $m 1"
+ echo "typedef int $v;"
+ echo "#endif"
+}end
+typ size_t fail{
+ echo "#ifndef $m"
+ echo "#define $m 1"
+ echo "typedef unsigned int $v;"
+ echo "#endif"
+}end
+typ clock_t,ino_t,off_t,ptrdiff_t fail{
+ echo "#ifndef $m"
+ echo "#define $m 1"
+ echo "typedef long $v;"
+ echo "#endif"
+}end
+typ time_t fail{
+ echo "#ifndef $m"
+ echo "#define $m 1"
+ echo "typedef unsigned long $v;"
+ echo "#endif"
+}end
+typ div_t fail{
+ echo "#ifndef $m"
+ echo "#define $m 1"
+ echo "typedef struct { int quot; int rem; } $v;"
+ echo "#endif"
+}end
+typ ldiv_t fail{
+ echo "#ifndef $m"
+ echo "#define $m 1"
+ echo "typedef struct { long quot; long rem; } $v;"
+ echo "#endif"
+}end
+tst typ_signed_size_t output{
+ #include <sys/types.h>
+ int
+ main()
+ {
+ unsigned long u = ~0;
+ size_t s = ~0;
+ if (s >= 0)
+ return 1;
+ printf("#if !defined(__cplusplus) && !defined(c_plusplus) && !defined(_typ_signed_size_t)\n/* what dipsticks made size_t signed? sun. */\ntypedef unsigned %s _ast_size_t;\n#undef\tsize_t\n#define size_t\t_ast_size_t\n#endif\n", u == (unsigned long)s ? "long" : "int");
+ return 0;
+ }
+}end
+
+define offsetof (type,member) ((size_t)&(((type*)0)->member))
+define EXIT_FAILURE 1
+define EXIT_SUCCESS 0
+define MB_CUR_MAX 1
+define RAND_MAX 32767
+
+define STDIN_FILENO 0
+define STDOUT_FILENO 1
+define STDERR_FILENO 2
+
+define NULL 0
+
+define SEEK_SET 0
+define SEEK_CUR 1
+define SEEK_END 2
+
+define F_OK 0
+define X_OK 1
+define W_OK 2
+define R_OK 4
+
+print #if _BLD_ast && defined(__EXPORT__)
+print #define extern __EXPORT__
+print #endif
+
+extern _exit void (int)
+extern abort void (void)
+extern abs int (int)
+extern access int (const char*, int)
+extern alarm unsigned (unsigned)
+extern atexit int (void(*)(void))
+extern atof double (const char*)
+extern atoi int (const char*)
+extern atol long (const char*)
+extern bsearch void* (const void*, const void*, size_t, size_t, int(*)(const void*, const void*))
+extern calloc void* (size_t, size_t)
+extern cfree void (void*)
+extern chdir int (const char*)
+extern chown int (const char*, uid_t, gid_t)
+extern close int (int)
+extern confstr size_t (int, char*, size_t)
+extern div div_t (int, int)
+extern dup int (int)
+extern dup2 int (int, int)
+extern eaccess int (const char*, int)
+extern execl int (const char*, const char*, ...)
+extern execle int (const char*, const char*, ...)
+extern execlp int (const char*, const char*, ...)
+extern execv int (const char*, char* const[])
+extern execve int (const char*, char* const[], char* const[])
+extern execve int (const char*, char* const[], char* const[])
+extern execvp int (const char*, char* const[])
+extern execvpe int (const char*, char* const[], char* const[])
+extern exit void (int)
+extern fork pid_t (void)
+extern fpathconf long (int, int)
+extern free void (void*)
+extern fsync int (int)
+extern ftruncate int (int, off_t)
+extern getcwd char* (char*, size_t)
+extern getegid gid_t (void)
+extern getenv char* (const char*)
+extern geteuid uid_t (void)
+extern getgid gid_t (void)
+extern getgroups int (int, gid_t[])
+extern getlogin char* (void)
+extern getpgrp pid_t (void)
+extern getpid pid_t (void)
+extern getppid pid_t (void)
+extern gettxt char* (const char*, const char*)
+extern getuid uid_t (void)
+extern isatty int (int)
+extern labs long (long)
+extern ldiv ldiv_t (long, long)
+extern link int (const char*, const char*)
+extern lseek off_t (int, off_t, int)
+extern malloc void* (size_t)
+extern mblen int (const char*, size_t)
+extern mbstowcs size_t (wchar_t*, const char*, size_t)
+extern mbtowc int (wchar_t*, const char*, size_t)
+extern memalign void* (size_t, size_t)
+extern memccpy void* (void*, const void*, int, size_t)
+extern memchr void* (const void*, int, size_t)
+extern memcmp int (const void*, const void*, size_t)
+extern memcpy void* (void*, const void*, size_t)
+extern memmove void* (void*, const void*, size_t)
+extern memset void* (void*, int, size_t)
+extern pathconf long (const char*, int)
+extern pause int (void)
+extern pipe int (int[])
+extern pvalloc void* (size_t)
+extern qsort void (void*, size_t, size_t, int(*)(const void*, const void*))
+extern rand int (void)
+extern read ssize_t (int, void*, size_t)
+extern realloc void* (void*, size_t)
+extern realpath char* (const char*, char*)
+extern resolvepath char* (const char*, char*, size_t)
+extern rmdir int (const char*)
+extern setgid int (gid_t)
+extern setpgid int (pid_t, pid_t)
+extern setsid pid_t (void)
+extern setuid int (uid_t)
+extern sleep unsigned (unsigned int)
+extern spawnveg pid_t (const char*, char* const[], char* const[], pid_t)
+extern srand void (unsigned int)
+extern strcasecmp int (const char*, const char*)
+extern strcat char* (char*, const char*)
+extern strchr char* (const char*, int)
+extern strcmp int (const char*, const char*)
+extern strcoll int (const char*, const char*)
+extern strcpy char* (char*, const char*)
+extern strcspn size_t (const char*, const char*)
+extern strdup char* (const char*)
+extern strlcat size_t (char*, const char*, size_t)
+extern strlcpy size_t (char*, const char*, size_t)
+extern strlen size_t (const char*)
+extern strncasecmp int (const char*, const char*, size_t)
+extern strncat char* (char*, const char*, size_t)
+extern strncmp int (const char*, const char*, size_t)
+extern strncpy char* (char*, const char*, size_t)
+extern strpbrk char* (const char*, const char*)
+extern strrchr char* (const char*, int)
+extern strspn size_t (const char*, const char*)
+extern strstr char* (const char*, const char*)
+extern strtok char* (char*, const char*)
+extern strxfrm size_t (char*, const char*, size_t)
+extern swab void (const void*, void*, ssize_t)
+extern sysconf long (int)
+extern system int (const char*)
+extern tcgetpgrp pid_t (int)
+extern tcsetpgrp int (int, pid_t)
+extern truncate int (const char*, off_t)
+extern ttyname char* (int)
+extern unlink int (const char*)
+extern valloc void* (size_t)
+extern wcstombs size_t (char*, const wchar_t*, size_t)
+extern wctomb int (char*, wchar_t)
+extern write ssize_t (int, const void*, size_t)
+
+print #undef extern
+
+# <stdarg.h> is handled by proto so this must be after the last test
+
+print #include <stdarg.h>
diff --git a/src/lib/libast/features/syscall b/src/lib/libast/features/syscall
new file mode 100644
index 0000000..9788b9b
--- /dev/null
+++ b/src/lib/libast/features/syscall
@@ -0,0 +1,18 @@
+lib sysgetcwd note{ syscall(SYS_getcwd,buf,len) implemented }end link{
+ #include <sys/syscall.h>
+ int main()
+ {
+ char buf[256];
+ return syscall(SYS_getcwd, buf, sizeof(buf)) < 0;
+ }
+}end
+
+if ( _lib_sysgetcwd ) {
+ #include <sys/syscall.h>
+}
+endif
+
+if ( _lib_sysgetcwd ) {
+ #define SYSGETCWD(a,b) syscall(SYS_getcwd,a,b)
+}
+endif
diff --git a/src/lib/libast/features/time b/src/lib/libast/features/time
new file mode 100644
index 0000000..6c15113
--- /dev/null
+++ b/src/lib/libast/features/time
@@ -0,0 +1,46 @@
+set prototyped
+lib nanosleep,usleep,_strftime
+typ clock_t = uint32_t
+typ time_t = uint32_t
+
+if sys time {
+ #include <sys/time.h>
+}
+endif
+
+if ! mem tm.tm_sec sys/time.h
+ if hdr time {
+ #include <time.h>
+ }
+ endif
+endif
+
+if sys times {
+ #include <sys/times.h>
+}
+else {
+ struct tms
+ {
+ clock_t tms_utime;
+ clock_t tms_stime;
+ clock_t tms_cutime;
+ clock_t tms_cstime;
+ };
+ extern clock_t times(struct tms*);
+}
+endif
+
+if ! mem timeval.tv_sec sys/time.h {
+ struct timeval
+ {
+ time_t tv_sec;
+ time_t tv_usec;
+ };
+}
+endif
+
+cat{
+#if !defined(CLOCKS_PER_SEC) && defined(CLK_TCK)
+#define CLOCKS_PER_SEC CLK_TCK
+#endif
+}end
diff --git a/src/lib/libast/features/tmlib b/src/lib/libast/features/tmlib
new file mode 100644
index 0000000..221079c
--- /dev/null
+++ b/src/lib/libast/features/tmlib
@@ -0,0 +1,45 @@
+set prototyped
+
+_cc_export_dynamic = note{ probe CC.EXPORT.DYNAMIC supported }end run{
+ case `{ probe -l C make cc | grep '^CC.EXPORT.DYNAMIC = .'; } 2>/dev/null` in
+ '') exit 1 ;;
+ esac
+}end
+
+tst tzset_environ note{ tzset() bypasses user getenv() }end execute{
+ #if _UWIN || !_cc_export_dynamic
+ int main()
+ {
+ return 0;
+ }
+ #else
+ #include <time.h>
+ extern char** environ;
+ extern char* tzname[2];
+ #if _STD_
+ extern char* getenv(char* s)
+ #else
+ extern char* getenv(s)
+ char* s;
+ #endif
+ {
+ return "foo0bar";
+ }
+ int main()
+ {
+ tzset();
+ return tzname[0] && !strcmp(tzname[0], "foo") &&
+ tzname[1] && !strcmp(tzname[1], "bar");
+ }
+ #endif
+}end
+
+if ( _tzset_environ ) {
+ #define tmlocaltime(p) _tm_localtime(p)
+
+ extern struct tm* _tm_localtime(const time_t*);
+}
+else {
+ #define tmlocaltime(p) localtime(p)
+}
+endif
diff --git a/src/lib/libast/features/tmx b/src/lib/libast/features/tmx
new file mode 100644
index 0000000..ebf5c0f
--- /dev/null
+++ b/src/lib/libast/features/tmx
@@ -0,0 +1,106 @@
+set prototyped
+set explicit
+iff TMX
+
+cat{
+ /*
+ * AT&T Research
+ *
+ * high resolution Time_t support
+ */
+
+ #include <tm.h>
+ #include <tv.h>
+}end
+
+inc FEATURE/common
+
+if ( _ast_int8_t ) {
+ #define TMX_MAXDATE "2554-07-21+23:34:33.709551614 UTC"
+ #define TMX_MAXYEAR 2554
+ #define TMX_MAXSEC ((Time_t)18446744073)
+ #define TMX_MAXNSEC 709551614
+ #define TMX_RESOLUTION 1000000000
+
+ typedef uint64_t Time_t;
+ typedef uint64_t Tmxsec_t;
+ typedef uint32_t Tmxnsec_t;
+
+ #define tmxsec(t) ((Tmxsec_t)((t)/1000000000))
+ #define tmxnsec(t) ((Tmxnsec_t)((t)%1000000000))
+ #define tmxsns(s,n) (((((Time_t)(s))*1000000000))+((Time_t)(n)))
+}
+elif ( _ast_flt8_t ) {
+ #define TMX_FLOAT 1
+ #define TMX_MAXDATE "2106-02-07+06:28:15.999 UTC"
+ #define TMX_MAXYEAR 2106
+ #define TMX_MAXSEC 0xffffffffL
+ #define TMX_MAXNSEC 999000000L
+ #define TMX_RESOLUTION 1000
+
+ typedef _ast_flt8_t Time_t;
+ typedef uint32_t Tmxsec_t;
+ typedef uint32_t Tmxnsec_t;
+
+ #define tmxsec(t) ((Tmxsec_t)(t))
+ #define tmxnsec(t) (((Tmxnsec_t)(((t)-((uint32_t)(t))+0.0000005)*1000L))*1000000L)
+ #define tmxsns(s,n) (((Time_t)(s))+((((uint32_t)(n))/1000L)/1e6))
+}
+else {
+ #define TMX_MAXDATE "2106-02-07+06:28:14 UTC"
+ #define TMX_MAXYEAR 2106
+ #define TMX_MAXSEC 0xfffffffeL
+ #define TMX_MAXNSEC 0L
+ #define TMX_RESOLUTION 1
+
+ typedef uint32_t Time_t;
+ typedef uint32_t Tmxsec_t;
+ typedef uint32_t Tmxnsec_t;
+
+ #define tmxsec(t) ((Tmxsec_t)(t))
+ #define tmxnsec(t) (0)
+ #define tmxsns(s,n) ((Time_t)(s))
+}
+endif
+
+cat{
+ #define TMX_NOTIME ((Time_t)(-1))
+ #define TMX_NOW tmxgettime()
+ #define TMX_MAXTIME tmxsns(TMX_MAXSEC,TMX_MAXNSEC)
+
+ #define tmx2tv(t,v) ((v)->tv_nsec=tmxnsec(t),(v)->tv_sec=tmxsec(t))
+ #define tv2tmx(v) tmxsns((v)->tv_sec,(v)->tv_nsec)
+
+ #define tmxclock(p) tmxsns(((p)?*(p):time(NiL)),0)
+
+ #define tmxgetatime(s) tmxsns((s)->st_atime,ST_ATIME_NSEC_GET(s))
+ #define tmxgetctime(s) tmxsns((s)->st_ctime,ST_CTIME_NSEC_GET(s))
+ #define tmxgetmtime(s) tmxsns((s)->st_mtime,ST_MTIME_NSEC_GET(s))
+
+ #define tmxsetatime(s,t) ((s)->st_atime=tmxsec(t),ST_ATIME_NSEC_SET(s,tmxnsec(t)))
+ #define tmxsetctime(s,t) ((s)->st_ctime=tmxsec(t),ST_CTIME_NSEC_SET(s,tmxnsec(t)))
+ #define tmxsetmtime(s,t) ((s)->st_mtime=tmxsec(t),ST_MTIME_NSEC_SET(s,tmxnsec(t)))
+
+ #if _BLD_ast && defined(__EXPORT__)
+ #define extern __EXPORT__
+ #endif
+
+ extern Time_t tmxdate(const char*, char**, Time_t);
+ extern Time_t tmxduration(const char*, char**);
+ extern char* tmxfmt(char*, size_t, const char*, Time_t);
+ extern Time_t tmxleap(Time_t);
+ extern Tm_t* tmxmake(Time_t);
+ extern Time_t tmxscan(const char*, char**, const char*, char**, Time_t, long);
+ extern int tmxsleep(Time_t);
+ extern Time_t tmxtime(Tm_t*, int);
+ extern Tm_t* tmxtm(Tm_t*, Time_t, Tm_zone_t*);
+
+ extern Time_t tmxgettime(void);
+ extern int tmxsettime(Time_t);
+
+ extern int tmxtouch(const char*, Time_t, Time_t, Time_t, int);
+
+ extern char* fmttmx(const char*, Time_t);
+
+ #undef extern
+}end
diff --git a/src/lib/libast/features/tty b/src/lib/libast/features/tty
new file mode 100644
index 0000000..a75edeb
--- /dev/null
+++ b/src/lib/libast/features/tty
@@ -0,0 +1,127 @@
+hdr termios,termio,sgtty
+sys termios,termio,ioctl,bsdtty,nttyio,ttyio
+lib tcgetattr,tcgetpgrp termios.h
+mac _POSIX_VDISABLE termios.h
+mem termios.c_line termios.h
+
+cat{
+
+#ifdef _hdr_termios
+# if _mac__POSIX_VDISABLE
+# undef _POSIX_VDISABLE
+# endif
+# include <termios.h>
+#else
+# if defined(_sys_termios) && defined(_lib_tcgetattr)
+# include <sys/termios.h>
+# define _hdr_termios 1
+# else
+# undef _sys_termios
+# endif /* _sys_termios */
+#endif /* _hdr_termios */
+
+#ifdef _hdr_termios
+# undef _hdr_sgtty
+# undef tcgetattr
+# undef tcsetattr
+# undef tcgetpgrp
+# undef tcsetpgrp
+# undef cfgetospeed
+# ifndef TCSANOW
+# define TCSANOW TCSETS
+# define TCSADRAIN TCSETSW
+# define TCSAFLUSH TCSETSF
+# endif /* TCSANOW */
+ /* The following corrects bugs in some implementations */
+# if defined(TCSADFLUSH) && !defined(TCSAFLUSH)
+# define TCSAFLUSH TCSADFLUSH
+# endif /* TCSADFLUSH */
+# ifndef _lib_tcgetattr
+# undef tcgetattr
+# define tcgetattr(fd,tty) ioctl(fd, TCGETS, tty)
+# undef tcsetattr
+# define tcsetattr(fd,action,tty) ioctl(fd, action, tty)
+# undef cfgetospeed
+# define cfgetospeed(tp) ((tp)->c_cflag & CBAUD)
+# endif /* _lib_tcgetattr */
+# undef TIOCGETC
+#else
+# define cfgetospeed(tp) ((tp)->c_cflag & CBAUD)
+# define cfgetispeed(tp) ((tp)->c_cflag & CBAUD)
+# define cfsetispeed(tp,val) ((tp)->c_cflag &=~ CBAUD,(tp)->c_cflag|=(val))
+# define cfsetospeed(tp,val) ((tp)->c_cflag &=~ CBAUD,(tp)->c_cflag|=(val))
+# ifdef _hdr_termio
+# include <termio.h>
+# else
+# ifdef _sys_termio
+# include <sys/termio.h>
+# define _hdr_termio 1
+# endif /* _sys_termio */
+# endif /* _hdr_termio */
+# ifdef _hdr_termio
+# define termios termio
+# undef TIOCGETC
+# define tcgetattr(fd,tty) ioctl(fd, TCGETA, tty)
+# define tcsetattr(fd,action,tty) ioctl(fd, action, tty)
+
+# ifdef _sys_bsdtty
+# include <sys/bsdtty.h>
+# endif /* _sys_bsdtty */
+# else
+# ifdef _hdr_sgtty
+# include <sgtty.h>
+# ifndef LPENDIN
+# ifdef _sys_nttyio
+# include <sys/nttyio.h>
+# endif /* _sys_nttyio */
+# endif /* LPENDIN */
+# define termios sgttyb
+# ifdef TIOCSETN
+# undef TCSETAW
+# endif /* TIOCSETN */
+# ifdef TIOCGETP
+# define tcgetattr(fd,tty) ioctl(fd, TIOCGETP, tty)
+# define tcsetattr(fd,action,tty) ioctl(fd, action, tty)
+# else
+# define tcgetattr(fd,tty) gtty(fd, tty)
+# define tcsetattr(fd,action,tty) stty(fd, tty)
+# endif /* TIOCGETP */
+# else
+# ifdef _sys_ttyio
+# include <sys/ttyio.h>
+# endif
+# endif /* _hdr_sgtty */
+# endif /* hdr_termio */
+
+# ifndef TCSANOW
+# ifdef TCSETAW
+# define TCSANOW TCSETA
+# define TCSAFLUSH TCSETAF
+# else
+# ifdef TIOCSETN
+# define TCSANOW TIOCSETN
+# define TCSADRAIN TIOCSETN
+# define TCSAFLUSH TIOCSETP
+# endif /* TIOCSETN */
+# endif /* TCSETAW */
+# endif /* TCSANOW */
+#endif /* _hdr_termios */
+
+/* set ECHOCTL if driver can echo control charaters as ^c */
+#ifdef LCTLECH
+# ifndef ECHOCTL
+# define ECHOCTL LCTLECH
+# endif /* !ECHOCTL */
+#endif /* LCTLECH */
+#ifdef LNEW_CTLECH
+# ifndef ECHOCTL
+# define ECHOCTL LNEW_CTLECH
+# endif /* !ECHOCTL */
+#endif /* LNEW_CTLECH */
+#ifdef LNEW_PENDIN
+# ifndef PENDIN
+# define PENDIN LNEW_PENDIN
+# endif /* !PENDIN */
+#endif /* LNEW_PENDIN */
+
+}end
diff --git a/src/lib/libast/features/tv b/src/lib/libast/features/tv
new file mode 100644
index 0000000..ae15682
--- /dev/null
+++ b/src/lib/libast/features/tv
@@ -0,0 +1,81 @@
+set prototyped
+set explicit
+iff TV
+
+cat{
+ /*
+ * AT&T Research
+ *
+ * high resolution Tv_t interface definitions
+ */
+
+ #include <ast.h>
+
+ #define TV_NSEC_IGNORE (1000000000L)
+ #define TV_TOUCH_RETAIN ((Tv_t*)1)
+
+ typedef struct Tv_s
+ {
+ uint32_t tv_sec;
+ uint32_t tv_nsec;
+ } Tv_t;
+}end
+
+if mem stat.st_mtimespec.tv_nsec sys/stat.h {
+ #define ST_ATIME_NSEC_GET(st) ((st)->st_atimespec.tv_nsec)
+ #define ST_CTIME_NSEC_GET(st) ((st)->st_ctimespec.tv_nsec)
+ #define ST_MTIME_NSEC_GET(st) ((st)->st_mtimespec.tv_nsec)
+}
+elif mem stat.st_mtim.st__tim.tv_nsec sys/stat.h {
+ #define ST_ATIME_NSEC_GET(st) ((st)->st_atim.st__tim.tv_nsec)
+ #define ST_CTIME_NSEC_GET(st) ((st)->st_ctim.st__tim.tv_nsec)
+ #define ST_MTIME_NSEC_GET(st) ((st)->st_mtim.st__tim.tv_nsec)
+}
+elif mem stat.st_mtim.tv_nsec sys/stat.h {
+ #define ST_ATIME_NSEC_GET(st) ((st)->st_atim.tv_nsec)
+ #define ST_CTIME_NSEC_GET(st) ((st)->st_ctim.tv_nsec)
+ #define ST_MTIME_NSEC_GET(st) ((st)->st_mtim.tv_nsec)
+}
+elif mem stat.st_mtimensec sys/stat.h {
+ #define ST_ATIME_NSEC_GET(st) ((st)->st_atimensec)
+ #define ST_CTIME_NSEC_GET(st) ((st)->st_ctimensec)
+ #define ST_MTIME_NSEC_GET(st) ((st)->st_mtimensec)
+}
+else pass{ no_stat_nsec=1 }end {
+ #define ST_ATIME_NSEC_GET(st) 0
+ #define ST_CTIME_NSEC_GET(st) 0
+ #define ST_MTIME_NSEC_GET(st) 0
+
+ #define ST_ATIME_NSEC_SET(st,n) 0
+ #define ST_CTIME_NSEC_SET(st,n) 0
+ #define ST_MTIME_NSEC_SET(st,n) 0
+}
+endif
+if ( !no_stat_nsec ) {
+ #define ST_ATIME_NSEC_SET(st,n) (ST_ATIME_NSEC_GET(st)=(n))
+ #define ST_CTIME_NSEC_SET(st,n) (ST_CTIME_NSEC_GET(st)=(n))
+ #define ST_MTIME_NSEC_SET(st,n) (ST_MTIME_NSEC_GET(st)=(n))
+}
+endif
+
+cat{
+ #define tvgetatime(t,s) ((t)->tv_nsec=ST_ATIME_NSEC_GET(s),(t)->tv_sec=(s)->st_atime)
+ #define tvgetmtime(t,s) ((t)->tv_nsec=ST_MTIME_NSEC_GET(s),(t)->tv_sec=(s)->st_mtime)
+ #define tvgetctime(t,s) ((t)->tv_nsec=ST_CTIME_NSEC_GET(s),(t)->tv_sec=(s)->st_ctime)
+
+ #define tvsetatime(t,s) (ST_ATIME_NSEC_SET(s,(t)->tv_nsec),(s)->st_atime=(t)->tv_sec)
+ #define tvsetmtime(t,s) (ST_MTIME_NSEC_SET(s,(t)->tv_nsec),(s)->st_mtime=(t)->tv_sec)
+ #define tvsetctime(t,s) (ST_CTIME_NSEC_SET(s,(t)->tv_nsec),(s)->st_ctime=(t)->tv_sec)
+
+ #if _BLD_ast && defined(__EXPORT__)
+ #define extern __EXPORT__
+ #endif
+
+ extern int tvgettime(Tv_t*);
+ extern int tvsettime(const Tv_t*);
+ extern int tvcmp(const Tv_t*, const Tv_t*);
+ extern int tvtouch(const char*, const Tv_t*, const Tv_t*, const Tv_t*, int);
+ extern int tvsleep(const Tv_t*, Tv_t*);
+
+ extern char* fmttv(const char*, Tv_t*);
+}end
diff --git a/src/lib/libast/features/tvlib b/src/lib/libast/features/tvlib
new file mode 100644
index 0000000..9b2f64f
--- /dev/null
+++ b/src/lib/libast/features/tvlib
@@ -0,0 +1,80 @@
+hdr time
+lib clock_settime,gettimeofday,settimeofday,stime,utimes
+lib nanosleep,usleep
+lib utimensat -D_ATFILE_SOURCE sys/stat.h note{ complete utimensat implementation }end link{
+ #include <fcntl.h>
+ static struct timespec ts[2];
+ int
+ main()
+ {
+ ts[0].tv_nsec = UTIME_NOW;
+ ts[1].tv_nsec = UTIME_OMIT;
+ return utimensat(AT_FDCWD, ".", ts, AT_SYMLINK_NOFOLLOW) != 0;
+ }
+}end
+
+if ! mem timeval.tv_sec sys/time.h {
+ struct timeval
+ {
+ time_t tv_sec;
+ time_t tv_usec;
+ };
+}
+endif
+
+lib clock_gettime execute{
+ #include <time.h>
+ int
+ main()
+ {
+ struct timespec tv;
+ return clock_gettime(CLOCK_REALTIME, &tv) != 0;
+ }
+}end
+
+lib utimets link{
+ #include <time.h>
+ #include <sys/time.h>
+ static struct timespec tv;
+ int
+ main()
+ {
+ return utimets(".", &tv) != 0;
+ }
+}end
+
+tst - -DN=1 - -DN=2 - -DN=3 - -DN=4 output{
+ #include <sys/types.h>
+ #include <sys/time.h>
+ int
+ main()
+ {
+ struct timeval tv;
+#if N == 1
+ struct timezone tz;
+ if (gettimeofday(&tv, (struct timezone*)0) < 0)
+ return 1;
+ printf("#define tmgettimeofday(p) gettimeofday(p,(struct timezone*)0)\n");
+#if _lib_settimeofday
+ printf("#define tmsettimeofday(p) settimeofday(p,(struct timezone*)0)\n");
+#endif
+#endif
+#if N == 2
+ if (gettimeofday(&tv, (void*)0) < 0)
+ return 1;
+ printf("#define tmgettimeofday(p) gettimeofday(p,(void*)0)\n");
+#if _lib_settimeofday
+ printf("#define tmsettimeofday(p) gettimeofday(p,(void*)0)\n");
+#endif
+#endif
+#if N == 3
+ if (gettimeofday(&tv) < 0)
+ return 1;
+ printf("#define tmgettimeofday(p) gettimeofday(p)\n");
+#if _lib_settimeofday
+ printf("#define tmsettimeofday(p) settimeofday(p)\n");
+#endif
+#endif
+ return 0;
+ }
+}end
diff --git a/src/lib/libast/features/uwin b/src/lib/libast/features/uwin
new file mode 100644
index 0000000..b42cea1
--- /dev/null
+++ b/src/lib/libast/features/uwin
@@ -0,0 +1,10 @@
+lib a64l,acosh,asinh,atanh,cbrt,ceil,crypt,erf,exp,expm1,floor
+lib gamma,getpass,lgamma,log,log1p,random,rcmd,rint,srand48
+lib copysign,logb,finite,drem,sqrt,ilogb,remainder,scalb
+lib _copysign,_finite,_scalb,__iob_func,_p__iob,__p__iob
+
+dat _iob
+
+cat{
+ #define stricmp strcasecmp
+}end
diff --git a/src/lib/libast/features/vfork b/src/lib/libast/features/vfork
new file mode 100644
index 0000000..f1a0ea7
--- /dev/null
+++ b/src/lib/libast/features/vfork
@@ -0,0 +1,13 @@
+set prototyped
+hdr vfork
+sys vfork
+
+tst run{
+ if test "$_hdr_vfork" = 1
+ then echo "#include <vfork.h>"
+ elif test "$_sys_vfork" = 1
+ then echo "#include <sys/vfork.h>"
+ else echo '#include <unistd.h>' > $tmp.c
+ $cc -E $tmp.c | grep vfork
+ fi
+}end
diff --git a/src/lib/libast/features/vmalloc b/src/lib/libast/features/vmalloc
new file mode 100644
index 0000000..b3cc2d0
--- /dev/null
+++ b/src/lib/libast/features/vmalloc
@@ -0,0 +1,220 @@
+#
+# This file defines probes for local features that vmalloc requires.
+# Such probes are interpreted by the "iffe" language interpreter.
+# Results are stored in the FEATURE directory. Some of the
+# {lib,hdr,sys,typ} tests may also be done in the AST features/lib;
+# repeating them here allows for single standalone and AST sources.
+#
+
+ref -D_def_map_ast=1
+
+lib atexit,getpagesize,mallinfo,mallopt,memalign,mstats
+lib onexit,pvalloc,strdup,valloc,vmalloc
+lib _malloc,__malloc,__libc_malloc
+hdr alloca,malloc,stat,stdlib,unistd
+mem mallinfo.arena,mstats.bytes_total malloc.h
+sys stat
+typ ssize_t
+
+tst mem_sbrk note{ brk()/sbrk() work as expected }end execute{
+ #include <sys/types.h>
+ #include <unistd.h>
+ #undef uchar
+ #define uchar unsigned char
+ int main()
+ { uchar *brk0, *brk1;
+
+ /* allocate a big chunk */
+ if(!(brk0 = (uchar*)sbrk(0)) || brk0 == (uchar*)(-1))
+ return 1;
+ brk0 += 256*1024;
+ if(brk(brk0) != 0)
+ return 1;
+ if((brk1 = (uchar*)sbrk(0)) != brk0)
+ return 1;
+
+ /* now return half of it */
+ brk1 -= 128*1024;
+ if(brk(brk1) != 0 )
+ return 1;
+ if((brk0 = (uchar*)sbrk(0)) != brk1)
+ return 1;
+
+ return 0;
+ }
+}end
+
+tst map_malloc note{ map malloc to _ast_malloc }end noexecute{
+ #if __CYGWIN__
+ int main() { return 1; }
+ #else
+ static int user = 0;
+ _BEGIN_EXTERNS_
+ #if _lib_strdup
+ extern char* strdup _ARG_((const char*));
+ #define LOCAL() strdup("s")
+ #else
+ extern void* calloc _ARG_((unsigned int, unsigned int));
+ #define LOCAL() calloc(1,1)
+ #endif
+ #if __CYGWIN__
+ #define extern __declspec(dllexport)
+ #endif
+ #define HT double
+ static HT heap[1024 * 4];
+ static HT* hp = &heap[1];
+ static HT* op;
+ #define MALLOC(n) if(user)return&heap[0];op=hp;hp+=(n+sizeof(HT)-1)/sizeof(HT);return(void*)op;
+ #define INTERCEPTED(p) (((char*)(p))==((char*)&heap[0]))
+ #if _STD_
+ extern void free(void* p) { }
+ extern void _free(void* p) { }
+ extern void __free(void* p) { }
+ extern void __libc_free(void* p) { }
+ extern void* malloc(unsigned int n) { MALLOC(n); }
+ extern void* _malloc(unsigned int n) { MALLOC(n); }
+ extern void* __malloc(unsigned int n) { MALLOC(n); }
+ extern void* __libc_malloc(unsigned int n) { MALLOC(n); }
+ #else
+ extern void free(p) char* p; { }
+ extern void _free(p) char* p; { }
+ extern void __free(p) char* p; { }
+ extern void __libc_free(p) char* p; { }
+ extern void* malloc(n) unsigned int n; { MALLOC(n); }
+ extern void* _malloc(n) unsigned int n; { MALLOC(n); }
+ extern void* __malloc(n) unsigned int n; { MALLOC(n); }
+ extern void* __libc_malloc(n) unsigned int n; { MALLOC(n); }
+ #endif
+ _END_EXTERNS_
+ int main() { user = 1; return !INTERCEPTED(LOCAL()); }
+ #endif
+}end
+
+tst map_malloc note{ map malloc to _ast_malloc -- wimp-o mach? }end noexecute{
+ #if _map_malloc
+ int main() { return 0; }
+ #else
+ _BEGIN_EXTERNS_
+ #if _STD_
+ void* calloc(unsigned n, unsigned m) { exit(1); }
+ #else
+ void* calloc(n, m) unsigned n, m; { exit(1); }
+ #endif
+ _END_EXTERNS_
+ int main() { return 0; }
+ #endif
+}end
+
+lib alloca note{ alloca exists }end link{
+ #if _hdr_alloca
+ #include <alloca.h>
+ #endif
+ int
+ main()
+ { alloca(10);
+ }
+}end
+
+tst mal_alloca note{ alloca is based on malloc() }end execute{
+ #if __CYGWIN__
+ int main() { return 1; }
+ #else
+ #if _hdr_alloca
+ #include <alloca.h>
+ #endif
+ #if _STD_
+ void* malloc(unsigned int size)
+ #else
+ void* malloc(size) unsigned int size;
+ #endif
+ { exit(0);
+ return 0;
+ }
+ int main()
+ { alloca(10);
+ return 1;
+ }
+ #endif
+}end
+
+tst stk_down note{ stack grows downward }end execute{
+ static growdown()
+ { static char* addr = 0;
+ char array[4];
+ if(!addr)
+ { addr = &array[0];
+ return growdown();
+ }
+ else if(addr < &array[0])
+ return 0;
+ else return 1;
+ }
+ int main() { return growdown() ? 0 : 1; }
+}end
+
+tst malloc_hook note{ gnu malloc hooks work }end execute{
+ #include <malloc.h>
+
+ static int test_free_hit = 0;
+ static int test_malloc_hit = 0;
+ static int test_memalign_hit = 0;
+ static int test_realloc_hit = 0;
+
+ static void test_free_hook(void* ptr, const void* caller)
+ {
+ test_free_hit++;
+ }
+
+ static void* test_malloc_hook(size_t size, const void* caller)
+ {
+ test_malloc_hit++;
+ return 0;
+ }
+
+ static void* test_memalign_hook(size_t align, size_t size, const void* caller)
+ {
+ test_memalign_hit++;
+ return 0;
+ }
+
+ static void* test_realloc_hook(void* ptr, size_t size, const void* caller)
+ {
+ test_realloc_hit++;
+ return 0;
+ }
+
+ static void test_initialize_hook(void)
+ {
+ __free_hook = test_free_hook;
+ __malloc_hook = test_malloc_hook;
+ __memalign_hook = test_memalign_hook;
+ __realloc_hook = test_realloc_hook;
+ }
+
+ void (*__malloc_initialize_hook)(void) = test_initialize_hook;
+
+ int main()
+ {
+ void* p;
+
+ p = malloc(16);
+ p = realloc(p, 32);
+ free(p);
+ p = memalign(32, 32);
+ return !test_free_hit || !test_malloc_hit || !test_memalign_hit || !test_realloc_hit;
+ }
+}end
+
+cat{
+ #include "FEATURE/mmap"
+ #if _BLD_INSTRUMENT || cray || _UWIN && _BLD_ast
+ #undef _map_malloc
+ #define _std_malloc 1 /* defer to standard malloc */
+ #endif
+ #if _mmap_anon
+ #define _mem_mmap_anon 1
+ #endif
+ #if _mmap_devzero
+ #define _mem_mmap_zero 1
+ #endif
+}end
diff --git a/src/lib/libast/features/wait b/src/lib/libast/features/wait
new file mode 100644
index 0000000..74c8c81
--- /dev/null
+++ b/src/lib/libast/features/wait
@@ -0,0 +1,9 @@
+lib wait,wait2,wait3,wait4,waitpid
+tst ok_wif sys/types.h sys/wait.h note{ posix wait macros ok }end compile{
+ int ifexited = WIFEXITED(0);
+ int exitstatus = WEXITSTATUS(0);
+ int ifsignaled = WIFSIGNALED(0);
+ int termsig = WTERMSIG(0);
+ int ifstopped = WIFSTOPPED(0);
+ int stopsig = WSTOPSIG(0);
+}end
diff --git a/src/lib/libast/features/wchar b/src/lib/libast/features/wchar
new file mode 100644
index 0000000..ac51f0f
--- /dev/null
+++ b/src/lib/libast/features/wchar
@@ -0,0 +1,158 @@
+set prototyped
+iff
+set stdio ast_common.h
+set include .
+
+cat{
+ #ifndef _AST_WCHAR_H
+ #define _AST_WCHAR_H 1
+}end
+
+lib mbstowcs,wctomb,wcrtomb,wcslen,wcstombs,wcwidth stdlib.h stdio.h wchar.h
+lib towlower,towupper stdlib.h stdio.h wchar.h
+typ mbstate_t stdlib.h stdio.h wchar.h
+nxt wchar
+
+cat{
+ #ifndef _SFSTDIO_H
+ #include <ast_common.h>
+ #include <stdio.h>
+ #endif
+}end
+
+if tst note{ <wchar.h> requires native <stdio.h> }end nocompile{
+ /*<NOSTDIO>*/
+ #define _STDIO_INCLUDED 1
+ #define FILE void
+ #include <wchar.h>
+ int tst;
+ }end
+ if tst note{ <stdio.h> defines __va_list for <wchar.h> }end compile{
+ /*<NOSTDIO>*/
+ #define _STDIO_INCLUDED 1
+ #define FILE void
+ #include <stdarg.h>
+ #define __va_list va_list
+ #include <wchar.h>
+ int tst;
+ }end && {
+ #define __va_list va_list
+ }
+ endif
+endif
+
+if hdr - wctype wchar.h
+ if ! npt - iswalpha wchar.h {
+ #include <wctype.h> /* <wchar.h> includes <wctype.h> */
+ }
+ endif
+endif
+
+run{
+cat <<!
+ #if _hdr_wchar && defined(_nxt_wchar)
+ #include ${_nxt_wchar-_nxt_wchar} /* the native wchar.h */
+ #endif
+
+ #ifndef WEOF
+ #define WEOF (-1)
+ #endif
+
+ #undef fgetwc
+ #undef fgetws
+ #undef fputwc
+ #undef fputws
+ #undef getwc
+ #undef getwchar
+ #undef getws
+ #undef putwc
+ #undef putwchar
+ #undef ungetwc
+
+ #define fgetwc _ast_fgetwc
+ #define fgetws _ast_fgetws
+ #define fputwc _ast_fputwc
+ #define fputws _ast_fputws
+ #define fwide _ast_fwide
+ #define fwprintf _ast_fwprintf
+ #define fwscanf _ast_fwscanf
+ #define getwc _ast_getwc
+ #define getwchar _ast_getwchar
+ #define getws _ast_getws
+ #define putwc _ast_putwc
+ #define putwchar _ast_putwchar
+ #define swprintf _ast_swprintf
+ #define swscanf _ast_swscanf
+ #define ungetwc _ast_ungetwc
+ #define vfwprintf _ast_vfwprintf
+ #define vfwscanf _ast_vfwscanf
+ #define vswprintf _ast_vswprintf
+ #define vswscanf _ast_vswscanf
+ #define vwprintf _ast_vwprintf
+ #define vwscanf _ast_vwscanf
+ #define wprintf _ast_wprintf
+ #define wscanf _ast_wscanf
+
+ #if !_typ_mbstate_t
+ #undef _typ_mbstate_t
+ #define _typ_mbstate_t 1
+ typedef char mbstate_t;
+ #endif
+
+ #if _BLD_ast && defined(__EXPORT__)
+ #define extern __EXPORT__
+ #endif
+
+ #if !_lib_mbstowcs
+ extern size_t mbstowcs(wchar_t*, const char*, size_t);
+ #endif
+ #if !_lib_wctomb
+ extern int wctomb(char*, wchar_t);
+ #endif
+ #if !_lib_wcrtomb
+ extern size_t wcrtomb(char*, wchar_t, mbstate_t*);
+ #endif
+ #if !_lib_wcslen
+ extern size_t wcslen(const wchar_t*);
+ #endif
+ #if !_lib_wcstombs
+ extern size_t wcstombs(char*, const wchar_t*, size_t);
+ #endif
+
+ extern int fwprintf(FILE*, const wchar_t*, ...);
+ extern int fwscanf(FILE*, const wchar_t*, ...);
+ extern wint_t fgetwc(FILE*);
+ extern wchar_t* fgetws(wchar_t*, int, FILE*);
+ extern wint_t fputwc(wchar_t, FILE*);
+ extern int fputws(const wchar_t*, FILE*);
+ extern int fwide(FILE*, int);
+ extern wint_t getwc(FILE*);
+ extern wint_t getwchar(void);
+ extern wchar_t* getws(wchar_t*);
+ extern wint_t putwc(wchar_t, FILE*);
+ extern wint_t putwchar(wchar_t);
+ extern int swprintf(wchar_t*, size_t, const wchar_t*, ...);
+ extern int swscanf(const wchar_t*, const wchar_t*, ...);
+ extern wint_t ungetwc(wint_t, FILE*);
+ extern int vfwprintf(FILE*, const wchar_t*, va_list);
+ extern int vfwscanf(FILE*, const wchar_t*, va_list);
+ extern int vwprintf(const wchar_t*, va_list);
+ extern int vwscanf(const wchar_t*, va_list);
+ extern int vswprintf(wchar_t*, size_t, const wchar_t*, va_list);
+ extern int vswscanf(const wchar_t*, const wchar_t*, va_list);
+ extern int wprintf(const wchar_t*, ...);
+ extern int wscanf(const wchar_t*, ...);
+
+ #undef extern
+
+ #else
+
+ /* on some systems <wchar.h> is included multiple times with multiple effects */
+
+ #if _hdr_wchar && defined(_nxt_wchar)
+ #include ${_nxt_wchar-_nxt_wchar} /* the native wchar.h */
+ #endif
+
+ #endif
+!
+}end
diff --git a/src/lib/libast/features/wctype b/src/lib/libast/features/wctype
new file mode 100644
index 0000000..0f59bc1
--- /dev/null
+++ b/src/lib/libast/features/wctype
@@ -0,0 +1,14 @@
+set prototyped
+nxt wctype
+
+run{
+cat <<!
+ #if _hdr_wctype && defined(_nxt_wctype)
+ #include ${_nxt_wctype-_nxt_wctype} /* the native wctype.h */
+ #endif
+
+ #undef iswalpha
+
+ #define iswalpha(w) (ast.mb_alpha?(*ast.mb_alpha)(w):isalpha(w))
+!
+}end