-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
30 lines (25 loc) · 761 Bytes
/
test.cpp
File metadata and controls
30 lines (25 loc) · 761 Bytes
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
#include <iostream>
#include <boost/scoped_ptr.hpp>
#include "ss_oper_file.h"
int main(int argc, char const *argv[])
{
SsOperFile *ptr = new SsOperFile("test.conf",
O_WRONLY|O_CREAT,
0666);
boost::scoped_ptr<SsOperFile> s_ptr(ptr);
if (s_ptr == nullptr) {
std::cout << "new SsOperFile failed" << std::endl;
return -1;
}
if (s_ptr->is_open() != true) {
std::cout << s_ptr->getErrInfo() << std::endl;
return -1;
}
if (s_ptr->getFileLock(F_WRLCK) == 0) {
if (s_ptr->setFileLock(F_WRLCK)) {
std::cout << "write locked" << std::endl;
s_ptr->setFileLock(F_UNLCK);
}
}
return 0;
}