1 | #include <stdio.h>
|
---|
2 |
|
---|
3 | #include <kernel/image.h>
|
---|
4 | #include <Directory.h>
|
---|
5 | #include <Entry.h>
|
---|
6 | #include <File.h>
|
---|
7 | #include <Path.h>
|
---|
8 | #include <TypeConstants.h>
|
---|
9 |
|
---|
10 | int
|
---|
11 | main()
|
---|
12 | {
|
---|
13 | image_info imageInfo;
|
---|
14 | int32 cookie = 0;
|
---|
15 | if (get_next_image_info(0, &cookie, &imageInfo) != B_OK) {
|
---|
16 | fprintf(stderr, "unable to get next image\n");
|
---|
17 | exit(5);
|
---|
18 | }
|
---|
19 |
|
---|
20 | entry_ref normalizedRef;
|
---|
21 | get_ref_for_path(imageInfo.name, &normalizedRef);
|
---|
22 |
|
---|
23 | entry_ref eref;
|
---|
24 | eref.device = imageInfo.device;
|
---|
25 | eref.directory = imageInfo.node;
|
---|
26 | eref.set_name(imageInfo.name);
|
---|
27 |
|
---|
28 | BPath path(imageInfo.name);
|
---|
29 | path.GetParent(&path);
|
---|
30 | BDirectory dir(path.Path());
|
---|
31 |
|
---|
32 | BEntry entry;
|
---|
33 | entry.SetTo(&normalizedRef);
|
---|
34 | printf("accessing entry via entry-ref with relative path %s\n",
|
---|
35 | entry.Exists() ? "works" : "doesn't work");
|
---|
36 |
|
---|
37 | entry.SetTo(&eref);
|
---|
38 | printf("accessing entry via entry-ref with absolute path %s\n",
|
---|
39 | entry.Exists() ? "works" : "doesn't work");
|
---|
40 |
|
---|
41 | entry.SetTo(&dir, normalizedRef.name);
|
---|
42 | printf("accessing entry via directory with relative path %s\n",
|
---|
43 | entry.Exists() ? "works" : "doesn't work");
|
---|
44 |
|
---|
45 | entry.SetTo(&dir, imageInfo.name);
|
---|
46 | printf("accessing entry via directory with absolute path %s\n",
|
---|
47 | entry.Exists() ? "works" : "doesn't work");
|
---|
48 |
|
---|
49 | BFile file;
|
---|
50 | file.SetTo(&normalizedRef, B_READ_ONLY);
|
---|
51 | printf("accessing file via entry-ref with relative path %s\n",
|
---|
52 | file.InitCheck() == B_OK ? "works" : "doesn't work");
|
---|
53 |
|
---|
54 | file.SetTo(&eref, B_READ_ONLY);
|
---|
55 | printf("accessing file via entry-ref with absolute path %s\n",
|
---|
56 | file.InitCheck() == B_OK ? "works" : "doesn't work");
|
---|
57 |
|
---|
58 | file.SetTo(&dir, normalizedRef.name, B_READ_ONLY);
|
---|
59 | printf("accessing file via directory with relative path %s\n",
|
---|
60 | file.InitCheck() == B_OK ? "works" : "doesn't work");
|
---|
61 |
|
---|
62 | file.SetTo(&dir, imageInfo.name, B_READ_ONLY);
|
---|
63 | printf("accessing file via directory with absolute path %s\n",
|
---|
64 | file.InitCheck() == B_OK ? "works" : "doesn't work");
|
---|
65 |
|
---|
66 | return 0;
|
---|
67 | }
|
---|
68 |
|
---|