Change the working directory to DIR, possibly creating DIR and its ancestors. After this is done, all files are accessed with names relative to DIR. */
| 938 | /* Change the working directory to DIR, possibly creating DIR and its |
| 939 | ancestors. After this is done, all files are accessed with names |
| 940 | relative to DIR. */ |
| 941 | static void |
| 942 | change_directory(char const *dir) |
| 943 | { |
| 944 | if (chdir(dir) != 0) { |
| 945 | int chdir_errno = errno; |
| 946 | if (chdir_errno == ENOENT) { |
| 947 | mkdirs(dir, false); |
| 948 | chdir_errno = chdir(dir) == 0 ? 0 : errno; |
| 949 | } |
| 950 | if (chdir_errno != 0) { |
| 951 | fprintf(stderr, _("%s: Can't chdir to %s: %s\n"), |
| 952 | progname, dir, strerror(chdir_errno)); |
| 953 | exit(EXIT_FAILURE); |
| 954 | } |
| 955 | } |
| 956 | } |
| 957 | |
| 958 | /* Compare the two links A and B, for a stable sort by link name. */ |