unix环境高级编程

文章作者 100test 发表时间 2012:03:17 17:37:33
来源 100Test.Com百考试题网


  每个进程都有一个当前的工作目录,此目录是搜索所有相对路径的起点。

  进程通过调用chdir或fcdir函数可以更改当前工作目录。

  进程通过调用chdir或者fchdir函数可以更改当前工作目录。

  view plain #include int chdir(const char* pathname);int fchdir(int filedes);

  这两个函数分别用文件名和文件描述符来制定新的工作目录。

  先查看GNU C手册。

  int chdir (const char *filename) [Function] This function is used to set the process‘s working directory to filename. The normal, successful return value from chdir is 0. A value of -1 is returned to indicate an error. The errno error conditions defined for this function are the usual file name syntax errors (see Section 11.2.3 [File Name Errors], page 224), plus ENOTDIR if the file filename is not a directory. int fchdir (int filedes) [Function] This function is used to set the process’s working directory to directory associated with the file descriptor filedes. The normal, successful return value from fchdir is 0. A value of -1 is returned to indicate an error. The following errno error conditions are defined for this function:EACCES Read permission is denied for the directory named by dirname. EBADF The filedes argument is not a valid file descriptor. ENOTDIR The file descriptor filedes is not associated with a directory. EINTR The function call was interrupt by a signal.

  实例;

  view plain #include"apue.h"

  int main(void)

  { if(chdir("/devis/wangchenglin")


相关文章


Linux下编写makefile文件
Linuxfind命令用法小结
Python常见文件操作的函数示例
linux下安装ACE
unix环境高级编程
LinuxWEB服务器CMWAP访问缓慢问题
Linux下相同配置的机器间内核拷贝
常用的主机监控shell脚本
linux时间函数
澳大利亚华人论坛
考好网
日本华人论坛
华人移民留学论坛
英国华人论坛