Date: 2015-10-02T21:59:50+00:00

Actual source code: ghome.c
petsc-3.6.2 2015-10-02
Report Typos and Errors

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

      9: /*@C
     10:    PetscGetHomeDirectory - Returns home directory name.

     12:    Not Collective

     14:    Input Parameter:
     15: .  maxlen - maximum lengh allowed

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

     20:    Level: developer

     22:    Note:
     23:    If PETSc cannot determine the home directory it makes dir a null string

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

     27:    Concepts: home directory
     28: @*/
     29: PetscErrorCode  PetscGetHomeDirectory(char dir[],size_t maxlen)
     30: {
     32:   const char     *d1;

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

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

     48:    Not Collective

     50:    Input Parameter:
     51: .  filein - name of file to be fixed

     53:    Output Parameter:
     54: .  fileout - the fixed name. Should long enough to hold the filename.

     56:    Level: advanced

     58:    Notes:
     59:    Call PetscFixFilename() just before calling fopen().
     60: @*/
     61: PetscErrorCode  PetscFixFilename(const char filein[],char fileout[])
     62: {
     64:   size_t         i,n;

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

     69:   PetscStrlen(filein,&n);
     70:   for (i=0; i<n; i++) {
     71:     if (filein[i] == PETSC_REPLACE_DIR_SEPARATOR) fileout[i] = PETSC_DIR_SEPARATOR;
     72:     else fileout[i] = filein[i];
     73:   }
     74:   fileout[n] = 0;
     75:   return(0);
     76: }