1 /* $Header: msdos.c,v 4.0 91/03/20 01:34:46 lwall Locked $
3 * (C) Copyright 1989, 1990 Diomidis Spinellis.
5 * You may distribute under the terms of the GNU General Public License
6 * as specified in the README file that comes with the perl 3.0 kit.
9 * Revision 4.0 91/03/20 01:34:46 lwall
12 * Revision 3.0.1.1 90/03/27 16:10:41 lwall
13 * patch16: MSDOS support
15 * Revision 1.1 90/03/18 20:32:01 dds
21 * Various Unix compatibility functions for MS-DOS.
31 * Interface to the MS-DOS ioctl system call.
32 * The function is encoded as follows:
33 * The lowest nibble of the function code goes to AL
34 * The two middle nibbles go to CL
35 * The high nibble goes to CH
37 * The return code is -1 in the case of an error and if successful
38 * for functions AL = 00, 09, 0a the value of the register DX
39 * for functions AL = 02 - 08, 0e the value of the register AX
40 * for functions AL = 01, 0b - 0f the number 0
42 * Notice that this restricts the ioctl subcodes stored in AL to 00-0f
43 * In the Ralf Borwn interrupt list 90.1 there are no subcodes above AL=0f
45 * Furthermore CH is also restriced in the same area. Where CH is used as a
46 * code it always is between 00-0f. In the case where it forms a count
47 * together with CL we arbitrarily set the highest count limit to 4095. It
48 * sounds reasonable for an ioctl.
49 * The other alternative would have been to use the pointer argument to
50 * point the the values of CX. The problem with this approach is that
51 * of accessing wild regions when DX is used as a number and not as a
55 ioctl(int handle, unsigned int function, char *data)
61 srv.h.al = (unsigned char)(function & 0x0F);
63 srv.x.cx = function >> 4;
65 #if ( defined(M_I86LM) || defined(M_I86CM) || defined(M_I86HM) )
66 segregs.ds = FP_SEG(data);
67 srv.x.dx = FP_OFF(data);
69 srv.x.dx = (unsigned int) data;
71 intdosx(&srv, &srv, &segregs);
72 if (srv.x.cflag & 1) {
110 switch (function & 0xf) {
111 case 0: case 9: case 0xa:
113 case 2: case 3: case 4: case 5:
114 case 6: case 7: case 8: case 0xe:
116 case 1: case 0xb: case 0xc: case 0xd:
133 end = time((time_t *)0) + len;
134 while (time((time_t *)0) < end)
139 * Just pretend that everyone is a superuser
169 { return (uid==ROOT_UID?0:-1); }
173 { return (gid==ROOT_GID?0:-1); }
176 * The following code is based on the do_exec and do_aexec functions
180 do_aspawn(really,arglast)
184 register STR **st = stack->ary_array;
185 register int sp = arglast[1];
186 register int items = arglast[2] - sp;
193 New(1101,argv, items+1, char*);
195 for (st += ++sp; items > 0; items--,st++) {
202 if (really && *(tmps = str_get(really)))
203 status = spawnvp(P_WAIT,tmps,argv);
205 status = spawnvp(P_WAIT,argv[0],argv);
223 /* save an extra exec if possible */
224 if ((shell = getenv("COMSPEC")) == 0)
225 shell = "\\command.com";
227 /* see if there are shell metacharacters in it */
228 if (strchr(cmd, '>') || strchr(cmd, '<') || strchr(cmd, '|'))
230 return spawnl(P_WAIT,shell,shell,"/c",cmd,(char*)0);
232 New(1102,argv, strlen(cmd) / 2 + 2, char*);
234 New(1103,cmd2, strlen(cmd) + 1, char);
237 for (s = cmd2; *s;) {
238 while (*s && isspace(*s)) s++;
241 while (*s && !isspace(*s)) s++;
247 if ((status = spawnvp(P_WAIT,argv[0],argv)) == -1) {