#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#ifdef O_NOFOLLOW
#define OPEN_FLAGS O_NOFOLLOW | O_NONBLOCK
#else
#define OPEN_FLAGS O_NONBLOCK
#endif
void func(const char *file_name) {
struct stat orig_st;
struct stat open_st;
int fd;
int flags;
if ((lstat(file_name, &orig_st) != 0) ||
(!S_ISREG(orig_st.st_mode))) {
}
fd = open(file_name, OPEN_FLAGS | O_WRONLY);
if (fd == -1) {
}
if (fstat(fd, &open_st) != 0) {
}
if ((orig_st.st_mode != open_st.st_mode) ||
(orig_st.st_ino != open_st.st_ino) ||
(orig_st.st_dev != open_st.st_dev)) {
}
if ((flags = fcntl(fd, F_GETFL)) == -1) {
}
if (fcntl(fd, F_SETFL, flags & ~O_NONBLOCK) == -1) {
}
if (close(fd) == -1) {
}
}