strncmp.c 505 B

1234567891011121314151617181920212223242526
  1. /* $Id$ */
  2. /*
  3. * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
  4. * See the copyright notice in the ACK home directory, in the file "Copyright".
  5. */
  6. /* return negative, zero or positive value if
  7. resp. s < t, s == t or s > t; compare at most n characters
  8. */
  9. #include "ack_string.h"
  10. int
  11. strncmp(s, t, n)
  12. register _CONST char *s, *t;
  13. register _SIZET n;
  14. {
  15. while (n-- > 0) {
  16. if (*s == *t++) {
  17. if (*s++ == '\0')
  18. return 0;
  19. }
  20. else
  21. return *s - *--t;
  22. }
  23. return 0;
  24. }