home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d0xx / d029 / stringlib.lha / StringLib / memccpy.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-07-21  |  677 b   |  41 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. CONST VOIDSTAR src;
  22. SIZET size;
  23. {
  24.     register char *d;
  25.     register CONST char *s;
  26.     register SIZET n;
  27.     register int uc;
  28.  
  29.     if (size <= 0)
  30.         return(NULL);
  31.  
  32.     s = src;
  33.     d = dst;
  34.     uc = UNSCHAR(ucharstop);
  35.     for (n = size; n > 0; n--)
  36.         if (UNSCHAR(*d++ = *s++) == uc)
  37.             return(d);
  38.  
  39.     return(NULL);
  40. }
  41.