• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 325
  • Last Modified:

mystery

hi all,
My standalone compress/decompress works perfect. After i imported compress function to my code, it work perfect. However, after import decompress function, it can't decompress the file. As a result, the file is empty. . After i check, it seems gzread() can't read. but the code is just copy and paste. Please tell me what i did wrong. tks a lot.

+ please remove .c in test1a.txt.myziphaha as the input
+ sample.c is the standalone
+ server.c at line 222 is to call decompress.
test1a.txt.myziphaha.c
sample.c
server.c
0
BeginToLearn
Asked:
BeginToLearn
  • 6
  • 2
1 Solution
 
Kent OlsenData Warehouse Architect / DBACommented:
Hi Begin,

What value does gzread() return (what is num_read set to)?

Also, 128 bytes is a very small buffer.  I believe that I'd allocate at least 8K to the buffer, and perhaps more.  But that won't fit on the stack well.  The snippet below should solve that problem.


char *buffer;

  buffer = (char*)malloc (8096);

// .. read/write loop.  Note the size is 8096, NOT sizeof (buffer)!

  fred (buffer);



Kent
0
 
BeginToLearnAuthor Commented:
gzread always return 0.why my sample can work?
0
 
Kent OlsenData Warehouse Architect / DBACommented:

Hmm... weird.  

Do you link the same libraries?

And fred(buffer) above should obviously have been free(buffer).

Kent
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
BeginToLearnAuthor Commented:
verything is same.i cppy n pastr from sample.c .you can take a lok at sample.c .tks a lot.very weird
0
 
BeginToLearnAuthor Commented:
your suggestion doesn't work. Somehow gzread() always return 0 . but in sample.c, it can return proper value.
0
 
BeginToLearnAuthor Commented:
ubuntu@ubuntu:~/program$ ./server /home/ubuntu/program/dest1 51000
constructor, dirname: /home/ubuntu/program/dest1
message1-> total number of files is 1
filename:test1a.txt.myziphaha
input:/home/ubuntu/program/dest1/test1a.txt.myziphaha
output:/home/ubuntu/program/dest1/test1a.txt
outside while, num_read:0
ubuntu@ubuntu:~/program$

--> so it can't get in the read/write loop
0
 
BeginToLearnAuthor Commented:
I have tried all ways, but fail. if I just run sample to decompress it, it works. do you see anything wrong?
0
 
BeginToLearnAuthor Commented:
I solved it :) reason is I call decompress before fclose() hihi
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 6
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now