4 # define INCL_DOSMEMMGR
5 # define INCL_DOSERRORS
6 #endif /* ! defined NO_SYS_ALLOC */
10 * Various Unix compatibility functions for OS/2
21 /*****************************************************************************/
24 int setpriority(int which, int pid, int val)
26 return DosSetPriority((pid < 0) ? PRTYS_PROCESSTREE : PRTYS_PROCESS,
27 val >> 8, val & 0xFF, abs(pid));
30 int getpriority(int which /* ignored */, int pid)
34 DosGetInfoBlocks(&tib, &pib);
35 return tib->tib_ptib2->tib2_ulpri;
38 /*****************************************************************************/
42 result(int flag, int pid)
45 Signal_t (*ihand)(); /* place to save signal during system() */
46 Signal_t (*qhand)(); /* place to save signal during system() */
48 if (pid < 0 || flag != 0)
51 ihand = signal(SIGINT, SIG_IGN);
52 qhand = signal(SIGQUIT, SIG_IGN);
54 r = wait4pid(pid, &status, 0);
55 } while (r == -1 && errno == EINTR);
56 signal(SIGINT, ihand);
57 signal(SIGQUIT, qhand);
59 statusvalue = (U16)status;
62 return status & 0xFFFF;
66 do_aspawn(really,mark,sp)
74 int flag = P_WAIT, trueflag;
77 New(401,Argv, sp - mark + 1, char*);
80 if (mark < sp && SvIOKp(*(mark+1))) {
85 while (++mark <= sp) {
87 *a++ = SvPVx(*mark, na);
97 if (*Argv[0] != '/' && *Argv[0] != '\\') /* will swawnvp use PATH? */
98 TAINT_ENV(); /* testing IFS here is overkill, probably */
99 if (really && *(tmps = SvPV(really, na)))
100 rc = result(trueflag, spawnvp(flag,tmps,Argv));
102 rc = result(trueflag, spawnvp(flag,Argv[0],Argv));
104 if (rc < 0 && dowarn)
105 warn("Can't spawn \"%s\": %s", Argv[0], Strerror(errno));
106 if (rc < 0) rc = 255 << 8; /* Emulate the fork(). */
124 if ((shell = getenv("EMXSHELL")) != NULL)
126 else if ((shell = getenv("SHELL")) != NULL)
128 else if ((shell = getenv("COMSPEC")) != NULL)
133 /* Consensus on perl5-porters is that it is _very_ important to
134 have a shell which will not change between computers with the
135 same architecture, to avoid "action on a distance".
136 And to have simple build, this shell should be sh. */
141 while (*cmd && isSPACE(*cmd))
144 /* save an extra exec if possible */
145 /* see if there are shell metacharacters in it */
147 if (*cmd == '.' && isSPACE(cmd[1]))
150 if (strnEQ(cmd,"exec",4) && isSPACE(cmd[4]))
153 for (s = cmd; *s && isALPHA(*s); s++) ; /* catch VAR=val gizmo */
157 for (s = cmd; *s; s++) {
158 if (*s != ' ' && !isALPHA(*s) && strchr("$&*(){}[]'\";\\|?<>~`\n",*s)) {
159 if (*s == '\n' && !s[1]) {
165 spawnl(P_NOWAIT,shell,shell,copt,cmd,(char*)0));
166 if (rc < 0 && dowarn)
167 warn("Can't spawn \"%s\": %s", shell, Strerror(errno));
168 if (rc < 0) rc = 255 << 8; /* Emulate the fork(). */
173 New(402,Argv, (s - cmd) / 2 + 2, char*);
174 Cmd = savepvn(cmd, s-cmd);
177 while (*s && isSPACE(*s)) s++;
180 while (*s && !isSPACE(*s)) s++;
186 rc = result(P_WAIT, spawnvp(P_NOWAIT,Argv[0],Argv));
187 if (rc < 0 && dowarn)
188 warn("Can't spawn \"%s\": %s", Argv[0], Strerror(errno));
189 if (rc < 0) rc = 255 << 8; /* Emulate the fork(). */
201 char *shell = getenv("EMXSHELL");
204 my_setenv("EMXSHELL", "sh.exe");
205 res = popen(cmd, mode);
206 my_setenv("EMXSHELL", shell);
210 /*****************************************************************************/
216 die(no_func, "Unsupported function fork");
222 /*****************************************************************************/
223 /* not implemented in EMX 0.9a */
225 void * ctermid(x) { return 0; }
227 #ifdef MYTTYNAME /* was not in emx0.9a */
228 void * ttyname(x) { return 0; }
231 void * gethostent() { return 0; }
232 void * getnetent() { return 0; }
233 void * getprotoent() { return 0; }
234 void * getservent() { return 0; }
235 void sethostent(x) {}
237 void setprotoent(x) {}
238 void setservent(x) {}
239 void endhostent(x) {}
241 void endprotoent(x) {}
242 void endservent(x) {}
244 /*****************************************************************************/
245 /* stat() hack for char/block device */
249 /* First attempt used DosQueryFSAttach which crashed the system when
250 used with 5.001. Now just look for /dev/. */
253 os2_stat(char *name, struct stat *st)
255 static int ino = SHRT_MAX;
257 if (stricmp(name, "/dev/con") != 0
258 && stricmp(name, "/dev/tty") != 0)
259 return stat(name, st);
261 memset(st, 0, sizeof *st);
262 st->st_mode = S_IFCHR|0666;
263 st->st_ino = (ino-- & 0x7FFF);
274 #define ONE_K (1<<10)
275 #define TWO_K (1<<11)
276 #define FOUR_K (1<<12)
277 #define FOUR_K_FLAG (FOUR_K - 1)
288 else if (size == TWO_K) {
297 } else if (size & FOUR_K_FLAG) {
298 croak("Memory allocation in units %li not multiple to 4K", size);
300 rc = DosAllocMem((void **)&got, size, PAG_COMMIT | PAG_WRITE);
301 if (rc == ERROR_NOT_ENOUGH_MEMORY) {
303 } else if ( rc ) die("Got an error from DosAllocMem: %li", (long)rc);
304 if (is2K) old2K = got + TWO_K;
307 #endif /* ! defined NO_SYS_ALLOC */
311 char *tmppath = TMPPATH1;
316 char *p = getenv("TMP"), *tpath;
319 if (!p) p = getenv("TEMP");
322 tpath = (char *)malloc(len + strlen(TMPPATH1) + 2);
325 strcpy(tpath + len + 1, TMPPATH1);