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 length allowed 15: Output Parameter: 16: . dir - contains the home directory. Must be long enough to hold the name. 18: Level: developer 20: Notes: 21: If PETSc cannot determine the home directory it makes dir a null string 23: On Windows machines the environmental variable `HOME` specifies the home directory. 25: .seealso: `PetscGetTmp()`, `PetscSharedTmp()`, `PetscGetWorkingDirectory()` 26: @*/ 27: PetscErrorCode PetscGetHomeDirectory(char dir[], size_t maxlen) 28: { 29: const char *d1; 31: d1 = getenv("HOME"); 32: if (d1) { 33: PetscStrncpy(dir, d1, maxlen); 34: } else if (maxlen > 0) dir[0] = 0; 35: return 0; 36: } 38: /*@C 39: PetscFixFilename - Fixes a file name so that it is correct for both Unix and 40: Windows by using the correct / or \ to separate directories. 42: Not Collective 44: Input Parameter: 45: . filein - name of file to be fixed 47: Output Parameter: 48: . fileout - the fixed name. Should long enough to hold the filename. 50: Level: advanced 52: Note: 53: Call `PetscFixFilename()` just before calling fopen(). 54: @*/ 55: PetscErrorCode PetscFixFilename(const char filein[], char fileout[]) 56: { 57: size_t i, n; 59: if (!filein || !fileout) return 0; 61: PetscStrlen(filein, &n); 62: for (i = 0; i < n; i++) { 63: if (filein[i] == PETSC_REPLACE_DIR_SEPARATOR) fileout[i] = PETSC_DIR_SEPARATOR; 64: else fileout[i] = filein[i]; 65: } 66: fileout[n] = 0; 67: return 0; 68: }