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