Remove unused variable and move declarations to function start
name was freed to soon
Convert basename in pread and pwrite