make string_compare_guy better
This commit is contained in:
parent
a06304f577
commit
39c986666f
|
@ -9,7 +9,7 @@ GOFLAGS += -g
|
||||||
GOFLAGS += -O3
|
GOFLAGS += -O3
|
||||||
|
|
||||||
CFLAGS += -Wall
|
CFLAGS += -Wall
|
||||||
#CFLAGS += -Werror
|
CFLAGS += -Werror
|
||||||
|
|
||||||
!nim = |> ^ Nim: %f -> %o^ nim c $(NIMFLAGS) -o:%o %f && rm -rf .nimcache |>
|
!nim = |> ^ Nim: %f -> %o^ nim c $(NIMFLAGS) -o:%o %f && rm -rf .nimcache |>
|
||||||
!gccgo = |> ^ GCCGo: %f -> %o^ gccgo $(GOFLAGS) -o %o %f |>
|
!gccgo = |> ^ GCCGo: %f -> %o^ gccgo $(GOFLAGS) -o %o %f |>
|
||||||
|
|
|
@ -1,23 +1,21 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
// string_compare_guy compares the contents of the left hand side, length with the contents of the
|
// string_compare_guy compares the contents of the left hand side, length with the contents of the
|
||||||
// right hand side, length and returns 1 if the right hand side (needle) is inside the left hand
|
// right hand side, length and returns 1 if the right hand side (needle) is inside the left hand
|
||||||
// side (haystack).
|
// side (haystack).
|
||||||
static int string_compare_guy(char* lhs, int llength, char* rhs, int rlength) {
|
static int string_compare_guy(char* lhs, int llength, char* rhs, int rlength) {
|
||||||
char* lnz = malloc(llength + 1);
|
char* lnz = alloca(llength + 1);
|
||||||
memcpy(lnz, lhs, llength);
|
memcpy(lnz, lhs, llength);
|
||||||
lnz[llength] = 0;
|
lnz[llength] = 0;
|
||||||
|
|
||||||
char* rnz = malloc(rlength + 1);
|
char* rnz = alloca(rlength + 1);
|
||||||
memcpy(rnz, rhs, rlength);
|
memcpy(rnz, rhs, rlength);
|
||||||
rnz[rlength] = 0;
|
rnz[rlength] = 0;
|
||||||
|
|
||||||
int result = strstr(lnz, rhs);
|
int result = (intptr_t) strstr(lnz, rhs);
|
||||||
|
|
||||||
free(lnz);
|
|
||||||
free(rnz);
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue