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

  1. /*-----------------------------------------------------------------------*
  2.  * filename - strncpy.cas
  3.  *
  4.  * function(s)
  5.  *        strncpy - copy string src to string dest
  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            strncpy - copy string src to string dest
  24.  
  25. Usage           char *strncpy (char *dest, const char *src, size_t maxlen);
  26.  
  27. Prototype in    string.h
  28.  
  29. Description     Copy the ASCIIZ string *src to  the buffer *dest. It is the
  30.                 callers responsibility  to ensure that  the dest buffer  is
  31.                 large enough  to contain the  string, and to  guard against
  32.                 supplying NULL arguments.
  33.  
  34.                 The  length of  source copied   will be  trimmed to  maxlen
  35.                 bytes,  including  terminator.  If  *src  is  shorter  than
  36.                 maxlen, then  the target buffer   is zero filled  up to the
  37.                 maxlen.
  38.  
  39.                 If the source needs to be  truncated then the target is NOT
  40.                 zero terminated.
  41.  
  42. Return value    strncpy returns dest.
  43.  
  44. *------------------------------------------------------------------------*/
  45. #undef strncpy                  /* not an intrinsic */
  46.  
  47. #if defined(__FARFUNCS__)
  48. #include <_farfunc.h>
  49. #endif
  50.  
  51. char *_CType _FARFUNC strncpy(char *dest, const char *src, size_t maxlen)
  52. {
  53. #if !(LDATA)
  54. asm     mov     ax, ds
  55. asm     mov     es, ax
  56. #endif
  57. asm     cld
  58.  
  59. asm     LES_    di, src
  60. asm     mov     si, di
  61. asm     xor     al, al
  62. asm     mov     bx, maxlen
  63. asm     mov     cx, bx
  64. asm     repne   scasb
  65. asm     sub     bx, cx
  66.  
  67. #if (LDATA)
  68. #if  !defined ( __HUGE__ )
  69. asm     push    ds
  70. #endif
  71. asm     mov     di, es
  72. asm     mov     ds, di
  73. #endif
  74. asm     LES_    di, dest
  75. asm     xchg    cx, bx
  76. asm     rep     movsb
  77. asm     mov     cx, bx
  78. asm     rep     stosb
  79. #if  defined ( __LARGE__ ) || defined ( __COMPACT__ )
  80. asm     pop     ds
  81. #endif
  82.  
  83.         return(dest) ;
  84. }
  85.