(xgetcwd): Reorganize to avoid some duplication. Use an initial, malloc'd, buffer of length 128 rather than a statically allocated one of length 1024.