summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.c-torture/execute/builtins/lib/strncpy.c
blob: a6ec98b054a2fe1128300c2de393001436c366c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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;
}