If the specified file is compressed, return a pipe that * uncompresses it. */
| 131 | * uncompresses it. |
| 132 | */ |
| 133 | FILE *fopen(const char *path, const char *mode) |
| 134 | { |
| 135 | static fopen_t real_fopen; |
| 136 | if (real_fopen == NULL) |
| 137 | real_fopen = (fopen_t)dlsym(RTLD_NEXT, "fopen"); |
| 138 | if (real_fopen == NULL) { |
| 139 | fprintf(stderr, "error: dlsym fopen: %s\n", dlerror()); |
| 140 | exit(EXIT_FAILURE); |
| 141 | } |
| 142 | |
| 143 | // open a web address |
| 144 | if (wgetExec(path) != NULL) |
| 145 | return funcompress(path); |
| 146 | |
| 147 | // to check if the file exists, we need to attempt to open it |
| 148 | FILE* stream = real_fopen(path, mode); |
| 149 | if (string(mode) != "r" || !stream || zcatExec(path) == NULL) |
| 150 | return stream; |
| 151 | else { |
| 152 | fclose(stream); |
| 153 | return funcompress(path); |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | /** If the specified file is compressed, return a pipe that |
| 158 | * uncompresses it. |
no test coverage detected