Does the input upstream actually output all the chars in the name? It looks like they are truncated at n chars, before the carriage return is reached. Do you have spaces or special characters in your filenames? Get rid of those and try again. Does it work if you use a static c-string buffer longer than the longest input you are expecting?