9.4.6.2 File System

SICStus Prolog caches the name of the current working directory. To take advantage of the cache and to keep it consistent, foreign code should call the following interface functions instead of calling chdir() and getcwd() directly:

int SP_chdir(const char *path)
Cause a directory pointed to by path to become the current working directory. Returns 0 upon successful completion. Otherwise, a value of -1 is returned and errno is set to indicate the error.
char *SP_getcwd(char *buf, unsigned int size);
Returns a pointer to the current directory pathname. If buf is not NULL, the pathname will be stored in the space pointed to by buf. If buf is a NULL pointer, size bytes of space will be obtained using SP_malloc(). In this case, the pointer returned may be used as the argument in a subsequent call to SP_free(). Returns NULL with errno set if size is not large enough to store the pathname.