src/hcode/mechfile.c

Go to the documentation of this file.
00001 
00002 /*
00003  * $Id: mechfile.c,v 1.1 2005/06/13 20:50:49 murrayma Exp $
00004  *
00005  * Author: Markus Stenberg <fingon@iki.fi>
00006  *
00007  *  Copyright (c) 1996 Markus Stenberg
00008  *       All rights reserved
00009  *
00010  * Created: Tue Oct 29 23:09:59 1996 fingon
00011  * Last modified: Fri Feb  7 19:37:02 1997 fingon
00012  *
00013  */
00014 
00015 #include <stdio.h>
00016 #include <string.h>
00017 
00018 #undef FILES_COMPRESSED_BY_DEFAULT
00019 
00020 FILE *my_open_file(char *name, char *mode, int *openway)
00021 {
00022         FILE *f;
00023         char buf[512];
00024         char buf2[512];
00025 
00026         if(!strcmp(mode, "w")) {
00027 #ifdef FILES_COMPRESSED_BY_DEFAULT
00028 
00029 /*       dup2(2, 1); */
00030                 sprintf(buf, "nice gzip -c > %s.gz", name);
00031                 if(!(f = popen(buf, mode)))
00032                         return NULL;
00033                 *openway = 1;
00034                 return f;
00035 #else
00036                 if(!(f = fopen(name, mode)))
00037                         return NULL;
00038                 *openway = 0;
00039                 return f;
00040 #endif
00041         }
00042         if((f = fopen(name, mode))) {
00043                 *openway = 0;
00044                 return f;
00045         }
00046         sprintf(buf, "%s.gz", name);
00047         if((f = fopen(buf, mode)))
00048                 fclose(f);
00049         else
00050                 return NULL;
00051         sprintf(buf2, "nice gzip -dc < %s", buf);
00052 
00053 /*   dup2(2, 1); */
00054         if((f = popen(buf2, mode))) {
00055                 *openway = 1;
00056                 return f;
00057         }
00058         return NULL;
00059 }
00060 
00061 void my_close_file(FILE * f, int *openway)
00062 {
00063         if(!f)
00064                 return;
00065         if(*openway) {
00066                 pclose(f);
00067 
00068 /*       close(1); */
00069         } else
00070                 fclose(f);
00071 }

Generated on Mon May 28 04:25:24 2007 for BattletechMUX by  doxygen 1.4.7