Actual source code: rpath.c
1: #include <petscsys.h>
2: #if defined(PETSC_HAVE_PWD_H)
3: #include <pwd.h>
4: #endif
5: #include <ctype.h>
6: #include <sys/stat.h>
7: #if defined(PETSC_HAVE_UNISTD_H)
8: #include <unistd.h>
9: #endif
10: #if defined(PETSC_HAVE_SYS_UTSNAME_H)
11: #include <sys/utsname.h>
12: #endif
13: #if defined(PETSC_HAVE_SYS_SYSTEMINFO_H)
14: #include <sys/systeminfo.h>
15: #endif
17: /*@C
18: PetscGetRelativePath - Given a filename, returns the relative path (removes
19: all directory specifiers).
21: Not Collective; No Fortran Support
23: Input Parameters:
24: + fullpath - full pathname
25: - flen - size of `path`
27: Output Parameter:
28: . path - buffer that holds relative pathname
30: Level: developer
32: .seealso: `PetscGetFullPath()`
33: @*/
34: PetscErrorCode PetscGetRelativePath(const char fullpath[], char path[], size_t flen)
35: {
36: char *p = NULL;
38: PetscFunctionBegin;
39: /* Find string after last / or entire string if no / */
40: PetscCall(PetscStrrchr(fullpath, '/', &p));
41: PetscCall(PetscStrncpy(path, p, flen));
42: PetscFunctionReturn(PETSC_SUCCESS);
43: }