Skip to content

Commit

Permalink
implement strcasestr since mingw doesn't have it
Browse files Browse the repository at this point in the history
  • Loading branch information
notsecure committed Aug 11, 2014
1 parent b135588 commit 01696f3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
3 changes: 1 addition & 2 deletions main.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#ifndef MAIN_H
#define MAIN_H

#define _GNU_SOURCE

#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
Expand All @@ -11,6 +9,7 @@
#include <string.h>
#include <math.h>
#include <limits.h>
#include <ctype.h>

#include <tox/tox.h>
#include <tox/toxav.h>
Expand Down
20 changes: 20 additions & 0 deletions util.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,26 @@ void* file_raw(char *path, uint32_t *size)
return data;
}

_Bool strcasestr(const char *a, const char *b)
{
const char *c = b;
while(*a) {
if(tolower(*a) != tolower(*c)) {
c = b;
}

if(tolower(*a) == tolower(*c)) {
c++;
if(!*c) {
return 1;
}
}
a++;
}

return 0;
}

static void to_hex(char_t *a, char_t *p, int size)
{
char_t b, c, *end = p + size;
Expand Down
3 changes: 3 additions & 0 deletions util.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
*/
void* file_raw(char *path, uint32_t *size);

/* returns non-zero if substring is found */
_Bool strcasestr(const char *a, const char *b);

/* convert tox id to string
* notes: dest must be (TOX_FRIEND_ADDRESS_SIZE * 2) bytes large, src must be TOX_FRIEND_ADDRESS_SIZE bytes large
*/
Expand Down

0 comments on commit 01696f3

Please sign in to comment.