My own malloc() function in C
Avoid globals

last_allocated is only used to communicate the result of set_data_to_block back to malloc. Returning the result is much cleaner.
Avoid special cases

There is no need to special case the initial allocation. If you do not want to rely on ((header *) heap)-&gt;next == NULL initially, you may want to provide an initialization method (which I recommend anyway).