Static _ ELEM * _ clrcall_or_cdecl _ copy_s (_ ELEM * _ first1, size_t _ dest_size, const _ ELEM * _ first2, size_t _ count) {// copy [_ first1, _ first1 + _ count) to [_ first2 ,...) // _ debug_pointer (_ first1); // _ debug_pointer (_ first2); _ scl_secure_crt_validate (_ dest_size> = _ count, null); _ ELEM * _ next = _ first1; for (; 0 <_ count; -- _ count, ++ _ next, ++ _ first2) Assign (* _ next, * _ first2); Return (_ first1 );}
Static _ ELEM * _ clrcall_or_cdecl _ move_s (_ ELEM * _ first1, size_t _ dest_size, const _ ELEM * _ first2, size_t _ count) {// move [_ first1, _ first1 + _ count) to [_ first2 ,...) // _ debug_pointer (_ first1); // _ debug_pointer (_ first2); _ scl_secure_crt_validate (_ dest_size> = _ count, null); _ ELEM * _ next = _ first1; if (_ first2 <_ next & _ next <_ first2 + _ count) // the same string for (_ next + = _ count, _ first2 + = _ count; 0 <_ count; -- _ count) Assign (* -- _ next, * -- _ first2); elsefor (; 0 <_ count; -- _ count, ++ _ next, ++ _ first2) Assign (* _ next, * _ first2); Return (_ first1 );}
The _ copy_s and _ move_s functions are very similar. The difference is that _ move_s judges multiple identical strings. If the string is the same, it is copied from the reverse order of the character. If you copy the data in sequence, overwriting may occur.