Actual source code: ghome.c

petsc-master 2019-11-16
Report Typos and Errors

  2: /*
  3:       Code for manipulating files.
  4: */
  5:  #include <petscsys.h>

  7: /*@C
  8:    PetscGetHomeDirectory - Returns home directory name.

 10:    Not Collective

 12:    Input Parameter:
 13: .  maxlen - maximum lengh allowed

 15:    Output Parameter:
 16: .  dir - contains the home directory. Must be long enough to hold the name.

 18:    Level: developer

 20:    Note:
 21:    If PETSc cannot determine the home directory it makes dir a null string

 23:    On Windows machines the enviornmental variable HOME specifies the home directory.

 25: @*/
 26: PetscErrorCode  PetscGetHomeDirectory(char dir[],size_t maxlen)
 27: {
 29:   const char     *d1;

 32:   d1 = getenv("HOME");
 33:   if (d1) {
 34:     PetscStrncpy(dir,d1,maxlen);
 35:   } else if (maxlen > 0) dir[0] = 0;
 36:   return(0);
 37: }

 39: /*@C
 40:     PetscFixFilename - Fixes a file name so that it is correct for both Unix and
 41:     Windows by using the correct / or \ to separate directories.

 43:    Not Collective

 45:    Input Parameter:
 46: .  filein - name of file to be fixed

 48:    Output Parameter:
 49: .  fileout - the fixed name. Should long enough to hold the filename.

 51:    Level: advanced

 53:    Notes:
 54:    Call PetscFixFilename() just before calling fopen().
 55: @*/
 56: PetscErrorCode  PetscFixFilename(const char filein[],char fileout[])
 57: {
 59:   size_t         i,n;

 62:   if (!filein || !fileout) return(0);

 64:   PetscStrlen(filein,&n);
 65:   for (i=0; i<n; i++) {
 66:     if (filein[i] == PETSC_REPLACE_DIR_SEPARATOR) fileout[i] = PETSC_DIR_SEPARATOR;
 67:     else fileout[i] = filein[i];
 68:   }
 69:   fileout[n] = 0;
 70:   return(0);
 71: }