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