Which zlib functions are compatible with WinZip? - c

Using deflate() I was unable to open the zipped file using WinZip. Are the gz() the only ones compatible with WinZip? or is there some sort of mode I must call deflate() with?

from http://www.zlib.net/zlib_faq.html
Can zlib handle .zip archives?
Not by
itself, no. See the directory
contrib/minizip in the zlib
distribution.

zlib only implements the used compression algorithm, not the ZIP file structure. You need to parse the ZIP file yourself and then you can decompress the file chunks with zlib.
Note, that there is no gzip header in the file chunks, so you need to do a "raw inflate". Check the zlib documentation for more details.

Related

cannot find proper file encoding for the libbgi.a file from the graphics library for C

I was trying to open the libbgi.a file from the graphics.h library for C, but I keep getting the error "File was loaded in the wrong encoding". No matter which encoding I use it just wont open properly (https://github.com/SagarGaniga/Graphics-Library)
The file libbgi.a is a precompiled library. This means that it is a binary file, not a text file.
You should not attempt to open a binary file as a text file. There is no text encoding with which you could open it.
Libraries are intended to be passed to the linker when building a program.

How to install C source files and headers?

I've been given these source files and headers. In the README.md the authors explain how to launch the test executables without the need of a proper installation. It is just a make command to run. They explain how to generate the .so files. I think these latter are meant to be used if I wanted to install the APIs at a system level (the definitions should be in api.h). My question is: where should I copy the shared objects generated by the Makefile and the api.h header? I aim to write a source file from scratch where I use those APIs (e.g. crypto_sign()) just including the headers, if it is possible. Thanks
where should I copy the shared objects generated by the Makefile and the api.h header? I aim to write a source file from scratch where I use those APIs (e.g. crypto_sign()) just including the headers, if it is possible
Nowhere.
The project comes with CMake support. Use CMake in your project and just add_subdirectory the repository directory.
Anyway, if you really wish to install the library system-wide, then FHS specifies directory structure on linux. For local system administration use /usr/local/lib for local libraries .so files and /usr/local/include for local C header files.

Static library header file

I am trying to import a static library based on Hierarchical Matrices (H2Lib). The folder contains a make file which compiles the library files, examples and tests into a single .a file. I have referred to tutorials on creating and using static libraries in C using archiver command line in Linux but this does not create a header file, which I had to create manually while working out the tutorial. The H2Lib has multiple files and it would be difficult and time consuming to create a header file manually for this. I am not sure if I am missing something here or doing something wrong; I am new to the concept of libraries in C. Can some one please help me on how to use this library in C?
P.S: git repository link for H2Lib: https://github.com/H2Lib/H2Lib/tree/master
You are not supposed to write the header files yourself. Somewhere on the folder where the library is defined there should be a directory with multiple .h files (the headers) (it's usually named include).
What you need to do is include them into your project. You do this by appending -I to the path of each folder containing the headers and then writing #include "headername.h" in your source code.
So if the headers are in dir/include, you'd do:
gcc yourfiles.c <flags> output.o -I dir/include

What is xutils.h, and what cflags/libs/packages do I need?

I am thinking about maybe creating my own modified version of a GTK2 libwnck widget. In the source files of these widgets, it includes a file called xutils.h. This header file is present in GNOME's libwnck git repository, but it is not present in my distro's libwnck header files.
I have tried searching for an xutils package for Arch Linux, but I cannot find such a package. I also looked in Fedora's libwnck header files, and that does not have an xutils.h file either.
Here are my questions:
What cflags/libs do I need in order to use this header file, or else what packages do I need to install?
Why is the xutils.h file not present in my distro's libwnck header files?
This program should be able to be linked against a distro's stock libraries. Potential users should not be expected to download and compile other libwnck source files.
Please note that the header file I am looking for is called xutils.h (with an "s"), not Xutil.h.
I don't claim to know anything, but a quick google suggests that xutils.h is related to the X11 client side library, and that it comes with the libx11 package on Arch.
This google link xutils.h still hints at an X11 related function, and it is interesting that the guards on the file are WNCK_XUTILS_H

file compression using zlib

Can i use the zlib library function to compress files. I try to do a file compression using "gzopen()" which is actually working with single file with some problems. When i try to decompress the output file using "WinZip" the file extension is not present in the output. For eg. If I compress a file named "test.pdf", the output file name is coming as "test". (the file content is proper. only problem is with the extension)
fi = (gzFile *)gzopen(destfile,"ab");
gzwrite(fi,buff,bufflen);
gzclose(fi);
When i try to compress two different file(eg "test.pdf" and "sample.pdf") only one file came after extraction using "WinZip"("test"). How to use the zlip file to compress more than one file. I think the problem is with header information in the compressed file. Can i use zlib to compress files?.
You can use the -N or --name option to gzip to have it use the filename stored in the gzip file instead of the name of the gzip file.
You cannot use gzip by itself to store multiple files. For a Windows application, I would recommend libzip for multiple files, which encodes and decodes .zip files. libzip uses zlib for the compression and decompression part.
you could use something like http://gnuwin32.sourceforge.net/packages/libarchive.htm to create a tar and the zip it
zlib (the library) and gzip (the utility) doesn't really do any file management. It doesn't have any concept of file names, so normally the gunzip utility just removes the .gz extension from an extracted file. There is no filename data embedded in the gzipped file, it just works off the filename at the time you unzip it.
gzip also doesn't support compressing multiple files together into the same archive. To do that usually you use the tar command to create one file that contains the individual files you want to compress, then gzip the tar file. that's why you'll see archive.tar.gz or archive.tgz a lot. It's a bunch of files in a tar file which has been compressed with gzip.
zlib only does comression it doesn't handle file names, file data, directory layout etc.
Winzip adds all these to the ZLIB protocol. In the zlib distribution there is a contrib library that gives you zip functions

Resources