$nm -AC /usr/lib/libc.*|grep strcasestrflag 'W' means weakly defined. If it is linked with normal code without defining the function(), compiler error is observed saying 'strcasestr() undefined'. The function's declaration could be found in
/usr/lib/libc.a:strcasestr.o:00000000 W strcasestr
I need to compare whether a given string is a sub-string(case-insensitive) of the given string. But the string could be found only at the word begining. The code fragment for the strcasestr() is pasted below.
static gchar* my_strcasestr(gchar *source, gchar *target) {If there is any better way of doing this, pls let me know.
gushort i = 0, len = 0; /* assuming search string length won't be greater than sizeof(gushort) */
guchar after_space = 1;
len = strlen(target);
for (; source[i] != '\0'; i++) {
if(!after_space && source[i] != ' ')
continue;
if(source[i] == ' ') {
after_space = 1;
continue;
}
after_space = 0;
if(!strncasecmp((source+i), target, len))
return (source+i);
}
return NULL;
}
No comments:
Post a Comment
Drop your message here to get in touch with me