ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/porting.C
(Generate patch)

Comparing deliantra/server/common/porting.C (file contents):
Revision 1.5 by root, Sun Sep 10 16:00:23 2006 UTC vs.
Revision 1.7 by root, Thu Sep 14 22:34:00 2006 UTC

1
2/*
3 * static char *rcsid_porting_c =
4 * "$Id: porting.C,v 1.5 2006/09/10 16:00:23 root Exp $";
5 */
6
7/* 1/*
8 CrossFire, A Multiplayer game for X-windows 2 CrossFire, A Multiplayer game for X-windows
9 3
10 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 4 Copyright (C) 2002 Mark Wedel & Crossfire Development Team
11 Copyright (C) 1992 Frank Tore Johansen 5 Copyright (C) 1992 Frank Tore Johansen
22 16
23 You should have received a copy of the GNU General Public License 17 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software 18 along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 20
27 The authors can be reached via e-mail at crossfire-devel@real-time.com 21 The authors can be reached via e-mail at <crossfire@schmorp.de>
28*/ 22*/
29 23
30/* This file contains various functions that are not really unique for 24/* This file contains various functions that are not really unique for
31 * crossfire, but rather provides what should be standard functions 25 * crossfire, but rather provides what should be standard functions
32 * for systems that do not have them. In this way, most of the 26 * for systems that do not have them. In this way, most of the
178 int fd[2]; 172 int fd[2];
179 int pd; 173 int pd;
180 FILE *ret; 174 FILE *ret;
181 175
182 if (!strcmp (type, "r")) 176 if (!strcmp (type, "r"))
183 {
184 pd = STDOUT_FILENO; 177 pd = STDOUT_FILENO;
185 }
186 else if (!strcmp (type, "w")) 178 else if (!strcmp (type, "w"))
187 {
188 pd = STDIN_FILENO; 179 pd = STDIN_FILENO;
189 }
190 else 180 else
191 {
192 return NULL; 181 return NULL;
193 } 182
194 if (pipe (fd) != -1) 183 if (pipe (fd) != -1)
195 { 184 {
196 switch (fork ()) 185 switch (fork ())
197 { 186 {
198 case -1: 187 case -1:
199 close (fd[0]); 188 close (fd[0]);
200 close (fd[1]); 189 close (fd[1]);
201 break; 190 break;
202 case 0: 191 case 0:
203 close (fd[0]); 192 close (fd[0]);
204 if ((fd[1] == pd) || (dup2 (fd[1], pd) == pd)) 193 if ((fd[1] == pd) || (dup2 (fd[1], pd) == pd))
205 { 194 {
206 if (fd[1] != pd) 195 if (fd[1] != pd)
207 { 196 {
208 close (fd[1]); 197 close (fd[1]);
209 } 198 }
210 execl ("/bin/sh", "sh", "-c", command, NULL); 199 execl ("/bin/sh", "sh", "-c", command, NULL);
211 close (pd); 200 close (pd);
212 } 201 }
213 exit (1); 202 _exit (1);
214 break; 203 break;
215 default: 204 default:
216 close (fd[1]); 205 close (fd[1]);
217 if (ret = fdopen (fd[0], type)) 206 if (ret = fdopen (fd[0], type))
218 { 207 {
219 return ret; 208 return ret;
220 } 209 }
221 close (fd[0]); 210 close (fd[0]);
222 break; 211 break;
223 } 212 }
224 } 213 }
225 return NULL; 214 return NULL;
226} 215}
227 216
229 218
230 219
231/***************************************************************************** 220/*****************************************************************************
232 * String related function 221 * String related function
233 ****************************************************************************/ 222 ****************************************************************************/
234
235
236 223
237/* 224/*
238 * A replacement of strdup(), since it's not defined at some 225 * A replacement of strdup(), since it's not defined at some
239 * unix variants. 226 * unix variants.
240 */ 227 */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines