X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Ffreeglut_misc.c;h=9d44470b7b428cfdcc237524279a9d51c16cdcf1;hb=fd025d3915f90c5af286ade32f25a0922644b177;hp=496ca4550e36cfd95f3f8aba5039673ba5471ccd;hpb=646676b8dbf8ab504ac8a275fe9a63a403a3190b;p=freeglut diff --git a/src/freeglut_misc.c b/src/freeglut_misc.c index 496ca45..9d44470 100644 --- a/src/freeglut_misc.c +++ b/src/freeglut_misc.c @@ -50,9 +50,8 @@ */ int FGAPIENTRY glutExtensionSupported( const char* extension ) { - const char *extensions; - const char *ptr; - int len = strlen ( extension ) ; + const char *extensions, *start; + const int len = strlen( extension ) ; /* * Make sure there is a current window, and thus -- a current context available @@ -61,41 +60,30 @@ int FGAPIENTRY glutExtensionSupported( const char* extension ) freeglut_return_val_if_fail( fgStructure.Window != NULL, 0 ); /* - * Note it is safe to query the extensions + * Check if the extension itself looks valid (contains no spaces) */ - extensions = glGetString(GL_EXTENSIONS); - - freeglut_return_val_if_fail( extensions != NULL, 0 ); + if (strchr(extension, ' ')) + return 0; /* - * Check if the extension itself looks valid + * Note it is safe to query the extensions */ - if ( strchr ( extension, ' ' ) != NULL ) - return( 0 ); + start = extensions = (const char *) glGetString(GL_EXTENSIONS); - /* - * Look for our extension + /* XXX consider printing a warning to stderr that there's no current + * rendering context. */ - for (ptr = extensions; *ptr;) - { - /* - * Is it the current extension? - */ - if ( strncmp ( extension, extensions, len ) == 0 ) - return 1 ; - - /* - * No, go find the next extension. They are separated from each other by one or more blank spaces. - */ - ptr = strchr ( ptr + len, ' ' ) ; - - /* - * If we ran off the end of the "extensions" character string, we didn't find it. Return failure. - */ - if ( !ptr ) return 0 ; + freeglut_return_val_if_fail( extensions != NULL, 0 ); - while ( *ptr == ' ' ) - ptr++ ; + while (1) { + const char *p = strstr(extensions, extension); + if (!p) + return 0; /* not found */ + /* check that the match isn't a super string */ + if ((p == start || p[-1] == ' ') && (p[len] == ' ' || p[len] == 0)) + return 1; + /* skip the false match and continue */ + extensions = p + len; } return 0 ;