powerpc: Remove power4 mpa optimization
[glibc.git] / inet / inet6_scopeid_pton.c
blob2d00ae5b6a2bc8111dbc7fc6a767ba828b7bdece
1 /* Convert an IPv6 scope ID from text to the internal representation.
2 Copyright (C) 2016-2019 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 #include <net-internal.h>
21 #include <ctype.h>
22 #include <errno.h>
23 #include <locale.h>
24 #include <net/if.h>
25 #include <stdbool.h>
26 #include <stdint.h>
27 #include <stdlib.h>
29 /* Parse SOURCE as a scope ID for ADDRESS. Return 0 on success and -1
30 on error. */
31 int
32 __inet6_scopeid_pton (const struct in6_addr *address, const char *scope,
33 uint32_t *result)
35 if (IN6_IS_ADDR_LINKLOCAL (address)
36 || IN6_IS_ADDR_MC_NODELOCAL (address)
37 || IN6_IS_ADDR_MC_LINKLOCAL (address))
39 uint32_t number = __if_nametoindex (scope);
40 if (number != 0)
42 *result = number;
43 return 0;
47 if (isdigit_l (scope[0], _nl_C_locobj_ptr))
49 char *end;
50 unsigned long long number
51 = ____strtoull_l_internal (scope, &end, /*base */ 10, /* group */ 0,
52 _nl_C_locobj_ptr);
53 if (*end == '\0' && number <= UINT32_MAX)
55 *result = number;
56 return 0;
60 __set_errno (EINVAL);
61 return -1;
64 libc_hidden_def (__inet6_scopeid_pton)