Actual source code: fwd.c

      1: /*
      2:       Code for manipulating files.
      3: */
      4: #include <petscsys.h>
      5: #if defined(PETSC_HAVE_PWD_H)
      6:   #include <pwd.h>
      7: #endif
      8: #include <ctype.h>
      9: #include <sys/stat.h>
     10: #if defined(PETSC_HAVE_UNISTD_H)
     11:   #include <unistd.h>
     12: #endif
     13: #if defined(PETSC_HAVE_SYS_UTSNAME_H)
     14:   #include <sys/utsname.h>
     15: #endif
     16: #if defined(PETSC_HAVE_DIRECT_H)
     17:   #include <direct.h>
     18: #endif
     19: #if defined(PETSC_HAVE_SYS_SYSTEMINFO_H)
     20:   #include <sys/systeminfo.h>
     21: #endif
     22: #include <errno.h>

     24: /*@C
     25:   PetscGetWorkingDirectory - Gets the current working directory.

     27:   Not Collective

     29:   Input Parameter:
     30: . len - maximum length of `path`

     32:   Output Parameter:
     33: . path - holds the result value. The string should be long enough to hold the path, for example, `PETSC_MAX_PATH_LEN`

     35:   Level: developer

     37: .seealso: `PetscGetTmp()`, `PetscSharedTmp()`, `PetscSharedWorkingDirectory()`, `PetscGetHomeDirectory()`
     38: @*/
     39: PetscErrorCode PetscGetWorkingDirectory(char path[], size_t len)
     40: {
     41:   PetscFunctionBegin;
     42: #if defined(PETSC_HAVE_GETCWD)
     43:   PetscCheck(getcwd(path, len), PETSC_COMM_SELF, PETSC_ERR_LIB, "Error in getcwd() due to \"%s\"", strerror(errno));
     44: #elif defined(PETSC_HAVE__GETCWD)
     45:   _getcwd(path, len);
     46: #else
     47:   SETERRQ(PETSC_COMM_SELF, PETSC_ERR_SUP_SYS, "Could not find getcwd()");
     48: #endif
     49:   PetscFunctionReturn(PETSC_SUCCESS);
     50: }