home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 9 / FreshFishVol9-CD2.bin / bbs / gnu / libnix-0.8-src.lha / libnix-0.8 / sources / nix / string / strncpy.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-12  |  478 b   |  43 lines

  1. #ifndef mc68000
  2.  
  3. #include <string.h>
  4.  
  5. char *strncpy(char *s1,const char *s2,size_t n)
  6. {
  7.   if (n != 0)
  8.   {
  9.     char *s=s1;
  10.  
  11.     while ((*s++=*s2++) && (--n != 0))
  12.       ;
  13.     if (n != 0)
  14.     {
  15.       do
  16.         *s++=0;
  17.       while (--n != 0);
  18.     }
  19.   }
  20.   return s1;
  21. }
  22.  
  23. #else
  24.  
  25. asm("
  26.     .globl    _strncpy
  27. _strncpy:
  28.     moveml    sp@(4:W),d0/a0
  29.     movel    d0,a1
  30.     movel    sp@(12:W),d1
  31. L4:    subql    #1,d1
  32.     bcs    L1
  33.     moveb    a0@+,a1@+
  34.     bne    L4
  35.     jra    L2
  36. L3:    clrb    a1@+
  37. L2:    subql    #1,d1
  38.     bcc    L3
  39. L1:    rts
  40. ");
  41.  
  42. #endif
  43.