Cnippets: A Melange of Drop-in C Code

description

THIS IS OLD CODE AND NO LONGER MAINTAINED.

Cnippets is just a repository for odds-and-ends; for C code that is used in several projects and which needs its own space to grow and mature. Particular functions from one project will be re-tooled for more general semantics and kept here.

popenve: popenl(3) with execve(2) family semantics. Also includes shell-style redirection. Ex: FILE *fp = popenl("/bin/ls","ls","/tmp",NULL,"2>/dev/null >%s","/tmp/ls.out");

pool: Pool is a fixed-size object memory pool. Much more convenient than allocating an array and managing a linked-list by-hand. Plus, it can grow and shrink.

hash: Hash is a generic hash implementation. You define the key and provide functions to operate on the key, i.e. key_fill(), key_cmp(), key_index(). Therefore, the actual interface to the hash is very intuitive and fits well into any application. All the boring stuff like memory management is handled behind-the-scenes.

snprintx(3): Snprintx is a simple hex print library.

cleanname(1)/cleanname(3): Cleanname is similar to realpath(3), except it is lexical only. Identical to Plan 9's cleanname(1) (shell) and cleanname(2) (C API). Cleanname will resolve dot-dot-dirs and dot-dirs, and remove multiple and trailing slashes. Also provided is abspath(), which will return an absolute, "rooted" path.

fd2path(3): fd2path returns the path-- fixed-up using cleanname() and abspath()-- used to get a descriptor from open(). It is identical to the Plan 9 version, except the return value is the logical length of the string should it fit into the provided buffer (much like snprintf()). fd2path provides wrappers for open(2), close(2), opendir(3) and closedir(3); uses dlsym(3) to manually call the system functions; and so must be linked with libdl (e.g. cc -ldl).

regmatch2strv(3): regmatch2strv returns a vector of C-strings from the input string and the regmatch_t array as returned from regexec(3). Use free(3) to free the vector.

faucet(1): Feeds output from the given command through a named pipe. Does not prevent race conditions when multiple processes access the named pipe simultaneously, but keeps the state of the named pipe consistent across multiple, serial invocations of the given command (i.e. if a process locks up while reading from the pipe, other processes can still read new data from it).

relay(1): Relays data from stdin or a named pipe to another named pipe.

drain(1): Drains a named pipe of stale data.

tempnam(1): shell utility mimicking tempnam(3).

license

Copyright (c) 2002, 2003 William Ahern

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

source

git clone http://25thandClement.com/~william/projects/cnippets.git

The Makefile can be used to compile testing/debugging application for each utility. E.g. `make hash'. Cleanname will actually compile to a shell utility ready for use, similar to Plan 9's shell version.

contributions

If you find this work useful, show your gratitude by giving back to the community.

other projects

airctl | bsdauth | cnippets | libarena | libevnet | authldap | streamlocal | libnostd | zoned | dns.c | delegate.c | llrb.h | lpegk | json.c | cqueues | siphash.h | hexdump.c | timeout.c | luapath | luaossl | lunix | phf | runlua | tarsum | prosody-openbsd | AnonNet