3
  1. Is it same deprecated in GNU as in Microsoft C runtime?

  2. Is deprecation, if there is such in GNU C, enforced by later standard of C after 89/90 or the compiler?

  3. If it's GNU C compiler, since when and does it provide such a secure alternative memory operating function like memcpy_s to the deprecated memcpy in Microsoft C?

  4. If it's later C standard after 89/90, since when and does it provide such a secure alternative memory operating function like memcpy_s to the deprecated memcpy in Microsoft C?

  5. If no such deprecation in GNU C runtime, is there a function which is neither among those memory operations (name started with mem) nor the one I know as bcopy, but I can use to copy memory safe in that it takes a parameter about length of the destination?

  6. If there is/are, could you please list as many as possible?

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
Yang
  • 777
  • 1
  • 10
  • 19
  • 1
    Let me assure you that the deprecation of good old `memcpy` is a mere Microsoft invention, trying to impose a kind of so-called "safety" that doesn't really fit the domain. There is no problem in using `memcpy` and if Microsoft some day dares to completely drop it (which won't ever happen), they'll loose any customers they might still have. – Christian Rau Aug 18 '12 at 10:22
  • Also check http://stackoverflow.com/questions/870019/memcpy-in-secure-programming – Qnan Aug 18 '12 at 10:32
  • @Qnan I have viewed that before posting these questions. That's why I wrote `...nor the one I know as bcopy,...` in question 5. – Yang Aug 18 '12 at 10:39
  • @ChristianRau I think I'm liberal in the first 4 questions. I would appreciate the answer more to question 5 and 6. – Yang Aug 18 '12 at 10:41
  • @Yang that was basically the answer to the parts 5 and 6 of your question -- you don't need `memcpy_s` or its variations to write safe code. – Qnan Aug 18 '12 at 10:41
  • If you want bound checking, why not implement a wrapper over the array yourself and use that? – Qnan Aug 18 '12 at 10:42
  • @Qnan I was about to do until the last moment before posting questions. I was in the hope that such snippet exists in either glibc or what I might have missed. – Yang Aug 18 '12 at 10:51

2 Answers2

6

The function memcpy is not deprecated. It's one of the safest and most useful functions in the library. The memcpy_s function became standard in C11 (optional, see "Bounds-checking interface" in Annex K).

cnicutar
  • 178,505
  • 25
  • 365
  • 392
6

memcpy_s has been in added since C11 but is an optional extension. memcpy has not been deprecated in C and is not an obsolescent function.

glibc as of now does not support _s functions and there is no plan (AFAIK) for glibc team to support them.

ouah
  • 142,963
  • 15
  • 272
  • 331