home *** CD-ROM | disk | FTP | other *** search
/ Just Call Me Internet / Just Call Me Internet.iso / prog / mint / netlib / lib / sncpy.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-27  |  445 b   |  24 lines

  1. /*
  2.  *    Almost like strncpy() except that it returns the length
  3.  *    of the copied string, terminates dst always with exectly
  4.  *    one '\0'.
  5.  */ 
  6.  
  7. #include <stdio.h>    /* for size_t */
  8.  
  9. int
  10. _sncpy (dst, src, len)
  11.     char *src, *dst;
  12.     size_t len;
  13. {
  14.     int count = len;
  15.  
  16.     if (count <= 0) return 0;
  17.     while (--count >= 0 && (*dst++ = *src++) != 0);
  18.     if (count < 0) {
  19.         dst[-1] = '\0';
  20.         return (len - 1);
  21.     }
  22.     return (len - count - 1);
  23. }
  24.