define __KERNEL_STRICT_NAMES to avoid inclusion of kernel types on systems that carry...
[cake.git] / test / openfromlock.c
blob85ad332bc5e2df9c9fa90ac749692d79771c497d
1 /*
2 Copyright © 2008, The AROS Development Team. All rights reserved.
3 $Id$
5 Test for OpenFromLock(), NameFromLock(), NameFromFH() and DupLockFromFH().
6 */
8 #include <exec/types.h>
9 #include <dos/dosextens.h>
10 #include <dos/bptr.h>
11 #include <proto/exec.h>
12 #include <proto/dos.h>
13 #include <stdio.h>
14 #include <string.h>
15 #include <stdlib.h>
17 int main(int argc, char **argv) {
18 LONG error = 0;
19 BPTR fh, lock;
20 TEXT buffer[100];
22 if (argc != 2) {
23 printf("usage: %s filename\n", argv[0]);
24 return 1;
27 lock = Lock(argv[1], SHARED_LOCK);
28 if (lock == NULL) {
29 PrintFault(IoErr(), "openfromlock");
30 return 0;
33 fh = OpenFromLock(lock);
34 if (fh == NULL) {
35 PrintFault(IoErr(), "openfromlock");
36 UnLock(lock);
37 return 0;
40 if (NameFromFH(fh, buffer, 100))
41 Printf("Name from filehandle: %s\n", buffer);
42 else
44 PutStr("Couldn't get name from file handle.\n");
45 error = IoErr();
48 if (error == 0)
50 lock = DupLockFromFH(fh);
51 if (lock == NULL)
53 PutStr("Couldn't duplicate lock from file handle.\n");
54 error = IoErr();
58 if (error == 0)
60 if (NameFromLock(lock, buffer, 100))
61 Printf("Name from lock: %s\n", buffer);
62 else
63 PutStr("Couldn't get name from lock.\n");
64 UnLock(lock);
67 Close(fh);
69 return 0;