00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
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
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
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
00069 } else
00070 fclose(f);
00071 }