1 #define PETSC_DLL 2 /* 3 Code for manipulating files. 4 */ 5 #include "petsc.h" 6 #include "petscsys.h" 7 #if defined(PETSC_HAVE_PWD_H) 8 #include <pwd.h> 9 #endif 10 #include <ctype.h> 11 #include <sys/types.h> 12 #include <sys/stat.h> 13 #if defined(PETSC_HAVE_UNISTD_H) 14 #include <unistd.h> 15 #endif 16 #if defined(PETSC_HAVE_STDLIB_H) 17 #include <stdlib.h> 18 #endif 19 #if defined(PETSC_HAVE_SYS_UTSNAME_H) 20 #include <sys/utsname.h> 21 #endif 22 #if defined(PETSC_HAVE_DIRECT_H) 23 #include <direct.h> 24 #endif 25 #if defined(PETSC_HAVE_SYS_SYSTEMINFO_H) 26 #include <sys/systeminfo.h> 27 #endif 28 #include "petscfix.h" 29 30 #undef __FUNCT__ 31 #define __FUNCT__ "PetscGetWorkingDirectory" 32 /*@C 33 PetscGetWorkingDirectory - Gets the current working directory. 34 35 Not Collective 36 37 Input Parameters: 38 . len - maximum length of path 39 40 Output Parameter: 41 . path - use to hold the result value. The string should be long enough 42 to hold the path. 43 44 Level: developer 45 46 Concepts: working directory 47 48 @*/ 49 PetscErrorCode PETSC_DLLEXPORT PetscGetWorkingDirectory(char path[],size_t len) 50 { 51 #if defined(PETSC_HAVE_GETCWD) 52 PetscFunctionBegin; 53 getcwd(path,len); 54 PetscFunctionReturn(0); 55 #elif defined(PETSC_HAVE__GETCWD) 56 PetscFunctionBegin; 57 _getcwd(path,len); 58 PetscFunctionReturn(0); 59 #elif defined(PETSC_HAVE_GETWD) 60 PetscFunctionBegin; 61 getwd(path); 62 PetscFunctionReturn(0); 63 #else 64 SETERRQ(PETSC_ERR_SUP_SYS, "Could not find getcwd() or getwd()"); 65 #endif 66 } 67 68