libgo: update to Go 1.11
[official-gcc.git] / libgo / go / strings / indexbyte.c
blob27f4240b44c0390d3dcb63beeb3a5e7ff790ff93
1 /* indexbyte.c -- implement strings.IndexByte for Go.
3 Copyright 2013 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 <stddef.h>
9 #include "runtime.h"
10 #include "go-string.h"
12 /* This is in C so that the compiler can optimize it appropriately.
13 We deliberately don't split the stack in case it does call the
14 library function, which shouldn't need much stack space. */
16 intgo IndexByte (String, char)
17 __asm__ (GOSYM_PREFIX "strings.IndexByte")
18 __attribute__ ((no_split_stack));
20 intgo
21 IndexByte (String s, char b)
23 const char *p;
25 p = __builtin_memchr ((const char *) s.str, b, s.len);
26 if (p == NULL)
27 return -1;
28 return p - (const char *) s.str;