home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 275 / DPCS0111DVD.ISO / Toolkit / Audio-Visual / VirtualDub / Source / VirtualDub-1.9.10-src.7z / src / system / source / strutil.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2009-09-14  |  2.5 KB  |  100 lines

  1. //    VirtualDub - Video processing and capture application
  2. //    System library component
  3. //    Copyright (C) 1998-2004 Avery Lee, All Rights Reserved.
  4. //
  5. //    Beginning with 1.6.0, the VirtualDub system library is licensed
  6. //    differently than the remainder of VirtualDub.  This particular file is
  7. //    thus licensed as follows (the "zlib" license):
  8. //
  9. //    This software is provided 'as-is', without any express or implied
  10. //    warranty.  In no event will the authors be held liable for any
  11. //    damages arising from the use of this software.
  12. //
  13. //    Permission is granted to anyone to use this software for any purpose,
  14. //    including commercial applications, and to alter it and redistribute it
  15. //    freely, subject to the following restrictions:
  16. //
  17. //    1.    The origin of this software must not be misrepresented; you must
  18. //        not claim that you wrote the original software. If you use this
  19. //        software in a product, an acknowledgment in the product
  20. //        documentation would be appreciated but is not required.
  21. //    2.    Altered source versions must be plainly marked as such, and must
  22. //        not be misrepresented as being the original software.
  23. //    3.    This notice may not be removed or altered from any source
  24. //        distribution.
  25.  
  26. #include "stdafx.h"
  27. #include <string.h>
  28. #include <ctype.h>
  29.  
  30. #include <vd2/system/strutil.h>
  31.  
  32. char *strncpyz(char *strDest, const char *strSource, size_t count) {
  33.     char *s;
  34.  
  35.     s = strncpy(strDest, strSource, count);
  36.     strDest[count-1] = 0;
  37.  
  38.     return s;
  39. }
  40.  
  41. wchar_t *wcsncpyz(wchar_t *strDest, const wchar_t *strSource, size_t count) {
  42.     wchar_t *s;
  43.  
  44.     s = wcsncpy(strDest, strSource, count);
  45.     strDest[count-1] = 0;
  46.  
  47.     return s;
  48. }
  49.  
  50. const char *strskipspace(const char *s) {
  51.     while(isspace((unsigned char)*s++))
  52.         ;
  53.  
  54.     return s-1;
  55. }
  56.  
  57. size_t vdstrlcpy(char *dst, const char *src, size_t size) {
  58.     size_t len = strlen(src);
  59.  
  60.     if (size) {
  61.         if (size > len)
  62.             size = len;
  63.  
  64.         memcpy(dst, src, size);
  65.         dst[size] = 0;
  66.     }
  67.     return len;
  68. }
  69.  
  70. size_t vdwcslcpy(wchar_t *dst, const wchar_t *src, size_t size) {
  71.     size_t len = wcslen(src);
  72.  
  73.     if (size) {
  74.         if (size > len)
  75.             size = len;
  76.  
  77.         memcpy(dst, src, size * sizeof(wchar_t));
  78.         dst[size] = 0;
  79.     }
  80.     return len;
  81. }
  82.  
  83. size_t vdstrlcat(char *dst, const char *src, size_t size) {
  84.     size_t dlen = strlen(dst);
  85.     size_t slen = strlen(src);
  86.  
  87.     if (dlen < size) {
  88.         size_t maxappend = size - dlen - 1;
  89.         if (maxappend > slen)
  90.             maxappend = slen;
  91.  
  92.         if (maxappend) {
  93.             memcpy(dst + dlen, src, maxappend);
  94.             dst[dlen+maxappend] = 0;
  95.         }
  96.     }
  97.  
  98.     return dlen+slen;
  99. }
  100.