xref: /petsc/src/sys/fileio/fwd.c (revision 0700a8246d308f50502909ba325e6169d3ee27eb)
1 #define PETSC_DLL
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 PETSC_DLLEXPORT PetscGetWorkingDirectory(char path[],size_t len)
48 {
49 #if defined(PETSC_HAVE_GETCWD)
50   PetscFunctionBegin;
51   getcwd(path,len);
52   PetscFunctionReturn(0);
53 #elif defined(PETSC_HAVE__GETCWD)
54   PetscFunctionBegin;
55   _getcwd(path,len);
56   PetscFunctionReturn(0);
57 #elif defined(PETSC_HAVE_GETWD)
58   PetscFunctionBegin;
59   getwd(path);
60   PetscFunctionReturn(0);
61 #else
62   SETERRQ(PETSC_ERR_SUP_SYS, "Could not find getcwd() or getwd()");
63 #endif
64 }
65 
66