home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / c / pdc / libsrc / stringlib / memccpy.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-04-07  |  695 b   |  42 lines

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