4 ms·
This is not how strcpy is implemented. It is typically done in assembly.
by huhtenberg 13y ago
This is not how strcpy is implemented. It is typically done in assembly.
- deleted 13y ago[deleted]
- andrewcooke 13y agohttps://sourceware.org/git/?p=glibc.git;a=blob;f=string/strcpy.c;h=b71f7536bca7fd2afc5854f681a3629cee2cab6f;hb=HEAD https://sourceware.org/git/?p=glibc.git;a=blob;f=string/strc...
- e12e 13y agoReally? I just did a "apt-get source libc6" and in strings/eglibc-2.17/string/strcpy.c I found: /* Copy SRC to DEST. */ char * strcpy (dest, src) char *dest; const char *src; { char c; char *__unbounded s = (char *__unbounded) CHECK_BOUNDS_LOW (src); const ptrdiff_t off = CHECK_BOUNDS_LOW (dest) - s - 1; size_t n; do { c = *s++; s[off] = c; } while (c != '\0'); n = s - src; (void) CHECK_BOUNDS_HIGH (src + n); (void) CHECK_BOUNDS_HIGH (dest + n); return dest; }
- peff 13y agoThat is the fallback implementation in case a platform does not have an optimized version available. Try `sysdeps/x86_64/strcpy.S` to see an optimized version.
- e12e 13y agoOooh, shiny. I'm not very familiar with how this is all tied together, thanks for the pointer. I was a bit thrown by the apparent lack of ifdefs and such in the c definition, but I see the asm-version starts out with: #ifndef USE_AS_STPCPY # define STRCPY strcpy #endif So I guess there is some logic set up in the configure-stage before building.