home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c065 / 2.ddi / CLIB2.ZIP / STRNCPY.CAS < prev    next >
Encoding:
Text File  |  1990-06-07  |  2.3 KB  |  81 lines

  1. /*-----------------------------------------------------------------------*
  2.  * filename - strncpy.cas
  3.  *
  4.  * function(s)
  5.  *        strncpy - copy string src to string dest
  6.  *-----------------------------------------------------------------------*/
  7.  
  8. /*[]------------------------------------------------------------[]*/
  9. /*|                                                              |*/
  10. /*|     Turbo C Run Time Library - Version 3.0                   |*/
  11. /*|                                                              |*/
  12. /*|                                                              |*/
  13. /*|     Copyright (c) 1987,1988,1990 by Borland International    |*/
  14. /*|     All Rights Reserved.                                     |*/
  15. /*|                                                              |*/
  16. /*[]------------------------------------------------------------[]*/
  17.  
  18. #pragma inline
  19. #include <asmrules.h>
  20. #include <string.h>
  21.  
  22. /*-----------------------------------------------------------------------*
  23.  
  24. Name        strncpy - copy string src to string dest
  25.  
  26. Usage        char *strncpy (char *dest, const char *src, size_t maxlen);
  27.  
  28. Prototype in    string.h
  29.  
  30. Description    Copy the ASCIIZ string *src to    the buffer *dest. It is the
  31.         callers responsibility    to ensure that    the dest buffer  is
  32.         large enough  to contain the  string, and to  guard against
  33.         supplying NULL arguments.
  34.  
  35.         The  length of    source copied    will be  trimmed to  maxlen
  36.         bytes,    including  terminator.    If  *src  is  shorter  than
  37.         maxlen, then  the target buffer   is zero filled  up to the
  38.         maxlen.
  39.  
  40.         If the source needs to be  truncated then the target is NOT
  41.         zero terminated.
  42.  
  43. Return value    strncpy returns dest.
  44.  
  45. *------------------------------------------------------------------------*/
  46. #undef strncpy                  /* not an intrinsic */
  47. char *_CType strncpy(char *dest, const char *src, size_t maxlen)
  48. {
  49. #if !(LDATA)
  50. asm    mov    ax, ds
  51. asm    mov    es, ax
  52. #endif
  53. asm    cld
  54.  
  55. asm    LES_    di, src
  56. asm    mov    si, di
  57. asm    xor    al, al
  58. asm    mov    bx, maxlen
  59. asm    mov    cx, bx
  60. asm    repne    scasb
  61. asm    sub    bx, cx
  62.  
  63. #if (LDATA)
  64. #if  !defined ( __HUGE__ )
  65. asm    push    ds
  66. #endif
  67. asm    mov    di, es
  68. asm    mov    ds, di
  69. #endif
  70. asm    LES_    di, dest
  71. asm    xchg    cx, bx
  72. asm    rep    movsb
  73. asm    mov    cx, bx
  74. asm    rep    stosb
  75. #if  defined ( __LARGE__ ) || defined ( __COMPACT__ )
  76. asm    pop    ds
  77. #endif
  78.  
  79.     return(dest) ;
  80. }
  81.