Ticket #2158: testlock.cpp

File testlock.cpp, 802 bytes (added by bga, 11 years ago)

Sample code

Line 
1#include <stdio.h>
2#include <string.h>
3
4#include <storage/Directory.h>
5#include <storage/Entry.h>
6#include <storage/Path.h>
7
8int main(void) {
9 BPath path("./testdir");
10 BEntry entry(path.Path(), true);
11
12 if (!entry.Exists()) {
13 printf("Creating directory %s.\n", path.Path());
14 create_directory(path.Path(), 0777);
15 }
16
17 BDirectory directory(path.Path());
18 int32 attribute;
19 ssize_t result;
20
21 result = directory.Lock();
22 if (result == B_OK) {
23 result = directory.WriteAttr("testattr", B_INT32_TYPE, 0, &attribute, sizeof(attribute));
24 if (result < B_OK) {
25 printf("BDirectory::WriteAttr() error : %s\n", strerror(result));
26 } else {
27 printf("BDirectory::WriteAttr() succeded.\n");
28 }
29 } else {
30 printf("BDirectory::Lock() error : %s\n", strerror(result));
31 }
32}