ref	-D_def_map_ast=1
hdr	float,floatingpoint,math,values
sys	filio,ioctl
lib	qfrexp,qldexp
key	signed

typ	struct.sf_hdtr sys/socket.h

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 fail{
	echo '#error The output block in src/lib/libast/features/sfio failed to compile. Rebuild with IFFEFLAGS=-d1 to debug.'
}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
