1 /* $RCSfile: msdos.c,v $$Revision: 4.1 $$Date: 92/08/07 18:24:49 $
3 * (C) Copyright 1989, 1990 Diomidis Spinellis.
5 * You may distribute under the terms of either the GNU General Public
6 * License or the Artistic License, as specified in the README file.
9 * Revision 4.1 92/08/07 18:24:49 lwall
11 * Revision 4.0.1.1 91/06/07 11:22:37 lwall
12 * patch4: new copyright notice
14 * Revision 4.0 91/03/20 01:34:46 lwall
17 * Revision 3.0.1.1 90/03/27 16:10:41 lwall
18 * patch16: MSDOS support
20 * Revision 1.1 90/03/18 20:32:01 dds
26 * Various Unix compatibility functions for MS-DOS.
36 * Interface to the MS-DOS ioctl system call.
37 * The function is encoded as follows:
38 * The lowest nibble of the function code goes to AL
39 * The two middle nibbles go to CL
40 * The high nibble goes to CH
42 * The return code is -1 in the case of an error and if successful
43 * for functions AL = 00, 09, 0a the value of the register DX
44 * for functions AL = 02 - 08, 0e the value of the register AX
45 * for functions AL = 01, 0b - 0f the number 0
47 * Notice that this restricts the ioctl subcodes stored in AL to 00-0f
48 * In the Ralf Borwn interrupt list 90.1 there are no subcodes above AL=0f
50 * Furthermore CH is also restriced in the same area. Where CH is used as a
51 * code it always is between 00-0f. In the case where it forms a count
52 * together with CL we arbitrarily set the highest count limit to 4095. It
53 * sounds reasonable for an ioctl.
54 * The other alternative would have been to use the pointer argument to
55 * point the the values of CX. The problem with this approach is that
56 * of accessing wild regions when DX is used as a number and not as a
60 ioctl(int handle, unsigned int function, char *data)
66 srv.h.al = (unsigned char)(function & 0x0F);
68 srv.x.cx = function >> 4;
70 #if ( defined(M_I86LM) || defined(M_I86CM) || defined(M_I86HM) )
71 segregs.ds = FP_SEG(data);
72 srv.x.dx = FP_OFF(data);
74 srv.x.dx = (unsigned int) data;
76 intdosx(&srv, &srv, &segregs);
77 if (srv.x.cflag & 1) {
115 switch (function & 0xf) {
116 case 0: case 9: case 0xa:
118 case 2: case 3: case 4: case 5:
119 case 6: case 7: case 8: case 0xe:
121 case 1: case 0xb: case 0xc: case 0xd:
138 end = time((time_t *)0) + len;
139 while (time((time_t *)0) < end)
144 * Just pretend that everyone is a superuser
174 { return (uid==ROOT_UID?0:-1); }
178 { return (gid==ROOT_GID?0:-1); }
181 * The following code is based on the do_exec and do_aexec functions
185 do_aspawn(really,arglast)
189 register STR **st = stack->ary_array;
190 register int sp = arglast[1];
191 register int items = arglast[2] - sp;
198 New(1101,argv, items+1, char*);
200 for (st += ++sp; items > 0; items--,st++) {
207 if (really && *(tmps = str_get(really)))
208 status = spawnvp(P_WAIT,tmps,argv);
210 status = spawnvp(P_WAIT,argv[0],argv);
228 /* save an extra exec if possible */
229 if ((shell = getenv("COMSPEC")) == 0)
230 shell = "\\command.com";
232 /* see if there are shell metacharacters in it */
233 if (strchr(cmd, '>') || strchr(cmd, '<') || strchr(cmd, '|'))
235 return spawnl(P_WAIT,shell,shell,"/c",cmd,(char*)0);
237 New(1102,argv, strlen(cmd) / 2 + 2, char*);
239 New(1103,cmd2, strlen(cmd) + 1, char);
242 for (s = cmd2; *s;) {
243 while (*s && isspace(*s)) s++;
246 while (*s && !isspace(*s)) s++;
252 if ((status = spawnvp(P_WAIT,argv[0],argv)) == -1) {