|
15 | 15 | * See the License for the specific language governing permissions and
|
16 | 16 | * limitations under the License.
|
17 | 17 | *
|
| 18 | + * The strlcpy implementation is taken from OpenBSD and reformatted. The |
| 19 | + * original has the following notice attached:- |
| 20 | + * | |
| 21 | + * | Copyright (c) 1998, 2015 Todd C. Miller <millert@openbsd.org> |
| 22 | + * | |
| 23 | + * | Permission to use, copy, modify, and distribute this software for any |
| 24 | + * | purpose with or without fee is hereby granted, provided that the above |
| 25 | + * | copyright notice and this permission notice appear in all copies. |
| 26 | + * | |
| 27 | + * | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 28 | + * | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 29 | + * | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 30 | + * | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 31 | + * | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 32 | + * | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 33 | + * | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.* |
| 34 | + * |
18 | 35 | * generic string handling calls
|
19 | 36 | */
|
20 | 37 |
|
@@ -448,6 +465,42 @@ g_atoix(const char *str)
|
448 | 465 | return strtol(str, NULL, base);
|
449 | 466 | }
|
450 | 467 |
|
| 468 | +/*****************************************************************************/ |
| 469 | +#if !defined(HAVE_STRLCPY) |
| 470 | +size_t strlcpy(char *dst, const char *src, size_t dsize) |
| 471 | +{ |
| 472 | + const char *osrc = src; |
| 473 | + size_t nleft = dsize; |
| 474 | + |
| 475 | + /* Copy as many bytes as will fit. */ |
| 476 | + if (nleft != 0) |
| 477 | + { |
| 478 | + while (--nleft != 0) |
| 479 | + { |
| 480 | + if ((*dst++ = *src++) == '\0') |
| 481 | + { |
| 482 | + break; |
| 483 | + } |
| 484 | + } |
| 485 | + } |
| 486 | + |
| 487 | + /* Not enough room in dst, add NUL and traverse rest of src. */ |
| 488 | + if (nleft == 0) |
| 489 | + { |
| 490 | + if (dsize != 0) |
| 491 | + { |
| 492 | + *dst = '\0'; /* NUL-terminate dst */ |
| 493 | + } |
| 494 | + while (*src++) |
| 495 | + { |
| 496 | + ; |
| 497 | + } |
| 498 | + } |
| 499 | + |
| 500 | + return (src - osrc - 1); /* count does not include NUL */ |
| 501 | +} |
| 502 | +#endif |
| 503 | + |
451 | 504 | /*****************************************************************************/
|
452 | 505 | int
|
453 | 506 | g_htoi(char *str)
|
|
0 commit comments