19#if defined(_WIN32) && !defined(__MINGW32__)
20# define popen(x, y) _popen(x, y)
24static char *unpackSuffix[UNPACK_TYPES] = {
29static char *unpackCommand[UNPACK_TYPES] = {
30 "gzip -dcn %s 2> /dev/null ",
47long PackSuffixType(
char *filename,
char **unpackedName,
unsigned long mode) {
48 char *extension, buffer[10];
52 if (!(extension = strrchr(filename,
'.')))
56 for (i = 0; i < UNPACK_TYPES; i++)
57 if (strcmp(extension, unpackSuffix[i]) == 0) {
59 cp_str(unpackedName, filename);
60 extension = strrchr(*unpackedName,
'.');
65 if (i == UNPACK_TYPES)
68 if (mode & UNPACK_REQUIRE_SDDS) {
69 if (!(fp = fopen(filename, FOPEN_READ_MODE)))
71 if (fread(buffer,
sizeof(*buffer), 4, fp) == 4 && strncmp(buffer,
"SDDS", 4) == 0) {
93FILE *
UnpackFopen(
char *filename,
unsigned long mode,
short *popenUsed,
char **tmpFileUsed) {
94 static char *command = NULL;
105 return fopen(filename, FOPEN_READ_MODE);
107 if (!(command =
trealloc(command,
sizeof(*command) * (strlen(filename) + 100))))
109 if (mode & UNPACK_USE_PIPE) {
110 sprintf(command, unpackCommand[type], filename);
114 fprintf(stderr,
"popen is not supported in vxWorks\n");
118 return popen(command, FOPEN_READ_MODE);
121 sprintf(command, unpackCommand[type], filename);
123 strcat(command,
"> /tmp/");
124 strcat(command, tmpName);
127 sprintf(command,
"/tmp/%s", tmpName);
129 cp_str(tmpFileUsed, command);
131 return fopen(command, FOPEN_READ_MODE);
144gzFile UnpackGZipOpen(
char *filename) {
147 return gzopen(filename,
"rb");
void * trealloc(void *old_ptr, uint64_t size_of_block)
Reallocates a memory block to a new size.
char * cp_str(char **s, char *t)
Copies a string, allocating memory for storage.
char * tmpname(char *s)
Supplies a unique temporary filename.
FILE * UnpackFopen(char *filename, unsigned long mode, short *popenUsed, char **tmpFileUsed)
Opens a file, potentially unpacking it based on its extension and mode.
long PackSuffixType(char *filename, char **unpackedName, unsigned long mode)
Determines the unpacking type based on the file extension.