Ticket #9834: open_for_writing.cpp

File open_for_writing.cpp, 420 bytes (added by bonefish, 8 years ago)
Line 
1#include <errno.h>
2#include <fcntl.h>
3#include <stdio.h>
4#include <string.h>
5
6
7int
8main(int argc, const char* const* argv)
9{
10 if (argc < 2) {
11 fprintf(stderr, "Usage: %s <path>\n", argv[0]);
12 return 1;
13 }
14
15 const char* path = argv[1];
16
17 int fd = open(path, O_RDWR);
18 if (fd < 0) {
19 fprintf(stderr, "Error: Failed to open \"%s\": %s\n", path,
20 strerror(errno));
21 return 1;
22 }
23
24 sleep(3);
25
26 close(fd);
27
28 return 0;
29}