make string_compare_guy better

This commit is contained in:
Christine Dodrill 2015-06-19 16:00:17 -07:00
parent a06304f577
commit 39c986666f
2 changed files with 5 additions and 7 deletions

View File

@ -9,7 +9,7 @@ GOFLAGS += -g
GOFLAGS += -O3
CFLAGS += -Wall
#CFLAGS += -Werror
CFLAGS += -Werror
!nim = |> ^ Nim: %f -> %o^ nim c $(NIMFLAGS) -o:%o %f && rm -rf .nimcache |>
!gccgo = |> ^ GCCGo: %f -> %o^ gccgo $(GOFLAGS) -o %o %f |>

View File

@ -1,23 +1,21 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
// 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
// side (haystack).
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);
lnz[llength] = 0;
char* rnz = malloc(rlength + 1);
char* rnz = alloca(rlength + 1);
memcpy(rnz, rhs, rlength);
rnz[rlength] = 0;
int result = strstr(lnz, rhs);
free(lnz);
free(rnz);
int result = (intptr_t) strstr(lnz, rhs);
return result;
}