/* * Copyright (C) 2002 - David W. Durham * * This file is part of ReZound, an audio editing application. * * ReZound is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published * by the Free Software Foundation; either version 2 of the License, * or (at your option) any later version. * * ReZound is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ /* I discovered what I think to be a bug in glibc where the following program will fail ONLY when gcc is giving --static which causes glibc to be linked to statically. #include #include void *func(void *temp) { return NULL; } int main() { pthread_t threadID; popen("ls","r"); pthread_create(&threadID,NULL,func,NULL); return 0; } So, when ReZound is being linked statically, mypopen is used instead of popen. I had to write this mypopen function for a college operating systems lab class, so I thought I'd put it to good use. Also, I might start using this exclusively which would give me more control like changing it to also let me capture the spawned process's stderr stream as well as stdout. Also, this would be mypopen.c instead of mypopen.cpp except that I need to include ../../config/common.h which has some C++ in it. */ #include "mypopen.h" #include #include #include #include #include #include #include #include #define MAX_OPENS 100 static int child_pids[MAX_OPENS]; /* init to zero */ static FILE *pipe_streams[MAX_OPENS]; static FILE *pipe_err_streams[MAX_OPENS]; /* passed: process id -- pid stream * -- s returns: 0 -- success 1 -- failure */ static int add_piped_process(int pid,FILE *s,FILE *e) { int t; for(t=0;t