Use strlen on OS X and use previous length value instead of calling strlen again