xref: /petsc/src/sys/fileio/rpath.c (revision 5b6bfdb9644f185dbf5e5a09b808ec241507e1e7)
1 
2 #include <petscsys.h>
3 #if defined(PETSC_HAVE_PWD_H)
4 #include <pwd.h>
5 #endif
6 #include <ctype.h>
7 #include <sys/stat.h>
8 #if defined(PETSC_HAVE_UNISTD_H)
9 #include <unistd.h>
10 #endif
11 #if defined(PETSC_HAVE_SYS_UTSNAME_H)
12 #include <sys/utsname.h>
13 #endif
14 #if defined(PETSC_HAVE_SYS_SYSTEMINFO_H)
15 #include <sys/systeminfo.h>
16 #endif
17 
18 /*@C
19    PetscGetRelativePath - Given a filename, returns the relative path (removes
20    all directory specifiers).
21 
22    Not Collective
23 
24    Input parameters:
25 +  fullpath  - full pathname
26 .  path      - pointer to buffer to hold relative pathname
27 -  flen     - size of path
28 
29    Level: developer
30 
31    Concepts: relative path
32    Concepts: path^relative
33 
34 .seealso: PetscGetFullPath()
35 @*/
36 PetscErrorCode  PetscGetRelativePath(const char fullpath[],char path[],size_t flen)
37 {
38   char           *p;
39   PetscErrorCode ierr;
40 
41   PetscFunctionBegin;
42   /* Find string after last / or entire string if no / */
43   ierr = PetscStrrchr(fullpath,'/',&p);CHKERRQ(ierr);
44   ierr = PetscStrncpy(path,p,flen);CHKERRQ(ierr);
45   PetscFunctionReturn(0);
46 }
47