- * \fn tVFS_Handle *VFS_GetHandle(int FD)
- * \brief Gets a pointer to the handle information structure
+ * \brief Change current working directory
+ */
+int VFS_ChDir(const char *Dest)
+{
+ char *buf;
+ int fd;
+ tVFS_Handle *h;
+
+ // Create Absolute
+ buf = VFS_GetAbsPath(Dest);
+ if(buf == NULL) {
+ Log_Notice("VFS", "VFS_ChDir: Path expansion failed");
+ return -1;
+ }
+
+ // Check if path exists
+ fd = VFS_Open(buf, VFS_OPENFLAG_EXEC);
+ if(fd == -1) {
+ Log_Notice("VFS", "VFS_ChDir: Path is invalid");
+ return -1;
+ }
+
+ // Get node so we can check for directory
+ h = VFS_GetHandle(fd);
+ if( !(h->Node->Flags & VFS_FFLAG_DIRECTORY) ) {
+ Log("VFS_ChDir: Path is not a directory");
+ VFS_Close(fd);
+ return -1;
+ }
+
+ // Close file
+ VFS_Close(fd);
+
+ // Free old working directory
+ if( CFGPTR(CFG_VFS_CWD) )
+ free( CFGPTR(CFG_VFS_CWD) );
+ // Set new
+ CFGPTR(CFG_VFS_CWD) = buf;
+
+ Log("Updated CWD to '%s'", buf);
+
+ return 1;
+}
+
+/**
+ * \fn int VFS_ChRoot(char *New)
+ * \brief Change current root directory