Skip to content

Instantly share code, notes, and snippets.

@deltheil
Created June 7, 2012 12:57
Show Gist options
  • Save deltheil/2888680 to your computer and use it in GitHub Desktop.
Save deltheil/2888680 to your computer and use it in GitHub Desktop.
moreutils (errno): auto-generated errno-s header file via the preprocessor
# Taken from http://joeyh.name/code/moreutils/ Makefile
# See http://blog.liw.fi/posts/errno/ for all the details about `errno` CLI tool
errno.o: errnos.h
errnos.h:
echo '#include <errno.h>' > dump.c
$(CC) -E -dD dump.c | awk '/^#define E/ { printf "{\"%s\",%d},\n", $$2, $$3 }' > errnos.h
rm -f dump.c
# On errno.c side this auto-generated header is used as follow
# --
# static struct {
# const char *name;
# int code;
# } errnos[] = {
# #include "errnos.h"
# };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment