PageRenderTime 39ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/xbmc/cores/paplayer/FLACCodec/flac-1.2.1/src/flac/local_string_utils.c

http://github.com/elan/plex
C | 109 lines | 49 code | 11 blank | 49 comment | 23 complexity | 36004b305ae7efcd1ebd8efb9e274247 MD5 | raw file
Possible License(s): LGPL-2.0, LGPL-3.0, CC-BY-SA-3.0, 0BSD, LGPL-2.1, GPL-3.0, BSD-3-Clause, CC0-1.0, Unlicense, GPL-2.0, AGPL-1.0
  1. /* flac - Command-line FLAC encoder/decoder
  2. */
  3. #if HAVE_CONFIG_H
  4. # include <config.h>
  5. #endif
  6. #include <string.h>
  7. #include "utils.h"
  8. #include "local_string_utils.h"
  9. /* $OpenBSD: strlcpy.c,v 1.8 2003/06/17 21:56:24 millert Exp $
  10. *
  11. * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
  12. *
  13. * Permission to use, copy, modify, and distribute this software for any
  14. * purpose with or without fee is hereby granted, provided that the above
  15. * copyright notice and this permission notice appear in all copies.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  18. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  19. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  20. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  21. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  22. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  23. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  24. *
  25. *
  26. * Copy src to string dst of size siz. At most siz-1 characters
  27. * will be copied. Always NUL terminates (unless siz == 0).
  28. * Returns strlen(src); if retval >= siz, truncation occurred.
  29. */
  30. size_t
  31. flac__strlcpy(char *dst, const char *src, size_t siz)
  32. {
  33. register char *d = dst;
  34. register const char *s = src;
  35. register size_t n = siz;
  36. /* Copy as many bytes as will fit */
  37. if (n != 0 && --n != 0) {
  38. do {
  39. if ((*d++ = *s++) == 0)
  40. break;
  41. } while (--n != 0);
  42. }
  43. /* Not enough room in dst, add NUL and traverse rest of src */
  44. if (n == 0) {
  45. if (siz != 0)
  46. *d = '\0'; /* NUL-terminate dst */
  47. while (*s++)
  48. ;
  49. }
  50. return(s - src - 1); /* count does not include NUL */
  51. }
  52. /* $OpenBSD: strlcat.c,v 1.11 2003/06/17 21:56:24 millert Exp $
  53. *
  54. * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
  55. *
  56. * Permission to use, copy, modify, and distribute this software for any
  57. * purpose with or without fee is hereby granted, provided that the above
  58. * copyright notice and this permission notice appear in all copies.
  59. *
  60. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  61. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  62. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  63. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  64. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  65. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  66. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  67. *
  68. *
  69. * Appends src to string dst of size siz (unlike strncat, siz is the
  70. * full size of dst, not space left). At most siz-1 characters
  71. * will be copied. Always NUL terminates (unless siz <= strlen(dst)).
  72. * Returns strlen(src) + MIN(siz, strlen(initial dst)).
  73. * If retval >= siz, truncation occurred.
  74. */
  75. size_t
  76. flac__strlcat(char *dst, const char *src, size_t siz)
  77. {
  78. register char *d = dst;
  79. register const char *s = src;
  80. register size_t n = siz;
  81. size_t dlen;
  82. /* Find the end of dst and adjust bytes left but don't go past end */
  83. while (n-- != 0 && *d != '\0')
  84. d++;
  85. dlen = d - dst;
  86. n = siz - dlen;
  87. if (n == 0)
  88. return(dlen + strlen(s));
  89. while (*s != '\0') {
  90. if (n != 1) {
  91. *d++ = *s;
  92. n--;
  93. }
  94. s++;
  95. }
  96. *d = '\0';
  97. return(dlen + (s - src)); /* count does not include NUL */
  98. }