当前位置: 首页> 科技> 名企 > 什么专业学网页设计_福田祥菱箱货_免费个人网站建站_网络营销策略有哪五种

什么专业学网页设计_福田祥菱箱货_免费个人网站建站_网络营销策略有哪五种

时间:2025/7/18 16:51:59来源:https://blog.csdn.net/weixin_47126666/article/details/142639276 浏览次数:0次
什么专业学网页设计_福田祥菱箱货_免费个人网站建站_网络营销策略有哪五种

C语言解析软链接路径,获取真实路径

#include <stdio.h>
#include <stdlib.h>
#include <limits.h>int resolve_symlink(const char *symlink_path, char *resolved_path, size_t size) {if (realpath(symlink_path, resolved_path) == NULL) {perror("realpath");return -1;}return 0;
}int main() {const char *symlink_path = "/data/wwwroot/TeamSpiritnode/1235.php";char resolved_path[PATH_MAX];if (resolve_symlink(symlink_path, resolved_path, sizeof(resolved_path)) == 0) {printf("Resolved path: %s\n", resolved_path);} else {printf("Failed to resolve symlink: %s\n", symlink_path);}return 0;
}
gcc -o test111 test1111.c
./test111

值得注意:readlink只能获取单个的软链接,不能获取嵌套的

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <limits.h>int resolve_symlink(const char *symlink_path, char *resolved_path, size_t size) {ssize_t len = readlink(symlink_path, resolved_path, size - 1);if (len == -1) {perror("readlink");return -1;}resolved_path[len] = '\0'; // Null-terminate the stringreturn 0;
}int main() {const char *symlink_path = "/data/wwwroot/111/111.php";char resolved_path[PATH_MAX];if (resolve_symlink(symlink_path, resolved_path, sizeof(resolved_path)) == 0) {printf("Resolved path: %s\n", resolved_path);} else {printf("Failed to resolve symlink: %s\n", symlink_path);}return 0;
}

内核态实现,只能4.17.x版本之前可用

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/dcache.h>
#include <linux/namei.h>
#include <linux/slab.h>static int resolve_symlink(const char *path, char *resolved_path, size_t size) {struct path kern_path;char *tmp;int err;err = kern_path(path, LOOKUP_FOLLOW, &kern_path);if (err) {printk(KERN_ERR "Failed to resolve path: %s\n", path);return err;}tmp = dentry_path_raw(kern_path.dentry, resolved_path, size);if (IS_ERR(tmp)) {printk(KERN_ERR "Failed to get real path: %s\n", path);path_put(&kern_path);return PTR_ERR(tmp);}path_put(&kern_path);return 0;
}static int __init my_module_init(void) {char resolved_path[PATH_MAX];const char *symlink_path = "/data/wwwroot/111/111.php";if (resolve_symlink(symlink_path, resolved_path, sizeof(resolved_path)) == 0) {printk(KERN_INFO "Resolved path: %s\n", resolved_path);} else {printk(KERN_ERR "Failed to resolve symlink: %s\n", symlink_path);}return 0;
}static void __exit my_module_exit(void) {printk(KERN_INFO "Module exiting\n");
}module_init(my_module_init);
module_exit(my_module_exit);MODULE_LICENSE("GPL");
MODULE_AUTHOR("Your Name");
MODULE_DESCRIPTION("A module to resolve symlink paths");
关键字:什么专业学网页设计_福田祥菱箱货_免费个人网站建站_网络营销策略有哪五种

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: