/* Set the current working directory function chdir(value: String|Path): void */ static EjsObj *app_chdir(Ejs *ejs, EjsObj *unused, int argc, EjsObj **argv) { cchar *path; assert(argc == 1); if (ejsIs(ejs, argv[0], Path)) { path = ((EjsPath*) argv[0])->value; } else if (ejsIs(ejs, argv[0], String)) { path = ejsToMulti(ejs, argv[0]); } else { ejsThrowIOError(ejs, "Bad path"); return NULL; } #if WINDOWS { MprFileSystem *fs; fs = mprLookupFileSystem(path); if (!mprPathExists(path, X_OK) && *path == '/') { path = sjoin(fs->cygwin, path, NULL); } } #endif if (chdir((char*) path) < 0) { ejsThrowIOError(ejs, "Cannot change the current directory"); } return 0; }
PUBLIC int mprCloseFile(MprFile *file) { MprFileSystem *fs; if (file == 0) { return MPR_ERR_CANT_ACCESS; } fs = mprLookupFileSystem(file->path); return fs->closeFile(file); }
PUBLIC int mprTruncateFile(cchar *path, MprOff size) { MprFileSystem *fs; assert(path && *path); if ((fs = mprLookupFileSystem(path)) == 0) { return MPR_ERR_CANT_OPEN; } return fs->truncateFile(fs, path, size); }
PUBLIC MprFile *mprAttachFileFd(int fd, cchar *name, int omode) { MprFileSystem *fs; MprFile *file; fs = mprLookupFileSystem("/"); if ((file = mprAllocObj(MprFile, manageFile)) != 0) { file->fd = fd; file->fileSystem = fs; file->path = sclone(name); file->mode = omode; file->attached = 1; } return file; }
/* function get tmpdir(): Path */ static EjsPath *system_tmpdir(Ejs *ejs, EjsObj *unused, int argc, EjsObj **argv) { cchar *dir; #if WINCE dir = "/Temp"; #elif BIT_WIN_LIKE { MprFileSystem *fs; fs = mprLookupFileSystem("/"); dir = sclone(getenv("TEMP")); #if UNUSED mprMapSeparators(dir, defaultSep(fs)); #endif } #elif VXWORKS dir = "."; #else dir = "/tmp"; #endif return ejsCreatePathFromAsc(ejs, dir); }
PUBLIC MprFile *mprOpenFile(cchar *path, int omode, int perms) { MprFileSystem *fs; MprFile *file; MprPath info; fs = mprLookupFileSystem(path); file = fs->openFile(fs, path, omode, perms); if (file) { file->fileSystem = fs; file->path = sclone(path); if (omode & (O_WRONLY | O_RDWR)) { /* OPT. Should compute this lazily. */ fs->getPathInfo(fs, path, &info); file->size = (MprOff) info.size; } file->mode = omode; file->perms = perms; } return file; }