change output_label() to label_to_string() to make it more flexible. Output to char *buffer instead of file descriptor: fd.