OpenIndiana and Solaris port
[oweals/cde.git] / cde / programs / dtksh / ksh93 / src / lib / libast / features / lib
1 cmd     universe
2 hdr     dirent,filio,jioctl,locale,mman,ndir,utime,vfork,wchar
3 dat     _tzname,tzname
4 lib     _cleanup,BSDsetpgrp,atexit,bcopy,bzero,confstr,dirread,dup2,fchmod
5 lib     fcntl,fnmatch,fork,fsync,getconf,getdents,getdirentries,getdtablesize
6 lib     getgroups,getpagesize,getrlimit,getuniverse,index,killpg,link
7 lib     localeconv,lstat,mbtowc,memccpy
8 lib     memchr,memcmp,memcpy,memmove,memset,mkdir,mkfifo,mknod,mktemp
9 lib     mount,on_exit,onexit,opendir,pathconf,readlink,remove,rename,rindex
10 lib     rmdir,rewinddir,setlocale,setpgid,setpgrp,setpgrp2,setreuid,setsid
11 lib     setuid,sigaction,sigprocmask,sigsetmask,sigvec
12 lib     socketpair,spawnve,spawnveg,strchr,strcoll,strdup,strerror,strrchr
13 lib     strtod,strtol,strtoul,strxfrm,symlink,sysconf
14 lib     telldir,tmpnam,tzset,universe,unlink,utime,vfork
15 lib     wctype,iswblank,iswctype
16 lib     execve,pcreateve,NutForkExecve
17 mem     direct.d_reclen sys/types.h sys/dir.h
18 mem     dirent.d_fileno,dirent.d_ino,dirent.d_namlen,dirent.d_off,dirent.d_reclen sys/types.h dirent.h
19 mem     DIR.dd_fd sys/types.h - dirent.h - sys/dir.h
20 sys     dir,filio,jioctl,localedef,mman,ptem,resource,socket,stream,universe
21 sys     vfork
22
23 tst     tst_errno note{ errno can be assigned }end link{
24         _BEGIN_EXTERNS_
25         extern int errno;
26         error() { }
27         strerror() { }
28         _END_EXTERNS_
29         main() { errno = 0; error(); strerror(); }
30 }end
31
32 tst     lib_poll_fd_1 note{ fd is first arg to poll() }end execute{
33         #include <poll.h>
34         _BEGIN_EXTERNS_
35         extern int      pipe _ARG_((int*));
36         _END_EXTERNS_
37         main()
38         {       int             rw[2];
39                 struct pollfd   fd;
40                 if (pipe(rw) < 0) return 1;
41                 fd.fd = rw[0];
42                 fd.events = POLLIN;
43                 fd.revents = 0;
44                 return poll(&fd, 1, 0) < 0;
45         }
46 }end
47
48 tst     lib_poll_fd_2 note{ fd is second arg to poll() }end execute{
49         #include <poll.h>
50         _BEGIN_EXTERNS_
51         extern int      pipe _ARG_((int*));
52         _END_EXTERNS_
53         main()
54         {       int             rw[2];
55                 struct pollfd   fd;
56                 if (pipe(rw) < 0) return 1;
57                 fd.fd = rw[0];
58                 fd.events = POLLIN;
59                 fd.revents = 0;
60                 return poll(1, &fd, 0) < 0;
61         }
62 }end
63
64 cat{
65         #if _lib_poll_fd_1 || _lib_poll_fd_2
66         #define _lib_poll       1
67         #endif
68         #if _lib_NutForkExecve
69         #define _map_spawnve    NutForkExecve
70         #else
71         #if _lib_pcreateve
72         #define _map_spawnve    pcreateve
73         #endif
74         #endif
75 }end
76
77 tst     lib_poll_notimer note{ poll with no fds ignores timeout }end execute{
78         #include <sys/types.h>
79         #include <poll.h>
80         _BEGIN_EXTERNS_
81         extern time_t   time _ARG_((time_t*));
82         _END_EXTERNS_
83         #define TIMEOUT         4
84         main()
85         {
86                 unsigned long   start;
87                 unsigned long   finish;
88                 struct pollfd   fd;
89                 start = time((time_t*)0);
90                 if (poll(&fd, 0, TIMEOUT * 1000) < 0)
91                         return 0;
92                 finish = time((time_t*)0);
93                 return (finish - start) > (TIMEOUT / 2);
94         }
95 }end
96
97 tst     lib_select note{ select() has standard 5 arg interface }end link{
98         #include <sys/types.h>
99         #include <sys/time.h>
100         #include <sys/socket.h>
101         main()
102         {       struct timeval  tmb;
103                 fd_set          rd;
104                 FD_ZERO(&rd);
105                 FD_SET(0,&rd);
106                 tmb.tv_sec = 0;
107                 tmb.tv_usec = 0;
108                 select(1,&rd,(fd_set*)0,(fd_set*)0,&tmb);
109                 return 0;
110         }
111 }end
112
113 tst     pipe_rw note{ full duplex pipes }end execute{
114         _BEGIN_EXTERNS_
115         extern int      pipe _ARG_((int*));
116         extern int      read _ARG_((int, void*, int));
117         extern int      strcmp _ARG_((const char*, const char*));
118         extern int      write _ARG_((int, void*, int));
119         _END_EXTERNS_
120         main()
121         {
122                 static char     test[] = "test\n";
123                 int             io[2];
124                 char            buf[sizeof(test)];
125                 if (pipe(io)) return 1;
126                 if (write(io[1], test, sizeof(test)) != sizeof(test)) return 1;
127                 if (read(io[0], buf, sizeof(test)) != sizeof(test)) return 1;
128                 if (strcmp(test, buf)) return 1;
129                 if (write(io[0], test, sizeof(test)) != sizeof(test)) return 1;
130                 if (read(io[1], buf, sizeof(test)) != sizeof(test)) return 1;
131                 if (strcmp(test, buf)) return 1;
132                 return 0;
133         }
134 }end
135
136 tst     real_vfork note{ vfork child shares data with parent }end execute{
137         _BEGIN_EXTERNS_
138         extern int      vfork();
139         extern int      _exit(int);
140         _END_EXTERNS_
141         int             code;
142         main()
143         {
144                 code = 1;
145                 if (!vfork()) code = 0;
146                 _exit(code);
147         }
148 }end
149
150 tst     stream_peek note{ ioctl(I_PEEK) works }end link{
151         #include <sys/types.h>
152         #include <stropts.h>
153         main()
154         {       struct strpeek  pbuf;
155                 pbuf.flags = 0;
156                 pbuf.ctlbuf.maxlen = pbuf.databuf.maxlen =
157                 pbuf.ctlbuf.len = pbuf.databuf.len = 0;
158                 pbuf.ctlbuf.buf = pbuf.databuf.buf = 0;
159                 ioctl(0,I_PEEK,&pbuf);
160                 return 0;
161         }
162 }end
163
164 tst     socket_peek note{ recv(MSG_PEEK) works }end link{
165         #include <sys/types.h>
166         #include <sys/socket.h>
167         main()
168         {       char    buf[128];
169                 recv(0,buf,sizeof(buf),MSG_PEEK);
170                 return 0;
171         }
172 }end
173
174 tst     lib_mmap sys/types.h sys/stat.h unistd.h fcntl.h mman.h sys/mman.h sys/times.h note{ standard mmap interface that works }end execute{
175         #define BUFSIZE (16*1024)
176         #define MAPSIZE (16*1024)
177         #define WRITE   (64)
178         #if _STD_
179         main(int argc, char** argv)
180         #else
181         main(argc,argv)
182         int     argc;
183         char**  argv;
184         #endif
185         {
186                 caddr_t         mm;
187                 char*           t;
188                 char*           f;
189                 int             i;
190                 int             fd;
191                 char            file[1024];
192                 char            buf[BUFSIZE];
193                 struct tms      brdtm, erdtm, bmmtm, emmtm;
194         
195                 f = argv[0];
196                 t = file;
197                 while (*t = *f++) t++;
198                 *t++ = '.';
199                 *t++ = 'D';
200                 *t = 0;
201                 /* create data file */
202                 if ((fd = creat(file,0666)) < 0)
203                         return(1);
204                 for (i = 0; i < sizeof(buf); ++i)
205                         buf[i] = '0' + (i%10);
206                 for (i = 0; i < WRITE; ++i)
207                         if (write(fd,buf,sizeof(buf)) != sizeof(buf))
208                                 return(1);
209                 close(fd);
210                 /* read time */
211                 if ((fd = open(file, 0)) < 0)
212                         return(1);
213                 times(&brdtm);
214                 for (i = 0; i < WRITE; ++i)
215                         if (read(fd,buf,sizeof(buf)) != sizeof(buf))
216                                 return(1);
217                 times(&erdtm);
218                 close(fd);
219                 /* memory map time */
220                 if ((fd = open(file,0)) < 0)
221                         return(1);
222                 times(&bmmtm);
223                 mm = 0;
224                 for (i = 0; i < (WRITE/(MAPSIZE/BUFSIZE)); ++i)
225                 {       mm = (caddr_t)mmap(mm, MAPSIZE, (PROT_READ|PROT_WRITE),
226                                   (MAP_PRIVATE | (mm ? MAP_FIXED : 0)),
227                                   fd, i*MAPSIZE );
228                         if(mm == (caddr_t)(-1) || mm == (caddr_t)0)
229                                 return(1);
230                 }
231                 times(&emmtm);
232                 close(fd);
233                 unlink(file);
234                 if(((erdtm.tms_utime-brdtm.tms_utime)+(erdtm.tms_stime-brdtm.tms_stime)) <=
235                    ((emmtm.tms_utime-bmmtm.tms_utime)+(emmtm.tms_stime-bmmtm.tms_stime)) )
236                         return(1);
237         
238                 return(0);
239         }
240 }end
241
242 tst     ptr_dd_buf sys/types.h - dirent.h - ndir.h - sys/dir.h note{ DIR.dd_buf is a pointer }end compile{
243         main()
244         {
245                 DIR*    dirp;
246                 dirp->dd_buf = 0;
247                 return 0;
248         }
249 }end
250
251 tst     lib_utime_now note{ utime works with 0 time vector }end execute{
252         #include <sys/types.h>
253         _BEGIN_EXTERNS_
254         extern int      utime _ARG_((const char*, void*));
255         _END_EXTERNS_
256         main()
257         {
258                 return utime(".", (void*)0) == -1;
259         }
260 }end
261
262 tst     run{
263         u=att
264         case `/bin/cat -s /dev/null/foo 2>&1` in
265         '')     ;;
266         *)      case `/bin/echo '\\\\t'` in
267                 '\\t')  u=ucb ;;
268                 esac
269                 ;;
270         esac
271         echo "#define _UNIV_DEFAULT     \\"$u\\"        /* default universe name */"
272 }end
273
274 std     cleanup note{ stuck with standard _cleanup }end noexecute{
275         #include <stdio.h>
276         _BEGIN_EXTERNS_
277         extern void exit _ARG_((int));
278         extern void _exit _ARG_((int));
279         extern void _cleanup();
280         void _cleanup() { _exit(0); }
281         _END_EXTERNS_
282         main() { printf("cleanup\n"); exit(1); }
283 }end
284
285 std     malloc note{ stuck with standard malloc }end noexecute{
286         _BEGIN_EXTERNS_
287         extern char* strdup _ARG_((const char*));
288         #if _STD_
289         char* malloc(unsigned n) { return 0; }
290         #else
291         char* malloc(n) unsigned n; { return 0; }
292         #endif
293         _END_EXTERNS_
294         main() { return strdup("yo") != 0; }
295 }end
296
297 std     signal note{ stuck with standard signal }end nolink{
298         _BEGIN_EXTERNS_
299         extern int abort();
300         int signal() { return 0; }
301         _END_EXTERNS_
302         main() { signal(); abort(); return 0; }
303 }end
304
305 std     strcoll note{ standard strcoll works }end execute{
306         #include <string.h>
307         #define S       "hello world"
308         main()
309         {
310                 char    s[] = S;
311                 char    t[] = S;
312                 return strcoll(s, t) || strcmp(s, t);
313         }
314 }end