如何检查路径是实际链接还是符号链接 [英] how to check if a path is actual or symbolic link

查看:40
本文介绍了如何检查路径是实际链接还是符号链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写自己的 shell 程序.我目前正在使用 chdir 实现 cd 命令.我想使用以下选项实现 cd :

I am writing my own shell program. I am currently implementing the cd command using chdir. I want to implement the cd with the below options :

  • -P 不要跟随符号链接
  • -L 跟随符号链接(默认)
  • -P Do not follow symbolic links
  • -L Follow symbolic links (default)

在shell上输入给定路径时,如何以编程方式确定该路径是符号链接还是绝对路径?

When a given path is entered on the shell, how to figure out if the path is a symbolic link or an absolute path progamatically?

谢谢

推荐答案

查看 lstat() 函数,您需要在 st_mode 字段上使用 S_ISLNK.

Check out the lstat() function , you need to use S_ISLNK on the st_mode field.

这篇关于如何检查路径是实际链接还是符号链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆