Don't unlock null lock.
[cake.git] / test / examine.c
blob0852bd6819611724d015d34dfce5f74b0f37875f
1 #include <exec/types.h>
2 #include <dos/dos.h>
3 #include <dos/bptr.h>
4 #include <dos/dosextens.h>
5 #include <dos/datetime.h>
6 #include <proto/dos.h>
7 #include <stdio.h>
9 #define ENTRYTYPESTR(e) ( \
10 e == ST_PIPEFILE ? "ST_PIPEFILE" : \
11 e == ST_LINKFILE ? "ST_LINKFILE" : \
12 e == ST_FILE ? "ST_FILE" : \
13 e == ST_ROOT ? "ST_ROOT" : \
14 e == ST_USERDIR ? "ST_USERDIR" : \
15 e == ST_SOFTLINK ? "ST_SOFTLINK" : \
16 e == ST_LINKDIR ? "ST_LINKDIR" : \
17 "unknown" \
20 int main (int argc, char **argv) {
21 BPTR lock;
22 struct FileInfoBlock *fib;
23 struct DateTime dt;
24 char date[32], time[32];
26 if (argc == 0) {
27 printf("usage: %s file\n", argv[0]);
28 return 1;
31 lock = Lock(argv[1], SHARED_LOCK);
32 if (lock == NULL) {
33 printf("couldn't open file [%ld]\n", IoErr());
34 return 1;
37 fib = (struct FileInfoBlock *) AllocDosObject(DOS_FIB, NULL);
38 if (fib == NULL) {
39 printf("couldn't allocate FileInfoBlock structure\n");
40 UnLock(lock);
41 return 1;
44 if (! Examine(lock, fib)) {
45 printf("Examine() failed [%ld]\n", IoErr());
46 FreeDosObject(DOS_FIB, fib);
47 UnLock(lock);
48 return 1;
51 printf("fib_DiskKey : 0x%x\n", fib->fib_DiskKey);
52 printf("fib_DirEntryType: %d [%s]\n", fib->fib_DirEntryType, ENTRYTYPESTR(fib->fib_DirEntryType));
53 printf("fib_FileName : %s\n", fib->fib_FileName);
54 printf("fib_Protection : 0x%04x\n", fib->fib_Protection);
55 printf("fib_EntryType : %d [%s]\n", fib->fib_EntryType, ENTRYTYPESTR(fib->fib_EntryType));
56 printf("fib_Size : %d\n", fib->fib_Size);
57 printf("fib_NumBlocks : %d\n", fib->fib_NumBlocks);
59 dt.dat_Stamp = fib->fib_Date;
60 dt.dat_Format = FORMAT_DOS;
61 dt.dat_Flags = 0;
62 dt.dat_StrDay = NULL;
63 dt.dat_StrDate = date;
64 dt.dat_StrTime = time;
65 DateToStr(&dt);
67 printf("fib_Date : %s %s\n", date, time);
69 printf("fib_Comment : %s\n", fib->fib_Comment);
70 printf("fib_OwnerUID : %d\n", fib->fib_OwnerUID);
71 printf("fib_OwnerGID : %d\n", fib->fib_OwnerGID);
73 FreeDosObject(DOS_FIB, fib);
74 UnLock(lock);
76 return 0;