xref: /petsc/src/sys/fileio/rpath.c (revision 6ac5842e34eedc6428162d8d42bedaaf46eae34c)
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 #undef __FUNCT__
19 #define __FUNCT__ "PetscGetRelativePath"
20 /*@C
21    PetscGetRelativePath - Given a filename, returns the relative path (removes
22    all directory specifiers).
23 
24    Not Collective
25 
26    Input parameters:
27 +  fullpath  - full pathname
28 .  path      - pointer to buffer to hold relative pathname
29 -  flen     - size of path
30 
31    Level: developer
32 
33    Concepts: relative path
34    Concepts: path^relative
35 
36 .seealso: PetscGetFullPath()
37 @*/
38 PetscErrorCode  PetscGetRelativePath(const char fullpath[],char path[],size_t flen)
39 {
40   char           *p;
41   PetscErrorCode ierr;
42 
43   PetscFunctionBegin;
44   /* Find string after last / or entire string if no / */
45   ierr = PetscStrrchr(fullpath,'/',&p);CHKERRQ(ierr);
46   ierr = PetscStrncpy(path,p,flen);CHKERRQ(ierr);
47   PetscFunctionReturn(0);
48 }
49