home *** CD-ROM | disk | FTP | other *** search
/ Atari FTP / ATARI_FTP_0693.zip / ATARI_FTP_0693 / Mint / mntlib25.zoo / memccpy.c < prev    next >
C/C++ Source or Header  |  1992-09-17  |  795b  |  43 lines

  1. /* from Henry Spencer's stringlib */
  2.  
  3. #include <stddef.h>
  4. #include <string.h>
  5.  
  6. /*
  7.  * memccpy - copy bytes up to a certain char
  8.  *
  9.  * CHARBITS should be defined only if the compiler lacks "unsigned char".
  10.  * It should be a mask, e.g. 0377 for an 8-bit machine.
  11.  */
  12.  
  13. #ifndef CHARBITS
  14. #    define    UNSCHAR(c)    ((unsigned char)(c))
  15. #else
  16. #    define    UNSCHAR(c)    ((c)&CHARBITS)
  17. #endif
  18.  
  19. void *
  20. memccpy(dst, src, ucharstop, size)
  21. void * dst;
  22. const void * src;
  23. int ucharstop;
  24. size_t size;
  25. {
  26.     register char *d;
  27.     register const char *s;
  28.     register size_t n;
  29.     register int uc;
  30.  
  31.     if (size == 0)
  32.         return(NULL);
  33.  
  34.     s = (const char *) src;
  35.     d = (char *)dst;
  36.     uc = UNSCHAR(ucharstop);
  37.     for (n = size; n > 0; n--)
  38.         if (UNSCHAR(*d++ = *s++) == uc)
  39.             return(d);
  40.  
  41.     return(NULL);
  42. }
  43.