PWD的编译及调试
实现mypwd
1 学习pwd命令
2 研究pwd实现需要的系统调用(man -k; grep),写出伪代码
3 实现mypwd
4 测试mypwd
Linux命令学习:pwd命令
该命令用来显示目前所在的工作目录。指令英文原义:print work directory
执行权限 :All User
指令所在路径:/usr/bin/pwd 或 /bin/pwd
命令语法:
pwd [OPTION]...
命令参数:
| 参数 | 长参数 | 描叙 |
|---|---|---|
| -L | --logical(无效) | 当目录为连接路径时,显示连接路径 |
| -P | --physical(无效) | 显示实际物理路径,而非使用连接(link)路径 |
查看pwd命令的帮助信息
root@DB-Server init.d]# man pwd
PWD(1) User Commands PWD(1)
NAME
pwd - print name of current/working directory
SYNOPSIS
pwd [OPTION]...
DESCRIPTION
Print the full filename of the current working directory.
-L, --logical
use PWD from environment, even if it contains symlinks
-P, --physical
avoid all symlinks
--help display this help and exit
--version
output version information and exit
NOTE: your shell may have its own version of pwd, which usually supersedes the version described here. Please refer to your shell鈥檚 documentation for details about the
options it supports.
AUTHOR
Written by Jim Meyering.
REPORTING BUGS
Report bugs to <bug-coreutils@gnu.org>.
COPYRIGHT
Copyright 2006 Free Software Foundation, Inc.
This is free software. You may redistribute copies of it under the terms of the GNU General Public License <http://www.gnu.org/licenses/gpl.html>. There is NO WARRANTY, to
the extent permitted by law.
SEE ALSO
The full documentation for pwd is maintained as a Texinfo manual. If the info and pwd programs are properly installed at your site, the command
info pwd
should give you access to the complete manual.
pwd 5.97 PWD(1)
(END)
PWD代码如下:
include
include<sys/stat.h>
include
include
include
include<sys/types.h>
void printpath();
char inode_to_name(int);
int getinode(char );
int main()
{
printpath();
putchar('\n');
return ;
}
void printpath()
{
int inode,up_inode;
char str;
inode = getinode(".");
up_inode = getinode("..");
chdir("..");
str = inode_to_name(inode);
if(inode == up_inode) {
// printf("/%s",str);
return;
}
printpath();
printf("/%s",str);
}
int getinode(char str)
{
struct stat st;
if(stat(str,&st) == -1){
perror(str);
exit(-1);
}
return st.st_ino;
}
char inode_to_name(int inode)
{
char str;
DIR dirp;
struct dirent dirt;
if((dirp = opendir(".")) == NULL){
perror(".");
exit(-1);
}
while((dirt = readdir(dirp)) != NULL)
{
if(dirt->d_ino == inode){
str = (char )malloc(strlen(dirt->d_name)sizeof(char));
strcpy(str,dirt->d_name);
return str;
}
}
perror(".");
exit(-1);
}
截图如下:

PWD的编译及调试的更多相关文章
- 开发者说 | 使用Visual Studio Code编译、调试Apollo项目
转载地址:https://mp.weixin.qq.com/s?__biz=MzI1NjkxOTMyNQ==&mid=2247484266&idx=1&sn=d6bcd4842 ...
- 剖析并利用Visual Studio Code在Mac上编译、调试c#程序
0x00 前言 一周多以前的微软的Build大会上,微软发布了一个让很多人眼前一亮的工具,也是本文的主角——Visual Studio Code.很多使用Windows的朋友都很高兴,认为又多了一个很 ...
- 转:在VS2010下编译、调试和生成mex文件
最近帮人调了一个程序,是网上公开的代码,利用matlab与c++混合编程做三维模型关键点检测,发现他们可以用VS2010编译.调试.生成mexw32文件,因此觉得之前在Matlab上利用mex命令真是 ...
- Android之源码之模块编译和调试
Android之源码之模块编译调试 (一) 进行源码模块修改进行编译的调试 1.首先是从git或者svn上拉一套完整的工程下来,然后全编一下,一般这个时间比较长,大概会得2,3个小时左右, 2,编译成 ...
- 附录三 嵌入式C程序的编译与调试
课程回顾 C语言库的特性和发展 C语言库的常用库函数 标准库函数的特色应用 git@github.com:Kevin-Dfg/Data-Structures-and-Algorithm-Analysi ...
- 在windows下使用vs2013编译和调试mysql源代码
1. 准备工作 1)OS:win10 + VS2013 2)mysql 源码(windows版):mysql-5.6.25.zip 3)perl tool:ActivePerl-5.16.3.1604 ...
- 剖析并利用Visual Studio Code在Mac上编译、调试c#程序【转】
0x00 前言 一周多以前的微软的Build大会上,微软发布了一个让很多人眼前一亮的工具,也是本文的主角——Visual Studio Code.很多使用Windows的朋友都很高兴,认为又多了一个很 ...
- 开个CS5.4编译编译,调试错误贴
记录各种编译,调试中遇到问题.
- thinkphp学习笔记3—项目编译和调试模式
原文:thinkphp学习笔记3-项目编译和调试模式 1.项目编译 在章节2.4项目编译中作者讲到使用thinkphp的项目在第一次运行的时候会吧核心需要加载的文件去掉空白和注释合并到一个文件中编译并 ...
随机推荐
- ssr
使用Nuxt.js改造已有项目的方法 https://www.jb51.net/article/145203.htm
- supervisor管理nginx
command = /usr/local/bin/nginx 这个命令默认是后台启动,但是supervisor不能监控后台程序,所以supervisor就一直执行这个命令. 加上-g 'daemon ...
- koa 路由配置
Koa 路由 路由(Routing)是由一个 URI(或者叫路径)和一个特定的 HTTP 方法(GET.POST 等) 组成的,涉及到应用如何响应客户端对某个网站节点的访问. 通俗的讲:路由就是根据不 ...
- day9-基础函数的学习(四)
这几天一直赶着写写作业,博客的书写又落下了,要加油鸭,开写 今日份目录 1.内置函数 2.递归函数 开始今日份总结 1.内置函数 内置函数就是python内部包含的函数,总计有68种,不过有些事真的天 ...
- MongoDB 用MongoTemplate查询指定时间范围的数据
mongoDB大于小于符号对应: > 大于 $gt< 小于 $lt>= 大于等于 $gte<= 小于等于 $lte 要查询同一个时间多个约束可能出现的error: org.sp ...
- C# 读写本地配置文件
1.在本地有一个如下配置文件 2.读写本地配置文件 3.对配置文件的内容进行操作
- OCR技术浅析-自写篇(2)
本例仅以本人浅薄理解,妄想自制文字识别程序,实际在识别部分未有完善. <?php class readChar{ private $imgSize; //图片尺寸 private $imgGd2 ...
- Insertion Sort(Java)
//Insertion Sort for(int i = 1; i < a.length; i++) { int key = a[i]; int j; for(j = i - 1; j > ...
- 如何搭建SVN的客户端和使用
1.下载安装TortoiseSVN 首先我们需要从官方网站下载TortoiseSVN客户端工具 可以选择32位和64位.也可以直接使用搜索引擎搜索TortoiseSVN 也会出现直接的下载方式.这里不 ...
- 基本环境安装: Centos7+Java+Hadoop+Spark+HBase+ES+Azkaban
1. 安装VM14的方法在 人工智能标签中的<跨平台踩的大坑有提到> 2. CentOS分区设置: /boot:1024M,标准分区格式创建. swap:4096M,标准分区格式创建. ...