Read compressed files and deal with byte swapping.

T

tianyf

1). Compressed data (.Z) from several servers (Sun/Linux).
The compressed files are in either big-endian or little-endian
style.

2). I'm programming in Cygwin (Windows XP) with gcc 3.4.

When use gzgetc to read data from compressed big-endian file, my
program hangs up. However, after uncompress and then compress the
file, the program works well. I supposed that the cause is the byte
ordering style. Is there a way to use gzgetc to read data directly
from big-endian .Z file when in a little-endian environment?


Regards,
Tian
 
S

santosh

1). Compressed data (.Z) from several servers (Sun/Linux).
The compressed files are in either big-endian or little-endian
style.

2). I'm programming in Cygwin (Windows XP) with gcc 3.4.

When use gzgetc to read data from compressed big-endian file, my
program hangs up. However, after uncompress and then compress the
file, the program works well. I supposed that the cause is the byte
ordering style. Is there a way to use gzgetc to read data directly
from big-endian .Z file when in a little-endian environment?

To get meaningful results you need to convert the input data to your native
endianess before performing any other operation. All the major OSes have
APIs to do this. You need to look into your Cygwin documentation to find
out what routines you need to use. Since Cygwin is a POSIX emulation layer
the functions you want might be htons, htonl, ntohs, and ntohl.
 
T

tianyf

To get meaningful results you need to convert the input data to your native
endianess before performing any other operation. All the major OSes have
APIs to do this. You need to look into your Cygwin documentation to find
out what routines you need to use. Since Cygwin is a POSIX emulation layer
the functions you want might be htons, htonl, ntohs, and ntohl.

It turns out that the "compress" command in Cygwin is actually "gzip"
which produces a file (.Z) that cannot be decompressed by Solaris
"uncompress" command.
uncompress a.Z
a.Z: not in compressed format

I wonder whether there is a C library to deal with files compressed by
Solaris "uncompress", just like zlib can handle .gz files.

Regards,
Tian
 
C

Charlie Gordon

It turns out that the "compress" command in Cygwin is actually "gzip"
which produces a file (.Z) that cannot be decompressed by Solaris
"uncompress" command.

a.Z: not in compressed format

I wonder whether there is a C library to deal with files compressed by
Solaris "uncompress", just like zlib can handle .gz files.

The easiest would be to use ``FILE *fp = popen("uncompress < filename",
"rb")'' on systems that support this Posix interface (linux, cygwin...)
 
T

tianyf

<[email protected]> a écrit dans le message de (e-mail address removed)...






The easiest would be to use ``FILE *fp = popen("uncompress < filename",
"rb")'' on systems that support this Posix interface (linux, cygwin...)

It works.

FILE *fp;
fp=popen("gunzip a.Z","r");
fgets(,,);
fgetc(,,);
pclose(fp);

Make sure to use pclose() not fclose() to close the stream. I made a
mistake and the program only read the first file correctly. Now, it
works perfectly.

Thanks.

Regards,
Tian
 
M

Mark McIntyre

I wonder whether there is a C library to deal with files compressed by
Solaris "uncompress", just like zlib can handle .gz files.

Why not just install gzip on both platforms? Its a free download.
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
 
T

tianyf

Why not just install gzip on both platforms? Its a free download.
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan

I do have gzip in both systems. However, my aim is to check the
integrity of the *.Z file without uncompressing it, which can preserve
the time stamp and save the processing time.

Regards,
Tian
 
C

Charlie Gordon

It works.

FILE *fp;
fp=popen("gunzip a.Z","r");
fgets(,,);
fgetc(,,);
pclose(fp);

Make sure to use pclose() not fclose() to close the stream. I made a
mistake and the program only read the first file correctly. Now, it
works perfectly.

Thanks.

Regards,
Tian

I guess this count as a vote to support Group M (Moderates)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top