# Znv: a totally compatible port of FreeBSD's nv library

**URL:** <https://ziggit.dev/t/znv-a-totally-compatible-port-of-freebsds-nv-library/18307>\
**Category:** Showcase\
**Tags:** llm\
**Created:** [November 10, 2026, 11:13pm UTC](https://ziggit.dev/t/znv-a-totally-compatible-port-of-freebsds-nv-library/18307 "2026-11-10T23:13:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![krasenyp](https://ziggit.dev/letter_avatar_proxy/v4/letter/k/aca169/32.png) [@krasenyp](https://ziggit.dev/u/krasenyp)\
**Post date:** [November 10, 2026, 11:13pm UTC](https://ziggit.dev/t/znv-a-totally-compatible-port-of-freebsds-nv-library/18307/1 "2026-11-10T23:13:03Z")

</div>

## znv

znv is a totally compatible Zig port of FreeBSD’s [nv](https://man.freebsd.org/cgi/man.cgi?query=libnv) library. As the original, znv is FreeBSD-only and will continue to be for the foreseeable future.

> The **nv** library permits creating and managing name value pairs as well as sending and receiving them over sockets.

Some of the notable features and divergences are:

- **Byte-identical packed output**  
Ensured by a specific test suite which uses the system nv.
- **Descriptors are duplicated when unpacking**  
A maliciously crafted buffer can’t cause double free.
- **No more `errno` and bailing**  
Idiomatic Zig is used for error handling.
- **Diagnostics on failures**  
Currently opt-in and only for unpacking.
- **Allocators and IO**  
Bring your own and reap the benefits.
- **Smaller surface**  
`dnv.h` and `cnv.h` are obsolete because we have simpler APIs.
- **Performance**  
znv is generally faster but for unpacking large list it’s _blazingly_ faster. Run `zig build bench` to see for yourself.

The library is available [here](https://git.sr.ht/~krasenp/znv). You might want to head to the “Surface coverage” section to see how the original API maps to the new and improved one.

Library documentation is available [here](https://krasenp.srht.site/znv/).

My long-term vision is to use znv as a platform to also port [casper](https://man.freebsd.org/cgi/man.cgi?query=libcasper&apropos=0&sektion=0&manpath=FreeBSD+15.1-RELEASE+and+Ports.quarterly&format=html) and make Zig a very ergonomic choice for writing sandboxed programs on FreeBSD.

### Supported Zig versions

Version 0.17.0 and onwards.

### AI / LLM usage disclosure

> I was familiar with the source code of the nv library but not as intimately as needed for this port so I used AI to help me research it properly.
