📄 _chdir.c
字号:
/***********************************************************************/
/* */
/* Module: _chdir.c */
/* Release: 2004.5 */
/* Version: 2002.0 */
/* Purpose: Implements chdir() */
/* */
/*---------------------------------------------------------------------*/
/* */
/* Copyright 2004, Blunk Microsystems */
/* ALL RIGHTS RESERVED */
/* */
/* Licensees have the non-exclusive right to use, modify, or extract */
/* this computer program for software development at a single site. */
/* This program may be resold or disseminated in executable format */
/* only. The source code may not be redistributed or resold. */
/* */
/***********************************************************************/
#include "posixfsp.h"
/***********************************************************************/
/* Global Function Definitions */
/***********************************************************************/
/***********************************************************************/
/* chdir: Change the current working directory */
/* */
/* Input: path = pointer to the name of the new directory */
/* */
/* Returns: 0 on success, -1 on failure */
/* */
/***********************************************************************/
int chdir(const char *path)
{
void *actual;
int r_value = -1;
DIR dir;
#if OS_PARM_CHECK
/*-------------------------------------------------------------------*/
/* If path is NULL, return -1. */
/*-------------------------------------------------------------------*/
if (path == NULL)
{
set_errno(EFAULT);
return -1;
}
#endif
/*-------------------------------------------------------------------*/
/* Initialize temporary file control block. */
/*-------------------------------------------------------------------*/
FsInitFCB(&dir, FCB_DIR);
/*-------------------------------------------------------------------*/
/* Get exclusive access to upper file system. */
/*-------------------------------------------------------------------*/
semPend(FileSysSem, WAIT_FOREVER);
/*-------------------------------------------------------------------*/
/* Ensure that path is valid. */
/*-------------------------------------------------------------------*/
actual = FSearch(&dir, &path, ACTUAL_DIR);
if (actual == NULL)
goto end;
/*-------------------------------------------------------------------*/
/* Acquire exclusive access to lower file system. */
/*-------------------------------------------------------------------*/
dir.acquire(&dir, F_READ | F_WRITE);
/*-------------------------------------------------------------------*/
/* Call file system specific ioctl to change directory. */
/*-------------------------------------------------------------------*/
r_value = (int)dir.ioctl(&dir, CHDIR, NULL, actual);
/*-------------------------------------------------------------------*/
/* Release exclusive access to lower file system. */
/*-------------------------------------------------------------------*/
dir.release(&dir, F_READ | F_WRITE);
/*-------------------------------------------------------------------*/
/* Release exclusive access to upper file system and return result. */
/*-------------------------------------------------------------------*/
end:
semPost(FileSysSem);
return r_value;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -