'How to return array size when not fixed

I'm curious of how people design C programs.

When I pass an array to a function I found out that generally people use

void function (unsigned char * ptr, size_t size)

However, I have to pass an array, which size is unknown in compile time, and have to return it after a function. Do I have to do

size_t function (unsigned char * ptr, size_t size)

or

void function (unsigned char * ptr, *size_t size)

?

In the method below, I will pass the size of the original array, and change the array size because I don't need the original size anymore.

I'm curious which is more general or better or safe. (or recommended)

The situation is that I'm doing socket connections and encrypting and decrypting messages. I heard that I should not use strlen() because the messages aren't actually strings.

c


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source