Source code of Windows XP (NT5)
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.

60 lines
1.4 KiB

  1. /***
  2. *strncpy.c - copy at most n characters of string
  3. *
  4. * Copyright (c) 1985-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * defines strncpy() - copy at most n characters of string
  8. *
  9. *Revision History:
  10. * 05-31-89 JCR C version created.
  11. * 02-27-90 GJF Fixed calling type, #include <cruntime.h>, fixed
  12. * copyright.
  13. * 10-02-90 GJF New-style function declarator.
  14. * 09-02-93 GJF Replaced _CALLTYPE1 with __cdecl.
  15. *
  16. *******************************************************************************/
  17. #include <cruntime.h>
  18. #include <string.h>
  19. /***
  20. *char *strncpy(dest, source, count) - copy at most n characters
  21. *
  22. *Purpose:
  23. * Copies count characters from the source string to the
  24. * destination. If count is less than the length of source,
  25. * NO NULL CHARACTER is put onto the end of the copied string.
  26. * If count is greater than the length of sources, dest is padded
  27. * with null characters to length count.
  28. *
  29. *
  30. *Entry:
  31. * char *dest - pointer to destination
  32. * char *source - source string for copy
  33. * unsigned count - max number of characters to copy
  34. *
  35. *Exit:
  36. * returns dest
  37. *
  38. *Exceptions:
  39. *
  40. *******************************************************************************/
  41. char * __cdecl strncpy (
  42. char * dest,
  43. const char * source,
  44. size_t count
  45. )
  46. {
  47. char *start = dest;
  48. while (count && (*dest++ = *source++)) /* copy string */
  49. count--;
  50. if (count) /* pad out with zeroes */
  51. while (--count)
  52. *dest++ = '\0';
  53. return(start);
  54. }