Skip to content

Instantly share code, notes, and snippets.

@RoyBellingan
Created November 16, 2014 21:57
Show Gist options
  • Save RoyBellingan/42d1cd5a974e64ce3367 to your computer and use it in GitHub Desktop.
Save RoyBellingan/42d1cd5a974e64ce3367 to your computer and use it in GitHub Desktop.
fbthrift libevent check
#include <sys/types.h>
#include <event.h>
#include <stdio.h>
int main (){
const char* lib_version = event_get_version();
const char* wnt_version = "2.0";
int lib_digits;
int wnt_digits;
printf("%s",lib_version);
for (;;) {
/* If we reached the end of the want version. We have it. */
if (*wnt_version == '\0' || *wnt_version == '-') {
return 0;
}
/* If the want version continues but the lib version does not, */
/* we are missing a letter. We don't have it. */
if (*lib_version == '\0' || *lib_version == '-') {
return 1;
}
/* In the 1.4 version numbering style, if there are more digits */
/* in one version than the other, that one is higher. */
for (lib_digits = 0;
lib_version[lib_digits] >= '0' &&
lib_version[lib_digits] <= '9';
lib_digits++)
;
for (wnt_digits = 0;
wnt_version[wnt_digits] >= '0' &&
wnt_version[wnt_digits] <= '9';
wnt_digits++)
;
if (lib_digits > wnt_digits) {
return 0;
}
if (lib_digits < wnt_digits) {
return 1;
}
/* If we have greater than what we want. We have it. */
if (*lib_version > *wnt_version) {
return 0;
}
/* If we have less, we don't. */
if (*lib_version < *wnt_version) {
return 1;
}
lib_version++;
wnt_version++;
}
return 0;
;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment