00001 /* 00002 Copyright (c) 2005, Quentin Lequy and Romain Gaucher 00003 All rights reserved. 00004 00005 Redistribution and use in source and binary forms, with or 00006 without modification, are permitted provided that the following 00007 conditions are met: 00008 00009 * Redistributions of source code must retain the above copyright 00010 notice, this list of conditions and the following disclaimer. 00011 00012 * Redistributions in binary form must reproduce the above copyright 00013 notice, this list of conditions and the following disclaimer in the 00014 documentation and/or other materials provided with the distribution. 00015 00016 * Neither the name of Quentin Lequy or Romain Gaucher nor the names 00017 of its contributors may be used to endorse or promote products 00018 derived from this software without specific prior written permission. 00019 00020 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00021 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00022 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00023 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00024 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00025 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00026 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 00027 AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00028 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00029 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00030 */ 00031 00032 #include "System.h" 00033 00034 #include <string> 00035 #ifndef WINDOWS_VERSION 00036 #include <unistd.h> 00037 #include <netdb.h> 00038 #include <fcntl.h> 00039 #endif 00040 00041 namespace Modelib { 00042 00043 namespace System 00044 { 00045 using namespace std; 00046 00052 void call (const char *str) 00053 { 00054 #ifdef WINDOWS_VERSION 00055 system(str); 00056 #else 00057 int p = SubSystemCall(str); 00058 // attendre la fin du processus 00059 while (wait(&p) != -1) 00060 ; 00061 #endif 00062 } 00063 00064 #ifndef WINDOWS_VERSION 00065 int SubSystemCall(const char *str) 00066 { 00067 int p[2]; 00068 pipe(p); 00069 if (fork()) 00070 { 00071 close(p[1]); 00072 return(p[0]); 00073 } 00074 else 00075 { 00076 close(p[0]); 00077 close(1); 00078 dup2(p[1],1); 00079 close(p[1]); 00080 system(str); 00081 exit(0); 00082 } 00083 } 00084 #endif 00085 00091 void del (const char *str) 00092 { 00093 #ifdef WINDOWS_VERSION 00094 string s = "del " + string(str); 00095 #else 00096 string s = "rm -f " + string(str); 00097 #endif 00098 system(s.c_str()); 00099 } 00100 00101 } 00102 00103 } 00104