summaryrefslogtreecommitdiff
path: root/src/lib/libast/features/sfio
blob: 901935a97455f94bcc2a0dba2614622ce3fbaa19 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
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