Mercurial > hg > octave-kai > gnulib-hg
annotate lib/unistr/u8-mblen.c @ 17429:88b6febaed97
tests: port large-fd POSIX spawn tests to OS X
Problem reported by Daiki Ueno in
<http://lists.gnu.org/archive/html/bug-gnulib/2013-06/msg00031.html>.
* tests/test-posix_spawn_file_actions_addclose.c:
* tests/test-posix_spawn_file_actions_adddup2.c:
* tests/test-posix_spawn_file_actions_addopen.c:
Include <limits.h>, for OPEN_MAX, if available.
(big_fd): New static function.
(main): Use it.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Tue, 11 Jun 2013 00:10:21 -0700 |
parents | e542fd46ad6f |
children |
rev | line source |
---|---|
7819
cfb404074993
New modules 'unistr/u8-mblen', 'unistr/u16-mblen', 'unistr/u32-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
1 /* Look at first character in UTF-8 string. |
17249
e542fd46ad6f
maint: update all copyright year number ranges
Eric Blake <eblake@redhat.com>
parents:
16201
diff
changeset
|
2 Copyright (C) 1999-2000, 2002, 2006-2007, 2009-2013 Free Software |
12559
c2cbabec01dd
update nearly all FSF copyright year lists to include 2010
Jim Meyering <meyering@redhat.com>
parents:
12518
diff
changeset
|
3 Foundation, Inc. |
7819
cfb404074993
New modules 'unistr/u8-mblen', 'unistr/u16-mblen', 'unistr/u32-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
4 Written by Bruno Haible <bruno@clisp.org>, 2002. |
cfb404074993
New modules 'unistr/u8-mblen', 'unistr/u16-mblen', 'unistr/u32-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
5 |
9307
ad8a75a45dc9
Change copyright notice from LGPLv2.0+ to LGPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8507
diff
changeset
|
6 This program is free software: you can redistribute it and/or modify it |
ad8a75a45dc9
Change copyright notice from LGPLv2.0+ to LGPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8507
diff
changeset
|
7 under the terms of the GNU Lesser General Public License as published |
ad8a75a45dc9
Change copyright notice from LGPLv2.0+ to LGPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8507
diff
changeset
|
8 by the Free Software Foundation; either version 3 of the License, or |
ad8a75a45dc9
Change copyright notice from LGPLv2.0+ to LGPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8507
diff
changeset
|
9 (at your option) any later version. |
7819
cfb404074993
New modules 'unistr/u8-mblen', 'unistr/u16-mblen', 'unistr/u32-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
10 |
cfb404074993
New modules 'unistr/u8-mblen', 'unistr/u16-mblen', 'unistr/u32-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
11 This program is distributed in the hope that it will be useful, |
cfb404074993
New modules 'unistr/u8-mblen', 'unistr/u16-mblen', 'unistr/u32-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
12 but WITHOUT ANY WARRANTY; without even the implied warranty of |
cfb404074993
New modules 'unistr/u8-mblen', 'unistr/u16-mblen', 'unistr/u32-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
9307
ad8a75a45dc9
Change copyright notice from LGPLv2.0+ to LGPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8507
diff
changeset
|
14 Lesser General Public License for more details. |
7819
cfb404074993
New modules 'unistr/u8-mblen', 'unistr/u16-mblen', 'unistr/u32-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
15 |
9307
ad8a75a45dc9
Change copyright notice from LGPLv2.0+ to LGPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8507
diff
changeset
|
16 You should have received a copy of the GNU Lesser General Public License |
ad8a75a45dc9
Change copyright notice from LGPLv2.0+ to LGPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8507
diff
changeset
|
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
7819
cfb404074993
New modules 'unistr/u8-mblen', 'unistr/u16-mblen', 'unistr/u32-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
18 |
cfb404074993
New modules 'unistr/u8-mblen', 'unistr/u16-mblen', 'unistr/u32-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
19 #include <config.h> |
cfb404074993
New modules 'unistr/u8-mblen', 'unistr/u16-mblen', 'unistr/u32-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
20 |
cfb404074993
New modules 'unistr/u8-mblen', 'unistr/u16-mblen', 'unistr/u32-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
21 /* Specification. */ |
cfb404074993
New modules 'unistr/u8-mblen', 'unistr/u16-mblen', 'unistr/u32-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
22 #include "unistr.h" |
cfb404074993
New modules 'unistr/u8-mblen', 'unistr/u16-mblen', 'unistr/u32-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
23 |
cfb404074993
New modules 'unistr/u8-mblen', 'unistr/u16-mblen', 'unistr/u32-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
24 int |
cfb404074993
New modules 'unistr/u8-mblen', 'unistr/u16-mblen', 'unistr/u32-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
25 u8_mblen (const uint8_t *s, size_t n) |
cfb404074993
New modules 'unistr/u8-mblen', 'unistr/u16-mblen', 'unistr/u32-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
26 { |
cfb404074993
New modules 'unistr/u8-mblen', 'unistr/u16-mblen', 'unistr/u32-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
27 if (n > 0) |
cfb404074993
New modules 'unistr/u8-mblen', 'unistr/u16-mblen', 'unistr/u32-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
28 { |
13861 | 29 /* Keep in sync with unistr.h and u8-mbtouc-aux.c. */ |
7819
cfb404074993
New modules 'unistr/u8-mblen', 'unistr/u16-mblen', 'unistr/u32-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
30 uint8_t c = *s; |
cfb404074993
New modules 'unistr/u8-mblen', 'unistr/u16-mblen', 'unistr/u32-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
31 |
cfb404074993
New modules 'unistr/u8-mblen', 'unistr/u16-mblen', 'unistr/u32-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
32 if (c < 0x80) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9307
diff
changeset
|
33 return (c != 0 ? 1 : 0); |
7819
cfb404074993
New modules 'unistr/u8-mblen', 'unistr/u16-mblen', 'unistr/u32-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
34 if (c >= 0xc2) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9307
diff
changeset
|
35 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9307
diff
changeset
|
36 if (c < 0xe0) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9307
diff
changeset
|
37 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9307
diff
changeset
|
38 if (n >= 2 |
7819
cfb404074993
New modules 'unistr/u8-mblen', 'unistr/u16-mblen', 'unistr/u32-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
39 #if CONFIG_UNICODE_SAFETY |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9307
diff
changeset
|
40 && (s[1] ^ 0x80) < 0x40 |
7819
cfb404074993
New modules 'unistr/u8-mblen', 'unistr/u16-mblen', 'unistr/u32-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
41 #endif |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9307
diff
changeset
|
42 ) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9307
diff
changeset
|
43 return 2; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9307
diff
changeset
|
44 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9307
diff
changeset
|
45 else if (c < 0xf0) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9307
diff
changeset
|
46 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9307
diff
changeset
|
47 if (n >= 3 |
7819
cfb404074993
New modules 'unistr/u8-mblen', 'unistr/u16-mblen', 'unistr/u32-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
48 #if CONFIG_UNICODE_SAFETY |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9307
diff
changeset
|
49 && (s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9307
diff
changeset
|
50 && (c >= 0xe1 || s[1] >= 0xa0) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9307
diff
changeset
|
51 && (c != 0xed || s[1] < 0xa0) |
7819
cfb404074993
New modules 'unistr/u8-mblen', 'unistr/u16-mblen', 'unistr/u32-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
52 #endif |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9307
diff
changeset
|
53 ) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9307
diff
changeset
|
54 return 3; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9307
diff
changeset
|
55 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9307
diff
changeset
|
56 else if (c < 0xf8) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9307
diff
changeset
|
57 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9307
diff
changeset
|
58 if (n >= 4 |
7819
cfb404074993
New modules 'unistr/u8-mblen', 'unistr/u16-mblen', 'unistr/u32-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
59 #if CONFIG_UNICODE_SAFETY |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9307
diff
changeset
|
60 && (s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9307
diff
changeset
|
61 && (s[3] ^ 0x80) < 0x40 |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9307
diff
changeset
|
62 && (c >= 0xf1 || s[1] >= 0x90) |
7819
cfb404074993
New modules 'unistr/u8-mblen', 'unistr/u16-mblen', 'unistr/u32-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
63 #if 1 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9307
diff
changeset
|
64 && (c < 0xf4 || (c == 0xf4 && s[1] < 0x90)) |
7819
cfb404074993
New modules 'unistr/u8-mblen', 'unistr/u16-mblen', 'unistr/u32-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
65 #endif |
cfb404074993
New modules 'unistr/u8-mblen', 'unistr/u16-mblen', 'unistr/u32-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
66 #endif |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9307
diff
changeset
|
67 ) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9307
diff
changeset
|
68 return 4; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9307
diff
changeset
|
69 } |
7819
cfb404074993
New modules 'unistr/u8-mblen', 'unistr/u16-mblen', 'unistr/u32-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
70 #if 0 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9307
diff
changeset
|
71 else if (c < 0xfc) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9307
diff
changeset
|
72 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9307
diff
changeset
|
73 if (n >= 5 |
7819
cfb404074993
New modules 'unistr/u8-mblen', 'unistr/u16-mblen', 'unistr/u32-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
74 #if CONFIG_UNICODE_SAFETY |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9307
diff
changeset
|
75 && (s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9307
diff
changeset
|
76 && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9307
diff
changeset
|
77 && (c >= 0xf9 || s[1] >= 0x88) |
7819
cfb404074993
New modules 'unistr/u8-mblen', 'unistr/u16-mblen', 'unistr/u32-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
78 #endif |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9307
diff
changeset
|
79 ) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9307
diff
changeset
|
80 return 5; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9307
diff
changeset
|
81 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9307
diff
changeset
|
82 else if (c < 0xfe) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9307
diff
changeset
|
83 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9307
diff
changeset
|
84 if (n >= 6 |
7819
cfb404074993
New modules 'unistr/u8-mblen', 'unistr/u16-mblen', 'unistr/u32-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
85 #if CONFIG_UNICODE_SAFETY |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9307
diff
changeset
|
86 && (s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9307
diff
changeset
|
87 && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9307
diff
changeset
|
88 && (s[5] ^ 0x80) < 0x40 |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9307
diff
changeset
|
89 && (c >= 0xfd || s[1] >= 0x84) |
7819
cfb404074993
New modules 'unistr/u8-mblen', 'unistr/u16-mblen', 'unistr/u32-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
90 #endif |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9307
diff
changeset
|
91 ) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9307
diff
changeset
|
92 return 6; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9307
diff
changeset
|
93 } |
7819
cfb404074993
New modules 'unistr/u8-mblen', 'unistr/u16-mblen', 'unistr/u32-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
94 #endif |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9307
diff
changeset
|
95 } |
7819
cfb404074993
New modules 'unistr/u8-mblen', 'unistr/u16-mblen', 'unistr/u32-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
96 } |
cfb404074993
New modules 'unistr/u8-mblen', 'unistr/u16-mblen', 'unistr/u32-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
97 /* invalid or incomplete multibyte character */ |
cfb404074993
New modules 'unistr/u8-mblen', 'unistr/u16-mblen', 'unistr/u32-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
98 return -1; |
cfb404074993
New modules 'unistr/u8-mblen', 'unistr/u16-mblen', 'unistr/u32-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
99 } |