diff --git a/clibrary.c b/clibrary.c index 9abbf74..f269f45 100644 --- a/clibrary.c +++ b/clibrary.c @@ -450,12 +450,14 @@ void LibStrncpy(struct ParseState *Parser, struct Value *ReturnValue, struct Val void LibStrcmp(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) { - ReturnValue->Val->Integer = strcmp(Param[0]->Val->NativePointer, Param[1]->Val->NativePointer); + int Result = strcmp(Param[0]->Val->NativePointer, Param[1]->Val->NativePointer); + ReturnValue->Val->Integer = (Result > 0) ? 1 : ((Result < 0) ? -1 : 0); } void LibStrncmp(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) { - ReturnValue->Val->Integer = strncmp(Param[0]->Val->NativePointer, Param[1]->Val->NativePointer, Param[2]->Val->Integer); + int Result = strncmp(Param[0]->Val->NativePointer, Param[1]->Val->NativePointer, Param[2]->Val->Integer); + ReturnValue->Val->Integer = (Result > 0) ? 1 : ((Result < 0) ? -1 : 0); } void LibStrcat(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) @@ -490,7 +492,8 @@ void LibMemcpy(struct ParseState *Parser, struct Value *ReturnValue, struct Valu void LibMemcmp(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) { - ReturnValue->Val->Integer = memcmp(Param[0]->Val->NativePointer, Param[1]->Val->NativePointer, Param[2]->Val->Integer); + int Result = memcmp(Param[0]->Val->NativePointer, Param[1]->Val->NativePointer, Param[2]->Val->Integer); + ReturnValue->Val->Integer = (Result > 0) ? 1 : ((Result < 0) ? -1 : 0); } #endif diff --git a/tests/28_strings.expect b/tests/28_strings.expect index 41ee1b2..5e19c73 100644 --- a/tests/28_strings.expect +++ b/tests/28_strings.expect @@ -5,10 +5,10 @@ gollo -1 5 gollo! -6 +1 0 0 --19 +-1 ollo! lo! NULL