Subject: Re: need compression for a C based program

From: [email-masked]
Date: 26 Feb 91 22:51:09 GMT

In article <[email-masked]>,
[email-masked] (Theodore W. Gaunt) writes:
> I am looking for the sources for quick, comression and decompression utilities
> written in C.  I need the source so that I can implement a compression and
> decompression of this tapefile on the fly.
>
> Ted Gaunt
> [email-masked]

If you just need compression and can't get any sources, you could run compress
as a child process and send your output to it via a pipe. This would be very
easy (assuming you have a UN!X system) and you wouldn't have to try to
integrate somebody else's code into yours.

Fake C code:

int pid, pipedes[2];

pipe(pipefds); // create pipe
if ((pid = fork()) == 0) {
  // child process -- redirect stdin to read from pipe
  close(0); // close stdin
  dup(pipedes[0]); // duplicate pipe into stdin
  close(pipedes[0]); // close other pipe descriptor
  close(pipedes[1]); // close child->parent output as well

  // here you could change the child process's stdout to be your output
  // file... (e.g., close(1); open("outputfile", O_WRONLY); ...)

  execlp("compress", "compress", "-c", 0); // I think "-c" means "use stdin"
}

// now we're in your program, compress is running as a child. Anything
// you write to file descriptor pipedes[1] will be sent to the child
// (compress) as input, be compressed, and sent to the child's output.

Hope this helps.

--Tom Moetel
[email-masked]
[email-masked]