-
Notifications
You must be signed in to change notification settings - Fork 125
/
Copy pathp1.c
51 lines (40 loc) · 1.12 KB
/
p1.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <dirent.h>
#include <unistd.h>
void checkLs() {
DIR *dp1, *dp2;
struct dirent *dirp1, *dirp2;
char *dir1 = ".";
char *dir2 = "..";
if ((dp1 = opendir(dir1)) == NULL)
printf("can't open %s", dir1);
if ((dp2 = opendir(dir2)) == NULL)
printf("can't open %s", dir2);
while ((dirp1 = readdir(dp1)) != NULL && (dirp2 = readdir(dp2)) != NULL)
if (strcmp(dirp1->d_name, dirp2->d_name) != 0) {
printf("%s 与 %s 目录内文件不同\n", dir1, dir2);
closedir(dp1);
closedir(dp2);
return;
}
printf("%s 与 %s 目录内文件相同\n", dir1, dir2);
closedir(dp1);
closedir(dp2);
}
void checkPwd() {
char path1[1024], path2[1024];
realpath(".", path1);
realpath("..", path2);
if (strcmp(path1, path2) == 0) {
printf("%s 与 %s 的绝对路径相同\n", path1, path2);
} else {
printf("%s 与 %s 的绝对路径不同\n", path1, path2);
}
}
int main(int argc, char *argv[]) {
checkLs();
checkPwd();
exit(0);
}