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