1 /* $Id: os9.c,v 1.4 2004/07/25 12:25:01 broeker Exp $ */
6 * Copyright 1986 - 1993, 1998, 2004 Thomas Williams, Colin Kelley
8 * Permission to use, copy, and distribute this software and its
9 * documentation for any purpose with or without fee is hereby granted,
10 * provided that the above copyright notice appear in all copies and
11 * that both that copyright notice and this permission notice appear
12 * in supporting documentation.
14 * Permission to modify the software is granted, but not the right to
15 * distribute the complete modified source code. Modifications are to
16 * be distributed as patches to the released version. Permission to
17 * distribute binaries produced by compiling modified sources is granted,
19 * 1. distribute the corresponding source modifications from the
20 * released version in the form of a patch file along with the binaries,
21 * 2. add special version identification to distinguish your version
22 * in addition to the base release version number,
23 * 3. provide your name and address as the primary contact for the
24 * support of your modified version, and
25 * 4. retain our contact information in regard to use of the base
27 * Permission to distribute the released version of the source code along
28 * with corresponding source modifications in the form of a patch file is
29 * granted with same provisions 2 through 4 for binary distributions.
31 * This software is provided "as is" without express or implied warranty
32 * to the extent permitted by applicable law.
37 * Some Unix like functions that gnuplot uses.
38 * Original sources from the blars lib.
48 /* Original version by Robert A. Larson */
49 /* Adapted by M.N. Schipper */
54 extern char *_environ;
56 extern mh_com *modlink();
57 extern mh_com *modloadp();
59 static int proc[_NFILE];
60 static mh_com *loadmods[_NFILE];
63 popen(char *command, char *mode)
72 if(mode[1]!='\0' || (*mode!='r' && *mode!='w'))
75 if((temp = dup(fd)) <= 0)
77 if((pipe = fopen("/pipe", "r+")) == NULL) {
84 if (strrchr (command, '/') == NULL)
85 mod = modlink (command, 0);
88 if (mod == (mh_com *) -1)
89 loadmods[fileno(pipe)] = mod = modloadp (command, 0, NULL);
92 loadmods[fileno(pipe)] = (mh_com *) -1;
96 if (mod != (mh_com *) -1) {
99 argv[3] = (char *)NULL;
102 argv[2] = (char *)NULL;
104 if((proc[fileno(pipe)] = os9exec(os9fork, argv[0], argv, _environ, 0, 0))
112 if (linked && mod != (mh_com *) -1)
122 if((p = proc[fileno(pipe)]) <= 0)
124 proc[fileno(pipe)] = 0;
126 if (loadmods[fileno(pipe)] != (mh_com *) -1)
127 munlink (loadmods[fileno(pipe)]);
129 while((w=wait(&stat)) != -1 && w!=p)
132 return w==-1 ? -1 : stat;
143 if(_gs_opt(f, &sgbuf) < 0) return -1;
144 return sgbuf.sg_class == 0;
153 int l, olddot = 0, i, d, dot, dotdot;
160 if((d = open(".", S_IREAD | S_IFDIR)) < 0) {
164 if((i = read(d, (char *)db, sizeof(db))) == 0) {
169 dotdot = db[0].dir_addr;
170 dot = db[1].dir_addr;
172 i -= 2 * sizeof(struct dirent);
176 if((i = read(d, (char *) db, sizeof(db))) == 0) {
184 if(olddot == dp->dir_addr) {
185 l = strlen(dp->dir_name);
186 /* last character has parity bit set... */
187 *--cp = dp->dir_name[--l] & 0x7f;
189 *--cp = dp->dir_name[--l];
193 i -= sizeof(struct dirent);
200 if(_gs_devn(d, p+1) < 0) {
209 if(chdir("..") != 0) {