xref: /petsc/src/sys/fileio/fwd.c (revision 58d68138c660dfb4e9f5b03334792cd4f2ffd7cc)
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/stat.h>
11 #if defined(PETSC_HAVE_UNISTD_H)
12 #include <unistd.h>
13 #endif
14 #if defined(PETSC_HAVE_SYS_UTSNAME_H)
15 #include <sys/utsname.h>
16 #endif
17 #if defined(PETSC_HAVE_DIRECT_H)
18 #include <direct.h>
19 #endif
20 #if defined(PETSC_HAVE_SYS_SYSTEMINFO_H)
21 #include <sys/systeminfo.h>
22 #endif
23 
24 /*@C
25    PetscGetWorkingDirectory - Gets the current working directory.
26 
27    Not Collective
28 
29    Input Parameters:
30 .  len  - maximum length of path
31 
32    Output Parameter:
33 .  path - use to hold the result value. The string should be long enough
34           to hold the path.
35 
36    Level: developer
37 
38 @*/
39 PetscErrorCode PetscGetWorkingDirectory(char path[], size_t len) {
40   PetscFunctionBegin;
41 #if defined(PETSC_HAVE_GETCWD)
42   PetscCheck(getcwd(path, len), PETSC_COMM_SELF, PETSC_ERR_LIB, "getcwd()");
43 #elif defined(PETSC_HAVE__GETCWD)
44   _getcwd(path, len);
45 #elif defined(PETSC_HAVE_GETWD)
46   getwd(path);
47 #else
48   SETERRQ(PETSC_COMM_SELF, PETSC_ERR_SUP_SYS, "Could not find getcwd() or getwd()");
49 #endif
50   PetscFunctionReturn(0);
51 }
52