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.

65 lines
2.1 KiB

  1. /************************************************************************/
  2. /* */
  3. /* RCPP - Resource Compiler Pre-Processor for NT system */
  4. /* */
  5. /* RCPPTIL.C - Utility routines for RCPP */
  6. /* */
  7. /* 27-Nov-90 w-BrianM Update for NT from PM SDK RCPP */
  8. /* */
  9. /************************************************************************/
  10. #include <malloc.h>
  11. #include <string.h>
  12. #include "rcpptype.h"
  13. #include "rcppdecl.h"
  14. extern void error(int);
  15. extern char Msg_Text[];
  16. extern char * Msg_Temp;
  17. /************************************************************************
  18. * PSTRDUP - Create a duplicate of string s and return a pointer to it.
  19. ************************************************************************/
  20. char *pstrdup(char *s)
  21. {
  22. char *p = malloc(strlen(s)+1);
  23. if (p)
  24. return(strcpy(p, s));
  25. else
  26. return NULL;
  27. }
  28. /************************************************************************
  29. ** pstrndup : copies n bytes from the string to a newly allocated
  30. ** near memory location.
  31. ************************************************************************/
  32. char * pstrndup(char *s, int n)
  33. {
  34. char *r;
  35. char *res;
  36. r = res = malloc(n+1);
  37. if (res == NULL) {
  38. Msg_Temp = GET_MSG (1002);
  39. SET_MSG (Msg_Text, Msg_Temp);
  40. error(1002);
  41. return NULL;
  42. }
  43. while(n--) {
  44. *r++ = *s++;
  45. }
  46. *r = '\0';
  47. return(res);
  48. }
  49. /************************************************************************
  50. ** strappend : appends src to the dst,
  51. ** returns a ptr in dst to the null terminator.
  52. ************************************************************************/
  53. char * strappend(register char *dst, register char *src)
  54. {
  55. while ((*dst++ = *src++) != 0);
  56. return(--dst);
  57. }