~ubuntu-branches/ubuntu/dapper/gnats/dapper

« back to all changes in this revision

Viewing changes to libiberty/strncmp.c

  • Committer: Bazaar Package Importer
  • Author(s): Chad Walstrom
  • Date: 2005-03-07 17:56:31 UTC
  • mfrom: (1.1.1 upstream) (2.1.1 hoary)
  • Revision ID: james.westby@ubuntu.com-20050307175631-agtm10dvjbemuc64
Tags: 4.1.0-0
* New upstream version
* debian/rules: now uses '--with-lispdir' option instead of environment
  variable overloading. Re-enabled optimization.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* strncmp -- compare two strings, stop after n bytes.
2
 
   This function is in the public domain.  */
3
 
 
4
 
#include <ansidecl.h>
5
 
#ifdef __STDC__
6
 
#include <stddef.h>
7
 
#else
8
 
#define size_t unsigned long
9
 
#endif
10
 
 
11
 
int
12
 
strncmp(s1, s2, n)
13
 
     const char *s1, *s2;
14
 
     register size_t n;
15
 
{
16
 
  register unsigned char u1, u2;
17
 
 
18
 
  while (n-- > 0)
19
 
    {
20
 
      u1 = (unsigned char) *s1++;
21
 
      u2 = (unsigned char) *s2++;
22
 
      if (u1 != u2)
23
 
        return u1 - u2;
24
 
      if (u1 == '\0')
25
 
        return 0;
26
 
    }
27
 
  return 0;
28
 
}