1 // Compare given libc name and version number to system name and version.
4 // - 0 if the libc name matches is at least the minimum version (if given).
5 // - 1 if the libc name doesn't match or the version is lower than requested.
6 // - 2 if the requested libc name isn't recognised.
7 // - 3 if there was a usage error (it also prints an error message).
14 #include <gnu/libc-version.h>
21 /* Assumes the versions are x.y.z, with y and z optional. */
22 static __attribute__((unused
)) Bool
matches_version(char *min_version
) {
23 int a1
=0, a2
=0, a3
=0, g1
=0, g2
=0, g3
=0; // 'a' = actual; 'g' = given
26 if (min_version
== NULL
) return True
; // no version specified
28 // get actual version number
30 aversion
= gnu_get_libc_version();
34 // We expect at least one number.
35 if (sscanf(aversion
, "%d.%d.%d", &a1
, &a2
, &a3
) < 1) return False
;
37 // parse given version number.
38 if (sscanf(min_version
, "%d.%d.%d", &g1
, &g2
, &g3
) < 1) return False
;
40 if (a1
> g1
) return True
;
41 if (a1
< g1
) return False
;
42 if (a2
> g2
) return True
;
43 if (a2
< g2
) return False
;
44 if (a3
>= g3
) return True
;
49 static Bool
go(char* libc
, char *min_version
)
52 if ( 0 == strcmp( libc
, "glibc" )
53 && matches_version( min_version
))
60 //---------------------------------------------------------------------------
62 //---------------------------------------------------------------------------
63 int main(int argc
, char **argv
)
66 fprintf( stderr
, "usage: libc_test <libc-name> [<min-version>]\n" );
67 exit(3); // Usage error.
69 if (go( argv
[1], argv
[2] )) {
73 if ( 0 == strcmp ( argv
[1], "glibc" ) ) {
74 return 1; // Requested libc name known, but this isn't it.
75 // Or it wasn't the minimum requested version.
77 return 2; // Didn't match any known libc name.