Skip to content

Instantly share code, notes, and snippets.

@cpq
Created October 16, 2014 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cpq/2ccc4de53f640e17a598 to your computer and use it in GitHub Desktop.
Save cpq/2ccc4de53f640e17a598 to your computer and use it in GitHub Desktop.
Extensible C API
#define END_OF_PARAMS (-1)
// Each extensible function is going to have it's own params enum
enum {
SEND_FILE_EXTRA_HEADER, // next arg is const char *
SEND_FILE_BYTE_RANGE, // next args are size_t, size_t
SEND_FILE_NUM_PARAMS
};
int mg_send_file(const char *path, ...) {
// ....
}
int main(void) {
mg_send_file("/etc/group", END_OF_PARAMS);
mg_send_file("/etc/group",
PARAM_EXTRA_HEADER, "Foo: bar\r\n",
PARAM_EXTRA_HEADER, "Baz: baz\r\n",
SEND_FILE_BYTE_RANGE, (size_t) 10, (size_t) 20,
END_OF_PARAMS);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment