| 1 |
/* |
| 2 |
* "$Id: flstring.c 4288 2005-04-16 00:13:17Z mike $" |
| 3 |
* |
| 4 |
* missing BSD string functions for the Fast Light Tool Kit (FLTK). |
| 5 |
* version < 1.3.2 |
| 6 |
* |
| 7 |
* Copyright 1998-2005 by Bill Spitzak and others. |
| 8 |
*/ |
| 9 |
// ---------------------------------------------------------------------------- |
| 10 |
// Copyright (C) 2014 |
| 11 |
// David Freese, W1HKJ |
| 12 |
// |
| 13 |
// This file is part of flmsg |
| 14 |
// |
| 15 |
// flrig is free software; you can redistribute it and/or modify |
| 16 |
// it under the terms of the GNU General Public License as published by |
| 17 |
// the Free Software Foundation; either version 3 of the License, or |
| 18 |
// (at your option) any later version. |
| 19 |
// |
| 20 |
// flrig is distributed in the hope that it will be useful, |
| 21 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 23 |
// GNU General Public License for more details. |
| 24 |
// |
| 25 |
// You should have received a copy of the GNU General Public License |
| 26 |
// along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 27 |
// ---------------------------------------------------------------------------- |
| 28 |
|
| 29 |
#include "missing_strings.h" |
| 30 |
|
| 31 |
// versions of FLTK < 1.3.2 do not contain fl_string |
| 32 |
#if (FLMSG_FLTK_API_MAJOR == 1 && FLMSG_FLTK_API_MINOR < 3 ) || \ |
| 33 |
(FLMSG_FLTK_API_MAJOR == 1 && FLMSG_FLTK_API_MINOR == 3 && FLMSG_FLTK_API_PATCH < 1) |
| 34 |
|
| 35 |
/* |
| 36 |
* 'fl_strlcat()' - Safely concatenate two strings. |
| 37 |
*/ |
| 38 |
|
| 39 |
size_t /* O - Length of string */ |
| 40 |
fl_strlcat(char *dst, /* O - Destination string */ |
| 41 |
const char *src, /* I - Source string */ |
| 42 |
size_t size) { /* I - Size of destination string buffer */ |
| 43 |
size_t srclen; /* Length of source string */ |
| 44 |
size_t dstlen; /* Length of destination string */ |
| 45 |
|
| 46 |
|
| 47 |
/* |
| 48 |
* Figure out how much room is left... |
| 49 |
*/ |
| 50 |
|
| 51 |
dstlen = strlen(dst); |
| 52 |
size -= dstlen + 1; |
| 53 |
|
| 54 |
if (!size) return (dstlen); /* No room, return immediately... */ |
| 55 |
|
| 56 |
/* |
| 57 |
* Figure out how much room is needed... |
| 58 |
*/ |
| 59 |
|
| 60 |
srclen = strlen(src); |
| 61 |
|
| 62 |
/* |
| 63 |
* Copy the appropriate amount... |
| 64 |
*/ |
| 65 |
|
| 66 |
if (srclen > size) srclen = size; |
| 67 |
|
| 68 |
memcpy(dst + dstlen, src, srclen); |
| 69 |
dst[dstlen + srclen] = '\0'; |
| 70 |
|
| 71 |
return (dstlen + srclen); |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
/* |
| 76 |
* 'fl_strlcpy()' - Safely copy two strings. |
| 77 |
*/ |
| 78 |
|
| 79 |
size_t /* O - Length of string */ |
| 80 |
fl_strlcpy(char *dst, /* O - Destination string */ |
| 81 |
const char *src, /* I - Source string */ |
| 82 |
size_t size) { /* I - Size of destination string buffer */ |
| 83 |
size_t srclen; /* Length of source string */ |
| 84 |
|
| 85 |
|
| 86 |
/* |
| 87 |
* Figure out how much room is needed... |
| 88 |
*/ |
| 89 |
|
| 90 |
size --; |
| 91 |
|
| 92 |
srclen = strlen(src); |
| 93 |
|
| 94 |
/* |
| 95 |
* Copy the appropriate amount... |
| 96 |
*/ |
| 97 |
|
| 98 |
if (srclen > size) srclen = size; |
| 99 |
|
| 100 |
memcpy(dst, src, srclen); |
| 101 |
dst[srclen] = '\0'; |
| 102 |
|
| 103 |
return (srclen); |
| 104 |
} |
| 105 |
|
| 106 |
#endif |