Retro68/gcc/libgo/runtime/go-strcmp.c

26 lines
510 B
C
Raw Normal View History

2012-03-27 23:13:14 +00:00
/* go-strcmp.c -- the go string comparison function.
Copyright 2009 The Go Authors. All rights reserved.
Use of this source code is governed by a BSD-style
license that can be found in the LICENSE file. */
2014-09-21 17:33:12 +00:00
#include "runtime.h"
2012-03-27 23:13:14 +00:00
2014-09-21 17:33:12 +00:00
intgo
__go_strcmp(String s1, String s2)
2012-03-27 23:13:14 +00:00
{
int i;
2014-09-21 17:33:12 +00:00
i = __builtin_memcmp(s1.str, s2.str,
(s1.len < s2.len ? s1.len : s2.len));
2012-03-27 23:13:14 +00:00
if (i != 0)
return i;
2014-09-21 17:33:12 +00:00
if (s1.len < s2.len)
2012-03-27 23:13:14 +00:00
return -1;
2014-09-21 17:33:12 +00:00
else if (s1.len > s2.len)
2012-03-27 23:13:14 +00:00
return 1;
else
return 0;
}