In general, it is possible to create your own library that contains all of another library plus routines you add, and it is possible to install that library in your system in place of the original library.
You should not do this.
Generally, when one wants to provide a function, one writes their own library and publishes it as a separate product.
stdio.h
is not a library. It is a header file. It declares objects and functions that are defined elsewhere, and it may declare related things such as macros and type names. The term “library” is generally used either to refer to the associated packaged object modules or to the entire product that is the software library: The object modules, the header files, and their documentation.
In C, a function cannot calculate the length of an array because it is not possible to pass an array to a function. When an array is used as an argument to a function, the compiler automatically converts it to a pointer to the first element of the array. This pointer does not have any information about the size of the array. For example this function:
size_t foo(int array[])
{
return sizeof array / sizeof array[0];
}
will return the size of a pointer to an int
divided by the size of an int
. It will return this same value for all arrays passed to it of any size, because its int array[]
parameter is automatically adjusted to be int *array
.
One can define a macro to calculate the size of an array:
#define NumberOf(a) (sizeof (a) / sizeof *(a))
This works as a macro because macros are different from functions. The macro argument is not passed like a function argument, and the sizeof
operator uses its argument directly—the conversion of an array to a pointer is not performed for a sizeof
operand.
This macro could be published in a header file, although it is sufficiently simple that it is usually merely defined in source files where it is used rather than provided in a header file. If you did publish it in a header file, you should publish it in your own header file. You should not modify standard C header files until you are creating your own C implementation.