xref: /titanic_50/usr/src/lib/libast/common/features/sfio (revision da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968)
1*da2e3ebdSchinref	-D_def_map_ast=1
2*da2e3ebdSchinhdr	float,floatingpoint,math,values
3*da2e3ebdSchinsys	filio,ioctl
4*da2e3ebdSchinlib	qfrexp,qldexp
5*da2e3ebdSchinkey	signed
6*da2e3ebdSchin
7*da2e3ebdSchintst	tmp_rmfail note{ open files cannot be removed }end execute{
8*da2e3ebdSchin	#include <string.h>
9*da2e3ebdSchin	#include <time.h>
10*da2e3ebdSchin	int
11*da2e3ebdSchin	main()
12*da2e3ebdSchin	{
13*da2e3ebdSchin	#if !_UWIN
14*da2e3ebdSchin		int		n;
15*da2e3ebdSchin		char*		s;
16*da2e3ebdSchin		FILE*		fr;
17*da2e3ebdSchin		FILE*		fw;
18*da2e3ebdSchin		char		file[16];
19*da2e3ebdSchin		static char	data[] = "0123456789";
20*da2e3ebdSchin		s = file;
21*da2e3ebdSchin		*s++ = '1';
22*da2e3ebdSchin		*s++ = 'F';
23*da2e3ebdSchin		*s++ = 'F';
24*da2e3ebdSchin		*s++ = '3';
25*da2e3ebdSchin		n = (int)time(0);
26*da2e3ebdSchin		*s++ = (n & 0xF) + 'A';
27*da2e3ebdSchin		*s++ = ((n >> 4) & 0xF) + 'A';
28*da2e3ebdSchin		*s++ = ((n >> 8) & 0xF) + 'A';
29*da2e3ebdSchin		*s++ = ((n >> 12) & 0xF) + 'A';
30*da2e3ebdSchin		*s++ = '.';
31*da2e3ebdSchin		*s++ = 'T';
32*da2e3ebdSchin		*s++ = 'M';
33*da2e3ebdSchin		*s++ = 'P';
34*da2e3ebdSchin		*s = 0;
35*da2e3ebdSchin		remove(file);
36*da2e3ebdSchin		if (!(fw = fopen(file, "w")))
37*da2e3ebdSchin			return 0;
38*da2e3ebdSchin		if (!(fr = fopen(file, "r")))
39*da2e3ebdSchin		{
40*da2e3ebdSchin			fclose(fw);
41*da2e3ebdSchin			remove(file);
42*da2e3ebdSchin			return 0;
43*da2e3ebdSchin		}
44*da2e3ebdSchin		if (remove(file) < 0)
45*da2e3ebdSchin		{
46*da2e3ebdSchin			fclose(fr);
47*da2e3ebdSchin			fclose(fw);
48*da2e3ebdSchin			remove(file);
49*da2e3ebdSchin			return 0;
50*da2e3ebdSchin		}
51*da2e3ebdSchin		if (fwrite(data, sizeof(data), 1, fw) != 1)
52*da2e3ebdSchin			return 0;
53*da2e3ebdSchin		fclose(fw);
54*da2e3ebdSchin		if (fread(file, sizeof(data), 1, fr) != 1)
55*da2e3ebdSchin			return 0;
56*da2e3ebdSchin		fclose(fr);
57*da2e3ebdSchin		if (strcmp(file, data) != 0)
58*da2e3ebdSchin			return 0;
59*da2e3ebdSchin	#endif
60*da2e3ebdSchin		return 1;
61*da2e3ebdSchin	}
62*da2e3ebdSchin}end
63*da2e3ebdSchin
64*da2e3ebdSchinmore void_int note{ voidptr is larger than int }end execute{
65*da2e3ebdSchin	int
66*da2e3ebdSchin	main()
67*da2e3ebdSchin	{
68*da2e3ebdSchin		return sizeof(char*) > sizeof(int) ? 0 : 1;
69*da2e3ebdSchin	}
70*da2e3ebdSchin}end
71*da2e3ebdSchin
72*da2e3ebdSchinmore long_int note{ long is larger than int }end execute{
73*da2e3ebdSchin	int
74*da2e3ebdSchin	main()
75*da2e3ebdSchin	{
76*da2e3ebdSchin		return sizeof(long) > sizeof(int) ? 0 : 1;
77*da2e3ebdSchin	}
78*da2e3ebdSchin}end
79*da2e3ebdSchin
80*da2e3ebdSchintst	vax_asm note{ register layout ok for vax string operations }end execute{
81*da2e3ebdSchin	int
82*da2e3ebdSchin	main()
83*da2e3ebdSchin	{
84*da2e3ebdSchin	#ifndef vax
85*da2e3ebdSchin		return absurd = -1;
86*da2e3ebdSchin	#else
87*da2e3ebdSchin		register int	r11, r10, r9, r8, r7, r6;
88*da2e3ebdSchin		r11 = r10 = r9 = r8 = r7 = r6 = -1;
89*da2e3ebdSchin		asm("clrw	r11");
90*da2e3ebdSchin		asm("clrw	r10");
91*da2e3ebdSchin		asm("clrw	r9");
92*da2e3ebdSchin		asm("clrw	r8");
93*da2e3ebdSchin		asm("clrw	r7");
94*da2e3ebdSchin		asm("clrw	r6");
95*da2e3ebdSchin		if(sizeof(int) != sizeof(char*) || r11 || r10 || r9 || r8 || r7 || r6 )
96*da2e3ebdSchin			return -1;
97*da2e3ebdSchin		return 0;
98*da2e3ebdSchin	#endif
99*da2e3ebdSchin	}
100*da2e3ebdSchin}end
101*da2e3ebdSchin
102*da2e3ebdSchintst	lib_cvt note{ native floating point conversions ok }end link{
103*da2e3ebdSchin	_BEGIN_EXTERNS_
104*da2e3ebdSchin	extern char* ecvt _ARG_((double, int, int*, int*));
105*da2e3ebdSchin	extern char* fcvt _ARG_((double, int, int*, int*));
106*da2e3ebdSchin	extern double strtod _ARG_((const char*, char**));
107*da2e3ebdSchin	_END_EXTERNS_
108*da2e3ebdSchin	int
109*da2e3ebdSchin	main()
110*da2e3ebdSchin	{
111*da2e3ebdSchin		ecvt(0.0, 0, 0, 0);
112*da2e3ebdSchin		fcvt(0.0, 0, 0, 0);
113*da2e3ebdSchin		strtod(0, 0);
114*da2e3ebdSchin		return 0;
115*da2e3ebdSchin	}
116*da2e3ebdSchin}end
117*da2e3ebdSchin
118*da2e3ebdSchintst	xopen_stdio note{ Stdio fseek/fflush are X/Open-compliant }end execute{
119*da2e3ebdSchin	#define Failed(file)	(unlink(file),1)
120*da2e3ebdSchin	int
121*da2e3ebdSchin	main(argc, argv)
122*da2e3ebdSchin	int	argc;
123*da2e3ebdSchin	char**	argv;
124*da2e3ebdSchin	{	FILE	*f1, *f2;
125*da2e3ebdSchin		char	file[1024], buf[1024], *f, *t;
126*da2e3ebdSchin		int	i, fd;
127*da2e3ebdSchin
128*da2e3ebdSchin		/* create file */
129*da2e3ebdSchin		for(f = argv[0], t = file; (*t = *f++) != 0; )
130*da2e3ebdSchin			t++;
131*da2e3ebdSchin		*t++ = '.'; *t++ = 'D'; *t++ = 0;
132*da2e3ebdSchin		if((fd = creat(file,0666)) < 0)
133*da2e3ebdSchin			return 1;
134*da2e3ebdSchin
135*da2e3ebdSchin		for (i = 0; i < sizeof(buf); ++i)
136*da2e3ebdSchin			buf[i] = '0' + (i%10);
137*da2e3ebdSchin		for (i = 0; i < 16; ++i)
138*da2e3ebdSchin			if (write(fd,buf,sizeof(buf)) != sizeof(buf))
139*da2e3ebdSchin				return Failed(file);
140*da2e3ebdSchin		close(fd);
141*da2e3ebdSchin
142*da2e3ebdSchin		if(!(f1 = fopen(file,"r+")) ||
143*da2e3ebdSchin		   (fd = dup(fileno(f1))) < 0 ||
144*da2e3ebdSchin		   !(f2 = fdopen(fd,"r+")) )
145*da2e3ebdSchin			return Failed(file);
146*da2e3ebdSchin
147*da2e3ebdSchin		if(fread(buf, 1, 7, f2) != 7 || ftell(f2) != 7)
148*da2e3ebdSchin			return Failed(file);
149*da2e3ebdSchin
150*da2e3ebdSchin		if(fseek(f1, 1010, 0) < 0 || ftell(f1) != 1010)
151*da2e3ebdSchin			return Failed(file);
152*da2e3ebdSchin
153*da2e3ebdSchin		fflush(f2); /* this should set the seek location to 1010 */
154*da2e3ebdSchin		if(ftell(f2) != 1010)
155*da2e3ebdSchin			return Failed(file);
156*da2e3ebdSchin
157*da2e3ebdSchin		unlink(file);
158*da2e3ebdSchin		return 0;
159*da2e3ebdSchin	}
160*da2e3ebdSchin}end
161