Unix to Windows Porting Dictionary for HPC

Links

Function List

getcwd


Unix

header file: unistd.h

char *getcwd(char *buffer, size_t maxlen);

Windows

header file: io.h

char *_getcwd(char *buffer, int maxlen);

Purpose

This function places the full path of the current working directory in buffer, and returns a pointer to buffer; this can also be NULL. The maxlen argument specifies the maximum length for the path.

Discussion

Since this function has a one-to-one correspondence with the _getcwd function in Windows, there should not be any other changes required other than renaming the function and including the header file.

Example of Use in Windows

#include <direct.h>

char* buffer;

buffer = _getcwd(NULL, 0);
if (buffer != NULL)
  printf("Current working directory is %s.", path);
else
  printf("_getcwd error.");
  
blog comments powered by Disqus