5

I'm using clang on a Debian 8 system. I have the standard C++ headers. And yet, there is no header defining strcpy_s. Why is this?

# grep -iRHI 'strcpy_s' /usr 2>/dev/null
/usr/include/x86_64-linux-gnu/bits/string2.h:                ? __strcpy_small (dest, __strcpy_args (src),             \
/usr/include/x86_64-linux-gnu/bits/string2.h:__STRING_INLINE char *__strcpy_small (char *, __uint16_t, __uint16_t,
/usr/include/x86_64-linux-gnu/bits/string2.h:__strcpy_small (char *__dest,
/usr/include/x86_64-linux-gnu/bits/string2.h:__STRING_INLINE char *__strcpy_small (char *, __STRING2_COPY_ARR2,
/usr/include/x86_64-linux-gnu/bits/string2.h:__strcpy_small (char *__dest,
/usr/src/broadcom-sta-6.30.223.248/src/include/bcmutils.h:#define bcm_strcpy_s(dst, noOfElements, src)            strcpy((dst), (src))
Sod Almighty
  • 1,768
  • 1
  • 16
  • 29

2 Answers2

6

Why does strcpy_s not exist anywhere on my system?

strcpy_s is not provided by the C++ standard library.

strcpy_s is however, specified by the C standard standard since C11. But even in C11, strcpy_s is optional. All standard library implementations do not provide all optional features. So, the answer seems to be: Because none of the C standard libraries you have installed declare it.

How to I get strcpy_s, strtok_s, and all the other safe string functions onto my system?

You will need to either find a library that implements them all, or implement them yourself.

eerorika
  • 232,697
  • 12
  • 197
  • 326
  • 1
    This is not a helpful answer. How to I get strcpy_s, strtok_s, and all the other safe string functions onto my system? – Sod Almighty Apr 19 '16 at 16:34
  • 1
    @SodAlmighty why do you think so? In my opinion, this is quite helpful to anyone wondering why they don't have headers that define `strcpy_s`, which is what you asked. I've now answered your new question as well. – eerorika Apr 19 '16 at 16:55
  • Ah. So, in order to find and get them, I have to find and get them. Right. THIS IS NOT HELPFUL!!! This is a NON-ANSWER. Why are people upvoting it? – Sod Almighty Apr 19 '16 at 18:14
  • @SodAlmighty Do you have an idea for how to improve the answer? – eerorika Apr 19 '16 at 20:36
  • Yes. Telling me where to get the missing functions would be pretty useful. – Sod Almighty Aug 21 '16 at 16:56
  • @SodAlmighty are you sure that someone has implemented the missing functions? Have you tried investigating that? – eerorika Aug 21 '16 at 20:16
5

Apparently, these don't exist because they don't exist. And I can find and install them by finding and installing them; or, alternatively, by coding them myself. Apparently this is a helpful solution, so let the upvotes begin.

Sod Almighty
  • 1,768
  • 1
  • 16
  • 29
  • 5
    I upvoted. Slap this into anything that needs strcpy_s `templateinline int strcpy_s(C*d,unsigned long dmax,const C*s){if(dmax<=1||!d){if(!d||!dmax)return 22;*d=C(0);return 0;}for(C*de=d+dmax-1;(d!=de||(*d=C(0)))&&(*d=*s);++d,++s);return 0;}` – Christopher Oicles Apr 20 '16 at 03:45
  • Thank you. But I'm still missing all the other functions :( – Sod Almighty Aug 21 '16 at 16:58