mescc: Mes C Library: Prepare for M2-Planet: strncmp.

* lib/string/strncmp.c: Rewrite C-constructs not supported by M2-Planet.
This commit is contained in:
Jan (janneke) Nieuwenhuizen 2020-05-17 19:44:02 +02:00
parent 99e24cd99a
commit b4895d7495
No known key found for this signature in database
GPG key ID: F3C1A0D9C1D65273

View file

@ -1,6 +1,6 @@
/* -*-comment-start: "//";comment-end:""-*- /* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software * GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* *
* This file is part of GNU Mes. * This file is part of GNU Mes.
* *
@ -23,12 +23,15 @@
int int
strncmp (char const *a, char const *b, size_t size) strncmp (char const *a, char const *b, size_t size)
{ {
if (!size) if (size == 0)
return 0; return 0;
while (*a && *b && *a == *b && --size)
while (a[0] != 0 && b[0] != 0 && a[0] == b[0] && size > 1)
{ {
a++; size = size - 1;
b++; a = a + 1;
b = b + 1;
} }
return *a - *b;
return a[0] - b[0];
} }