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