home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 5.ddi / CLIBSRC2.ZIP / STRCAT.CAS < prev    next >
Encoding:
Text File  |  1992-06-10  |  2.7 KB  |  102 lines

  1. /*-----------------------------------------------------------------------*
  2.  * filename - strcat.c
  3.  *
  4.  * function(s)
  5.  *        strcat - appends one string to another
  6.  *-----------------------------------------------------------------------*/
  7.  
  8. /*
  9.  *      C/C++ Run Time Library - Version 5.0
  10.  *
  11.  *      Copyright (c) 1987, 1992 by Borland International
  12.  *      All Rights Reserved.
  13.  *
  14.  */
  15.  
  16.  
  17. #pragma  inline
  18. #include <asmrules.h>
  19. #include <string.h>
  20.  
  21. /*---------------------------------------------------------------------*
  22.  
  23. Name            strcat - appends one string to another
  24.  
  25. Usage           char *strcat(char *destin, const char *source);
  26.  
  27. Prototype in    string.h
  28.  
  29. Description     strcat appends a copy of source to the end of destin. The
  30.                 length of the resulting string is strlen(destin) +
  31.                 strlen(source).
  32.  
  33. Return value    returns a pointer dest
  34.  
  35. *---------------------------------------------------------------------*/
  36. #undef strcat                   /* not an intrinsic */
  37.  
  38. #if defined(__FARFUNCS__)
  39. #include <_farfunc.h>
  40. #endif
  41.  
  42. char *_CType _FARFUNC strcat(register char *dest, const char *src)
  43. {
  44.         SaveSI
  45.         SaveDI
  46.  
  47. asm     cld
  48. #if  defined(__LARGE__) || defined(__COMPACT__)
  49. asm     push    ds
  50. #endif
  51. #if LDATA
  52. asm     les     di, dest        /* es:di = dest */
  53. #else
  54. asm     mov     di, dest        /* es:di = dest */
  55. asm     push    ds
  56. asm     pop     es
  57. #endif
  58. asm     mov     dx, di          /* save dest offset in dx */
  59. asm     xor     al, al
  60. asm     mov     cx, -1          /* find end of dest */
  61. asm     repne  scasb
  62. #if LDATA
  63. asm     push    es
  64. #endif
  65. asm     lea     si,[di-1]       /* es:si points to terminating null in dest */
  66. asm     LES_    di, src
  67. asm     mov     cx,-1           /* figure out strlen(src) */
  68. asm     repne  scasb
  69. asm     not     cx              /* CX = strlen(src) + 1 */
  70. asm     sub     di,cx           /* point es:di back to start of src */
  71. #if LDATA
  72. asm     push    es
  73. asm     pop     ds              /* set DS: to seg of src */
  74. asm     pop     es              /* restore ES: as seg of dest */
  75. #endif
  76. asm     xchg    si, di          /* DS:SI = src, ES:DI = dest+strlen(dest) */
  77. asm     test    si,1            /* odd src? */
  78. asm     jz      move_rest
  79. asm     movsb                   /* move a byte to make src even */
  80. asm     dec     cx
  81. move_rest:
  82. asm     shr     cx, 1
  83. asm     rep  movsw
  84. asm     jnc     move_last
  85. asm     movsb
  86. move_last:
  87. asm     xchg    ax, dx                  /* return addr of string */
  88. #if LDATA
  89. asm     mov     dx, es
  90. #endif
  91. #if  defined(__LARGE__) || defined(__COMPACT__)
  92. asm     pop     ds
  93. #endif
  94.  
  95. #if LDATA
  96.         return( (char *)(MK_LONG) );
  97. #else
  98.         return( (char *)_AX );
  99. #endif
  100. }
  101.  
  102.