* Return the current working directory in a new string */
| 886 | * Return the current working directory in a new string |
| 887 | */ |
| 888 | char *dGetcwd (void) |
| 889 | { |
| 890 | size_t size = 128; |
| 891 | |
| 892 | while (1) { |
| 893 | char *buffer = dNew(char, size); |
| 894 | if (getcwd (buffer, size) == buffer) |
| 895 | return buffer; |
| 896 | dFree (buffer); |
| 897 | if (errno != ERANGE) |
| 898 | return 0; |
| 899 | size *= 2; |
| 900 | } |
| 901 | } |
| 902 | |
| 903 | /** |
| 904 | * Return the home directory in a static string (don't free) |