Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: a9dc781d2a
Fetching contributors…

Cannot retrieve contributors at this time

file 30 lines (25 sloc) 0.722 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
/* Reasonable strlen versus glibc i386 strlen example (example-1.c) */
#include <stdio.h>

size_t ex_strlen(const char *s) {
size_t i;
for (i = 0; *s != '\0'; i++)
s++;
return i;
}

/* From glibc/sysdeps/i386/strlen.c
* http://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/i386/strlen.c
* Licensed: GNU Lesser General Public License */
size_t
glibc_strlen (const char *str)
{
  int cnt;

  asm("cld\n" /* Search forward. */
      /* Some old versions of gas need `repne' instead of `repnz'. */
      "repnz\n" /* Look for a zero byte. */
      "scasb" /* %0, %1, %3 */ :
      "=c" (cnt) : "D" (str), "0" (-1), "a" (0));

  return -2 - cnt;
}

int main(void) {
return 0;
}
Something went wrong with that request. Please try again.