annotate lib/mbstok_r.c @ 15727:144db791c6fa

Ensure EBADF returns for socket functions on mingw. * lib/accept.c (rpl_accept): Fail with error EBADF if the file descriptor is invalid. * lib/bind.c (rpl_bind): Likewise. * lib/connect.c (rpl_connect): Likewise. * lib/getpeername.c (rpl_getpeername): Likewise. * lib/getsockname.c (rpl_getsockname): Likewise. * lib/getsockopt.c (rpl_getsockopt): Likewise. * lib/listen.c (rpl_listen): Likewise. * lib/recv.c (rpl_recv): Likewise. * lib/recvfrom.c (rpl_recvfrom): Likewise. * lib/send.c (rpl_send): Likewise. * lib/sendto.c (rpl_sendto): Likewise. * lib/setsockopt.c (rpl_setsockopt): Likewise. * lib/shutdown.c (rpl_shutdown): Likewise.
author Bruno Haible <bruno@clisp.org>
date Wed, 21 Sep 2011 00:20:59 +0200
parents 97fc9a21a8fb
children 8250f2777afc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8106
2ff19298dd56 New module 'mbstok_r'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Tokenizing a string.
14079
97fc9a21a8fb maint: update almost all copyright ranges to include 2011
Jim Meyering <meyering@redhat.com>
parents: 12559
diff changeset
2 Copyright (C) 1999, 2002, 2006-2011 Free Software Foundation, Inc.
8106
2ff19298dd56 New module 'mbstok_r'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3 Written by Bruno Haible <bruno@clisp.org>, 2007.
2ff19298dd56 New module 'mbstok_r'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8106
diff changeset
5 This program is free software: you can redistribute it and/or modify
8106
2ff19298dd56 New module 'mbstok_r'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 it under the terms of the GNU General Public License as published by
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8106
diff changeset
7 the Free Software Foundation; either version 3 of the License, or
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8106
diff changeset
8 (at your option) any later version.
8106
2ff19298dd56 New module 'mbstok_r'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9
2ff19298dd56 New module 'mbstok_r'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 This program is distributed in the hope that it will be useful,
2ff19298dd56 New module 'mbstok_r'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
2ff19298dd56 New module 'mbstok_r'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2ff19298dd56 New module 'mbstok_r'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13 GNU General Public License for more details.
2ff19298dd56 New module 'mbstok_r'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14
2ff19298dd56 New module 'mbstok_r'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 You should have received a copy of the GNU General Public License
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8106
diff changeset
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
8106
2ff19298dd56 New module 'mbstok_r'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17
2ff19298dd56 New module 'mbstok_r'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18 #include <config.h>
2ff19298dd56 New module 'mbstok_r'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19
2ff19298dd56 New module 'mbstok_r'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20 /* Specification. */
2ff19298dd56 New module 'mbstok_r'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 #include <string.h>
2ff19298dd56 New module 'mbstok_r'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22
10954
a0bbe1a6f787 Remove HAVE_MBRTOWC conditionals. Use mbrtowc unconditionally.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
23 #include "mbuiter.h"
8106
2ff19298dd56 New module 'mbstok_r'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24
2ff19298dd56 New module 'mbstok_r'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 char *
2ff19298dd56 New module 'mbstok_r'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 mbstok_r (char *string, const char *delim, char **save_ptr)
2ff19298dd56 New module 'mbstok_r'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 {
2ff19298dd56 New module 'mbstok_r'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 if (MB_CUR_MAX > 1)
2ff19298dd56 New module 'mbstok_r'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 {
2ff19298dd56 New module 'mbstok_r'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 if (string == NULL)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10954
diff changeset
31 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10954
diff changeset
32 string = *save_ptr;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10954
diff changeset
33 if (string == NULL)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10954
diff changeset
34 return NULL; /* reminder that end of token sequence has been
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10954
diff changeset
35 reached */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10954
diff changeset
36 }
8106
2ff19298dd56 New module 'mbstok_r'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37
2ff19298dd56 New module 'mbstok_r'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 /* Skip leading delimiters. */
2ff19298dd56 New module 'mbstok_r'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 string += mbsspn (string, delim);
2ff19298dd56 New module 'mbstok_r'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40
2ff19298dd56 New module 'mbstok_r'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 /* Found a token? */
2ff19298dd56 New module 'mbstok_r'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 if (*string == '\0')
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10954
diff changeset
43 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10954
diff changeset
44 *save_ptr = NULL;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10954
diff changeset
45 return NULL;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10954
diff changeset
46 }
8106
2ff19298dd56 New module 'mbstok_r'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47
2ff19298dd56 New module 'mbstok_r'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 /* Move past the token. */
2ff19298dd56 New module 'mbstok_r'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 {
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10954
diff changeset
50 char *token_end = mbspbrk (string, delim);
8106
2ff19298dd56 New module 'mbstok_r'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10954
diff changeset
52 if (token_end != NULL)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10954
diff changeset
53 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10954
diff changeset
54 /* NUL-terminate the token. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10954
diff changeset
55 *token_end = '\0';
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10954
diff changeset
56 *save_ptr = token_end + 1;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10954
diff changeset
57 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10954
diff changeset
58 else
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10954
diff changeset
59 *save_ptr = NULL;
8106
2ff19298dd56 New module 'mbstok_r'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60 }
2ff19298dd56 New module 'mbstok_r'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61
2ff19298dd56 New module 'mbstok_r'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62 return string;
2ff19298dd56 New module 'mbstok_r'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63 }
2ff19298dd56 New module 'mbstok_r'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64 else
2ff19298dd56 New module 'mbstok_r'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65 return strtok_r (string, delim, save_ptr);
2ff19298dd56 New module 'mbstok_r'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66 }