Mercurial > hg > octave-shane > gnulib-hg
annotate lib/stpncpy.c @ 17255:d81be792518a
update from texinfo
author | Karl Berry <karl@freefriends.org> |
---|---|
date | Tue, 01 Jan 2013 15:51:49 -0800 |
parents | e542fd46ad6f |
children | 815194217914 |
rev | line source |
---|---|
17249
e542fd46ad6f
maint: update all copyright year number ranges
Eric Blake <eblake@redhat.com>
parents:
16201
diff
changeset
|
1 /* Copyright (C) 1993, 1995-1997, 2002-2003, 2005-2007, 2009-2013 Free Software |
12518
b5e42ef33b49
update nearly all FSF copyright year lists to include 2009
Jim Meyering <meyering@redhat.com>
parents:
12421
diff
changeset
|
2 * Foundation, Inc. |
4221 | 3 |
4 NOTE: The canonical source of this file is maintained with the GNU C Library. | |
5 Bugs can be reported to bug-glibc@gnu.org. | |
6 | |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
7944
diff
changeset
|
7 This program is free software: you can redistribute it and/or modify it |
4221 | 8 under the terms of the GNU General Public License as published by the |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
7944
diff
changeset
|
9 Free Software Foundation; either version 3 of the License, or any |
4221 | 10 later version. |
11 | |
12 This program is distributed in the hope that it will be useful, | |
13 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 GNU General Public License for more details. | |
16 | |
17 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:
7944
diff
changeset
|
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
4221 | 19 |
20 /* This is almost copied from strncpy.c, written by Torbjorn Granlund. */ | |
21 | |
7304
1c4ed7637c24
Include <config.h> unconditionally.
Bruno Haible <bruno@clisp.org>
parents:
7025
diff
changeset
|
22 #include <config.h> |
4221 | 23 |
24 /* Specification. */ | |
7944
a1d177cd9523
* doc/gnulib-tool.texi (Initial import): Update to match current
Paul Eggert <eggert@cs.ucla.edu>
parents:
7304
diff
changeset
|
25 #include <string.h> |
4221 | 26 |
27 #ifndef weak_alias | |
28 # define __stpncpy stpncpy | |
29 #endif | |
30 | |
4746
7f0802de0710
Better handling of collision with AIX stpncpy() function.
Bruno Haible <bruno@clisp.org>
parents:
4691
diff
changeset
|
31 /* Copy no more than N bytes of SRC to DST, returning a pointer past the |
7f0802de0710
Better handling of collision with AIX stpncpy() function.
Bruno Haible <bruno@clisp.org>
parents:
4691
diff
changeset
|
32 last non-NUL byte written into DST. */ |
4221 | 33 char * |
34 __stpncpy (char *dest, const char *src, size_t n) | |
35 { | |
36 char c; | |
37 char *s = dest; | |
38 | |
39 if (n >= 4) | |
40 { | |
41 size_t n4 = n >> 2; | |
42 | |
43 for (;;) | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
44 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
45 c = *src++; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
46 *dest++ = c; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
47 if (c == '\0') |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
48 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
49 c = *src++; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
50 *dest++ = c; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
51 if (c == '\0') |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
52 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
53 c = *src++; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
54 *dest++ = c; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
55 if (c == '\0') |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
56 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
57 c = *src++; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
58 *dest++ = c; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
59 if (c == '\0') |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
60 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
61 if (--n4 == 0) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
62 goto last_chars; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
63 } |
4221 | 64 n -= dest - s; |
65 goto zero_fill; | |
66 } | |
67 | |
68 last_chars: | |
69 n &= 3; | |
70 if (n == 0) | |
71 return dest; | |
72 | |
73 for (;;) | |
74 { | |
75 c = *src++; | |
76 --n; | |
77 *dest++ = c; | |
78 if (c == '\0') | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
79 break; |
4221 | 80 if (n == 0) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
81 return dest; |
4221 | 82 } |
83 | |
84 zero_fill: | |
85 while (n-- > 0) | |
86 dest[n] = '\0'; | |
87 | |
88 return dest - 1; | |
89 } | |
90 #ifdef weak_alias | |
91 weak_alias (__stpncpy, stpncpy) | |
92 #endif |