DR 1402
[official-gcc.git] / libgo / runtime / go-strcmp.c
blob8e6cb1834a28fac9d1563e0dcf4d85d13c8ff158
1 /* go-strcmp.c -- the go string comparison function.
3 Copyright 2009 The Go Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style
5 license that can be found in the LICENSE file. */
7 #include "go-string.h"
9 int
10 __go_strcmp(struct __go_string s1, struct __go_string s2)
12 int i;
14 i = __builtin_memcmp(s1.__data, s2.__data,
15 (s1.__length < s2.__length
16 ? s1.__length
17 : s2.__length));
18 if (i != 0)
19 return i;
21 if (s1.__length < s2.__length)
22 return -1;
23 else if (s1.__length > s2.__length)
24 return 1;
25 else
26 return 0;