This is an archive of the discontinued LLVM Phabricator instance.

[libc] add stpcpy and stpncpy
ClosedPublic

Authored by michaelrj on Oct 15 2021, 4:14 PM.

Details

Summary

Adds an implementation for stpcpy and stpncpy, which are posix extension
functions.

Diff Detail

Event Timeline

michaelrj created this revision.Oct 15 2021, 4:14 PM
michaelrj requested review of this revision.Oct 15 2021, 4:14 PM
sivachandra added inline comments.
libc/src/string/stpcpy.cpp
31

Not sure if this is a valid argument for mempcpy. As in, we might want mempcpy to be instrumented really.

libc/src/string/stpncpy.cpp
18

Nit: Instead of initializing to 0 here, do it in the for statement ...

21

... like this:

for (i = 0; ...)
24

Nit: This can be

size_t end = i;
26

Can this for loop be replaced with a call to bzero?

michaelrj updated this revision to Diff 380532.Oct 18 2021, 3:28 PM
michaelrj marked 4 inline comments as done.

respond to comments

libc/src/string/stpcpy.cpp
31

I was figuring that since mempcpy is effectively just a call to memcpy it should be treated the same, but I have no strong opinion one way or another.

sivachandra accepted this revision.Nov 3 2021, 12:05 AM
sivachandra added inline comments.
libc/src/string/stpncpy.cpp
22

Remove the braces around single statement for blocks.

libc/test/src/string/stpncpy_test.cpp
23

Is this comment correct?

This revision is now accepted and ready to land.Nov 3 2021, 12:05 AM
lntue accepted this revision.Nov 3 2021, 7:09 AM
lntue added inline comments.
libc/src/string/stpncpy.cpp
25

Do you still need both i and end?

michaelrj updated this revision to Diff 384569.Nov 3 2021, 1:23 PM
michaelrj marked 4 inline comments as done.

fix reference to CPP utils and address comments

lntue accepted this revision.Nov 3 2021, 7:46 PM
This revision was automatically updated to reflect the committed changes.