1

I'm trying to copy a .tgz file into memory and sending it elsewhere.

Using fopen I get a NULL pointer which tells me that a .tgz file isn't a binary file, but I was wondering if it is even possible to open, buffer, and pass a .tgz file using C standard libraries and libraries?

ardent
  • 2,453
  • 1
  • 16
  • 15
  • 1
    Try calling `perror("fopen");` when you determine that `fopen` returns null. – asveikau Jul 26 '12 at 18:41
  • if a plain fopen fails for any file, you're doing something wrong, fopen() should open all types of files. –  Jul 26 '12 at 18:42
  • 1
    You're probably passing the wrong filename to fopen. Common mistakes include: 1. forgetting to remove the newline after reading a filename from a text file; 2. using backslashes as path separators and forgetting to double them inside a C string; 3. using a filename you got from readdir without prepending the directory or chdir'ing into it. – Alan Curry Jul 26 '12 at 18:46
  • @AlanCurry, that was exactly it. I keep forgetting DOS doesn't let you have file names > 7 or 8 characters, not the first time it has screwed me over. – ardent Jul 26 '12 at 18:48

1 Answers1

2

Q: I was wondering if it is even possible to open, buffer, and pass a .tgz file using C standard libraries and libraries?

Q: Do you want to copy the binary .tgz file as-is? Sure - piece of cake :)

Or do you want to interpret the .tgz file, and then copy its contents?

If the latter, I'd look at "zlib":

Q: Using fopen I get a NULL pointer which tells me that a .tgz file isn't a binary file

A: That tells you no such thing! You should be able to "fopen()" any file ... as long as it exists, and as long as you have the correct permissions.

Use "perror()" to find out what the underlying error was.

paulsm4
  • 114,292
  • 17
  • 138
  • 190
  • see my comment to Alan Curry, I will accept this answer because it was my own goof. Upvoted for now. – ardent Jul 26 '12 at 18:49