Actual source code: rpath.c

  1: #define PETSC_DLL

 3:  #include petscsys.h
  4: #if defined(PETSC_HAVE_PWD_H)
  5: #include <pwd.h>
  6: #endif
  7: #include <ctype.h>
  8: #include <sys/types.h>
  9: #include <sys/stat.h>
 10: #if defined(PETSC_HAVE_UNISTD_H)
 11: #include <unistd.h>
 12: #endif
 13: #if defined(PETSC_HAVE_STDLIB_H)
 14: #include <stdlib.h>
 15: #endif
 16: #if defined(PETSC_HAVE_SYS_UTSNAME_H)
 17: #include <sys/utsname.h>
 18: #endif
 19: #if defined(PETSC_HAVE_SYS_SYSTEMINFO_H)
 20: #include <sys/systeminfo.h>
 21: #endif

 25: /*@C
 26:    PetscGetRelativePath - Given a filename, returns the relative path (removes
 27:    all directory specifiers).

 29:    Not Collective

 31:    Input parameters:
 32: +  fullpath  - full pathname
 33: .  path      - pointer to buffer to hold relative pathname
 34: -  flen     - size of path

 36:    Level: developer

 38:    Concepts: relative path
 39:    Concepts: path^relative

 41: .seealso: PetscGetFullPath()
 42: @*/
 43: PetscErrorCode  PetscGetRelativePath(const char fullpath[],char path[],size_t flen)
 44: {
 45:   char           *p;

 49:   /* Find string after last / or entire string if no / */
 50:   PetscStrrchr(fullpath,'/',&p);
 51:   PetscStrncpy(path,p,flen);
 52:   return(0);
 53: }