*/
int FGAPIENTRY glutExtensionSupported( const char* extension )
{
- const char *extensions;
+ const char *extensions, *start;
const char *ptr;
- int len = strlen ( extension ) ;
+ const int len = strlen( extension ) ;
/*
* Make sure there is a current window, and thus -- a current context available
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, ' ' ) ;
-
- /*
- * 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 ;