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_STDLIB_H) 16 #include <stdlib.h> 17 #endif 18 #if defined(PETSC_HAVE_SYS_UTSNAME_H) 19 #include <sys/utsname.h> 20 #endif 21 #if defined(PETSC_HAVE_DIRECT_H) 22 #include <direct.h> 23 #endif 24 #if defined(PETSC_HAVE_SYS_SYSTEMINFO_H) 25 #include <sys/systeminfo.h> 26 #endif 27 28 #undef __FUNCT__ 29 #define __FUNCT__ "PetscGetWorkingDirectory" 30 /*@C 31 PetscGetWorkingDirectory - Gets the current working directory. 32 33 Not Collective 34 35 Input Parameters: 36 . len - maximum length of path 37 38 Output Parameter: 39 . path - use to hold the result value. The string should be long enough 40 to hold the path. 41 42 Level: developer 43 44 Concepts: working directory 45 46 @*/ 47 PetscErrorCode PetscGetWorkingDirectory(char path[],size_t len) 48 { 49 PetscFunctionBegin; 50 #if defined(PETSC_HAVE_GETCWD) 51 if (!getcwd(path,len)) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_LIB,"getcwd()"); 52 #elif defined(PETSC_HAVE__GETCWD) 53 _getcwd(path,len); 54 #elif defined(PETSC_HAVE_GETWD) 55 getwd(path); 56 #else 57 SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP_SYS, "Could not find getcwd() or getwd()"); 58 #endif 59 PetscFunctionReturn(0); 60 } 61 62