Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.4 KiB

  1. #include <windows.h>
  2. #include "keys.h"
  3. //--------------------------------------------------------------------------
  4. // Description:
  5. // This implements lstrcat except that we always only cat up to the
  6. // passed on maxDest length. This prevents cases where we cat past
  7. // the end of the destination buffer.
  8. //
  9. // Arguments:
  10. // pDest - destination string to append to
  11. // pSrc - src string to append
  12. // maxDest - the maxuium number of characters of the destination buffer
  13. //
  14. // Returns: the destination buffer or NULL on error.
  15. // GetLastError() will return the reason for the failure.
  16. //
  17. //--------------------------------------------------------------------------
  18. LPTSTR
  19. lstrcatn(LPTSTR pDest, LPTSTR pSrc, int maxDest)
  20. {
  21. int destLen;
  22. destLen=lstrlen(pDest);
  23. if (destLen < maxDest)
  24. {
  25. lstrcpyn(pDest+destLen,pSrc,maxDest-destLen);
  26. pDest[maxDest-1] = TEXT('\0');
  27. return pDest;
  28. }
  29. //
  30. // if the buffer is the exact length and we have nothing to append
  31. // then this is ok, just return the destination buffer.
  32. //
  33. if ((destLen == maxDest) && ((NULL == pSrc) || (*pSrc == TEXT('\0'))))
  34. return pDest;
  35. //
  36. // the destination buffer is too small, so return an error.
  37. //
  38. SetLastError(ERROR_INSUFFICIENT_BUFFER);
  39. return NULL;
  40. }