#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>
void print_file_info(const char *path) {
struct stat file_info;
if (lstat(path, &file_info) < 0) {
perror("lstat");
exit(EXIT_FAILURE);
}
printf("File: %s\n", path);
if (S_ISLNK(file_info.st_mode)) {
printf("Type: Symbolic link\n");
} else {
printf("Is not Symbolic link\n");
}
printf("Size: %ld bytes\n", (long)file_info.st_size);
printf("Permissions: ");
printf((S_ISDIR(file_info.st_mode)) ? "d" : "-");
printf((file_info.st_mode & S_IRUSR) ? "r" : "-");
printf((file_info.st_mode & S_IWUSR) ? "w" : "-");
printf((file_info.st_mode & S_IXUSR) ? "x" : "-");
printf((file_info.st_mode & S_IRGRP) ? "r" : "-");
printf((file_info.st_mode & S_IWGRP) ? "w" : "-");
printf((file_info.st_mode & S_IXGRP) ? "x" : "-");
printf((file_info.st_mode & S_IROTH) ? "r" : "-");
printf((file_info.st_mode & S_IWOTH) ? "w" : "-");
printf((file_info.st_mode & S_IXOTH) ? "x" : "-");
printf("\n");
}
int main() {
const char *path = "example_symlink";
// 测试路径是否存在的符号链接
print_file_info(path);
return 0;
}