minitar/README.md

79 lines
3.0 KiB
Markdown
Raw Permalink Normal View History

2022-11-05 17:25:26 +00:00
# minitar
2023-02-04 18:03:55 +00:00
Tiny and easy-to-use C library to read/write tar (specifically, the [ustar](https://www.ibm.com/docs/en/zos/2.3.0?topic=formats-tar-format-tar-archives#taf) variant, which is a bit old but simple, and newer tar variants (pax, GNU tar) are mostly backwards-compatible with it) archives.
2022-11-30 18:25:55 +00:00
2022-12-31 11:57:24 +00:00
No third-party dependencies, only a minimally capable standard C library (pretty much only requires a basic subset of the C FILE API, apart from other simple functions).
2022-11-30 18:25:55 +00:00
2023-02-04 18:03:55 +00:00
Aims to be bloat-free (currently a bit above 500 LoC), fast and optimized, and as portable between systems as possible (has its own implementation of some non-standard functions, such as [strlcpy](https://linux.die.net/man/3/strlcpy) or [basename](https://linux.die.net/man/3/basename)).
2022-11-30 18:25:55 +00:00
Does not include support for compressed archives. You'll have to pass those through another program or library to decompress them before minitar can handle them.
2022-11-05 19:10:48 +00:00
## Example
```c
2022-11-05 19:10:48 +00:00
#include <stdio.h>
#include <minitar.h>
int main(int argc, char** argv)
{
if(argc == 1)
{
fprintf(stderr, "Usage: %s [file]\n", argv[0]);
return 1;
}
struct minitar mp;
if(minitar_open(argv[1], &mp) != 0)
2022-11-05 19:10:48 +00:00
{
perror(argv[1]);
return 1;
}
struct minitar_entry entry;
2022-11-05 19:10:48 +00:00
do {
if(minitar_read_entry(&mp, &entry) == 0) {
printf("%s\n", entry.metadata.path);
} else break;
2023-01-12 19:04:28 +00:00
} while(1);
minitar_close(&mp);
2022-11-05 19:10:48 +00:00
}
```
The output of this example program when running it with an uncompressed tar archive is identical to that of `tar --list -f archive.tar` with the same uncompressed archive. And in most cases, it's faster as well!
2022-11-06 10:06:01 +00:00
See [examples](examples/) for more examples using minitar.
2022-11-23 19:50:40 +00:00
## Project structure
The user-facing API (functions defined in `minitar.h` and documented in [API.md](docs/API.md)) is implemented in `src/tar.c`. Utility and internally-used functions live in `src/util.c`.
2022-11-23 19:50:40 +00:00
## Documentation
2022-11-06 10:06:01 +00:00
2023-01-12 19:45:46 +00:00
See the [build instructions](docs/Build.md) to start using minitar.
See the [API documentation](docs/API.md) for a full description of all functions and types.
2022-11-06 11:11:40 +00:00
## Error handling
When a fatal error occurs, minitar calls the function `minitar_handle_panic()` with a message describing the error.
The default implementation of this function prints the error message out to standard error and aborts.
You might want to handle errors differently. Well, you can override the panic function! Just create a function with the following signature:
`noreturn void minitar_handle_panic(const char* message)`
and put your error handling code in there. This function will automatically override the default one used by minitar.
This function needs to have C linkage and be unmangled. If you're using other languages, this might not be the case, for example, a C++ implementation would need the following signature:
2022-11-06 11:39:17 +00:00
`extern "C" [[noreturn]] void minitar_handle_panic(const char* message)`
and a Rust implementation would need:
```
#[no_mangle]
pub extern "C" fn minitar_handle_panic(message: *const u8) -> !
```
2022-11-06 10:56:40 +00:00
## License
`minitar` is free and open-source software under the [BSD-2-Clause](LICENSE) license.