Created
October 16, 2014 15:02
-
-
Save cpq/2ccc4de53f640e17a598 to your computer and use it in GitHub Desktop.
Extensible C API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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