Skip to content

Instantly share code, notes, and snippets.

@dougpuob
Last active September 29, 2020 14:00
Show Gist options
  • Save dougpuob/433f16ae9286d562dce30774a3b84903 to your computer and use it in GitHub Desktop.
Save dougpuob/433f16ae9286d562dce30774a3b84903 to your computer and use it in GitHub Desktop.
// [Repo] https://github.com/gcc-mirror/gcc/blob/master/gcc/testsuite/gcc.c-torture/execute/builtins/lib/strncpy.c
// [Local] C:\petzone\reference\gcc\gcc.git\gcc\testsuite\gcc.c-torture\execute\builtins\lib\strncpy.c
extern void abort(void);
extern int inside_main;
typedef __SIZE_TYPE__ size_t;
__attribute__ ((__noinline__))
char *
strncpy(char *s1, const char *s2, size_t n)
{
char *dest = s1;
#ifdef __OPTIMIZE__
if (inside_main)
abort();
#endif
for (; *s2 && n; n--)
*s1++ = *s2++;
while (n--)
*s1++ = 0;
return dest;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment