3 Basic Rules in C
Functions should do 1 thing and only 1 thing. The minute a function tries to do 2 or 3 things, or it goes over 50-60 lines (with a few exceptions around conditionals) it is trying to do to much.
Check all parameters for validity before doing anything else in the function.
Check all return values.