This is a fundamental C question, and I think you should go and invest in a copy of Kernighan and Ritchie "The C Programming Language". On page 135 it states
<div class='quotetop'>QUOTE </div>
--- Quote Start ---
C provides a compile-time unary operator called sizeof that can be used to compute the size of any object. The expressions
sizeof onject
and
sizeof(type name)
yield an integer equal to the size of the specified object or type in bytes.[/b]
--- Quote End ---
i.e. in your code it will return the sizeof the type of data_written, which I assume is an unsigned char* given your cast. That is indeed 4 bytes on the Nios architecture