Can I use memcpy_s with ObjC on iOS?

Viewed 1872

Is there any replacement for memcpy in iOS? So far as I know, memcpy is not 'safe', and the suggested alternative is 'memcpy_s'

But, code fail to compile due to 'Undefined symbols for architecture armv7:' problem, after replacing memcpy with memcpy_s.

How can I fix this problem? How to setup the project settings? Any help will be appreciated.

Some code from AsyncSocket.m:

- (CFIndex)readIntoBuffer:(UInt8 *)buffer maxLength:(CFIndex)length
{
    if([_partialReadBuffer length] > 0)
    {
        // Determine the maximum amount of data to read
        CFIndex bytesToRead = MIN(length, [_partialReadBuffer length]);

        // Copy the bytes from the buffer
        memcpy(buffer, [_partialReadBuffer bytes], bytesToRead);

        // Remove the copied bytes from the buffer
        [_partialReadBuffer replaceBytesInRange:NSMakeRange(0, bytesToRead) withBytes:NULL length:0];

        return bytesToRead;
    }
    else
    {
        return CFReadStreamRead(_theReadStream, buffer, length);
    }
}
2 Answers

You can write your own version following what Microsoft did with memcpy_s. Just look at their code.

Related