Unix system programming - unzipping a file programmatically - c

What I need to do is unzip a file, (.gz or .z), read the first line and do some stuff according to the first line read. But the C standard library doesn't seem to offer a way to do this.
Is the a platform-independent way to do it?

Use "zlib", the library that performs compression and decompression:
http://www.zlib.net/
It's included in the base of all Unix distributions, and you can easily link your program against it for the windows version and ship the DLL.

The info-zip libraries are quite portable.

if you want to platform-independent, you'd have to have the unzipping code in your program. Likely, you'd want to link against a third-party library, such as ZLib which is standard on Unix systems, or use the DLL when on Windows.
The rest is pretty simple: use ZLib to unzip the file to a temporary location, read the file as normal, then remove the file when you're done.

Related

decompressing tar.gz in rtems operating system

I was wondering if there was a specific set of library that can decompress tar.gz files in an rtems operating system. Most of the answer I seen is for linux. I was looking at gzip and libz but was not sure if these were for linux or can I use them for rtems as well.
There are some integrated functions that can extract tgz files in RTEMS. Take a look at the tar01 test for some examples with different sources (memory or file): https://git.rtems.org/rtems/tree/testsuites/libtests/tar01/init.c?id=8d989c56ff0c65beb7ec3390aebef6ea52840fab
Note that this is a test application intended to test the functionality. So some things might try to trigger expected failures. The test tar file is automatically generated by the Makefile, translated into some object file and linked into the application.
There is also the tarfs that can use a tar (not sure about tgz) as a read only file system. It's used in tar02 test.
Regarding libz: Although I haven't tried I would expect that it is possible to compile libz for RTEMS. If you need specifically that library you might want to ask on the RTEMS users mailing list whether someone already did that. There are a lot more RTEMS specific users and developers than on stackoverflow.

Cross-Platform API to monitor file system in C?

I'm looking for a cross platform library to detect when files in a directory are added or modified.
I know there are OS specific way to do this (inotify for Linux, FindFirstChangeNotification for windows, etc...).
But is there a platform independent library that works specifically in C? (Like the QFileSystemWatcher in C++)
inotify is Linux specific, if you want some UNIX portable features you are pobably looking for something like libfam. it is name of library. Full package name is fileschanged.
fileschanged is a GNU/Linux command-line utility that reports when files have been altered.
It's now 2021 so maybe septag/dmon is your cup of tea.
From the description:
Single header C99 portable library for monitoring directory changes
... or maybe the more beefy fswatch ?
Sounds like a good use case for golang.
Simply change $GOOS and/or $GOARCH and run go build.
Boom - trivial cross-platform development.

How convert file. a to .c or other extension? I need read file .a

Good day, I am working with Codeblock IDE under Windows in C language and I got the static library in file ".a" with the development of some functions. I must see somehow the code of the functions in the file because i need.
I was reading a lot on the forum but I could not solve my doubt.
someone could help? Tanks!!
(People said that this should be an answer, so here it is!)
*.a files are compiled libraries on Windows (the file extension is different on different operating systems). You can't see the source code unless you decompile it (which is very hard or impossible).
(From another comment) However, if the library is from an open-source project, then you might be able to find the source code.

1- Make a library in C 2- Call and use it in MASM

The teacher asked to do the two tasks given in the title,and the only hint he gave is that the library file will have extension ".lib" . I have tried to make a static library using Code Blocks, and it has ".a" extension instead of .lib. Now how do I call and use this library in MASM, I have no idea. Please Help!
A .a file is a static library on Linux / UNIX. Code Blocks is cross-platform, but often found on Linux, so I wouldn't be surprised if you were running it there.
A .lib file is a static library on Windows. MASM is the Microsoft (Windows) assembler.
You're not using the right toolchain for your platform. Or potentially, you're not even working on the right platform.

C library to read from zip archives

Is there a portable C library to access .zip archives? "gzip" or "zlib" (the closest I could find) only handle compressed data, I need to be able to list the files inside the archive, and access each one individually, and if they're compressed using the 'deflate' method, I can use zlib on it.
Minizip, maybe?
http://www.winimage.com/zLibDll/minizip.html
The zip that comes with Linux and BSD is actually called info-ZIP which is here. Personally I have not tried such a thing but the info-zip front page states "Info-ZIP's primary compression engine has also been spun off into the free zlib compression library", so you might want to check out zlib. The zlib page has a FAQ with a answer to your specific question. I would start by studying how info-zip works. Good luck.
7-zip has a complete SDK, with example sources, and a lot of functionality.
take a look here

Resources