0

I want to use flock(int fd, int operation) on opened file, but flock() is c function. How to get int fd from std::ofstream outfile to use as argument for flock().

ps. I want int fd at c++ style, I know that I can open file in c style and get it. The question is about c++ and flock()

std::ofstream outfile;
outfile.open ( LOCKFILE, std::ios_base::trunc);

thanks

abrahab
  • 2,430
  • 9
  • 39
  • 64

1 Answers1

2

There is no standard way to get a file descriptor from a standard fstream. There may be a platform specific method, depending on your standard library implementation.

If you're using libstdc++ then according to this there may be a filedesc() method on the fstream object that gives you what you want.

bames53
  • 86,085
  • 15
  • 179
  • 244
  • :( so, the only way to use locking is to use c style file open? ps. about your 'edit', seems it's not a good idea to use specific method for my system. I need method that will work on all unix systems. – abrahab Aug 03 '14 at 23:06