4

I am trying to implement an encryption on a file through s3fs using rc4. Basically I need to take a file descriptor that s3fs gives use it to extract the name of the file and then do the thing. So how would I do that in c++?

I don't have any code to show because I don't know how to start it would look something like:

void foo(int fd){
// something

string temp; 
temp = // result of that somethingthing;
ifstream in;
in.open(temp,ios::binary | ios::in);
}

Is this even doable? Or am I just doomed to use system calls?

Callat
  • 2,928
  • 5
  • 30
  • 47
  • 1
    Use C functions to read into a character buffer, then convert that character buffer into a `std::string` and then a `std::stringstream`, perhaps? – tadman Apr 14 '17 at 01:21
  • @EhabEl-Nabarawy the approaches listed there don't work on my system. I'm trying to `jerry-rig` a solution using tadman's suggestion which seems to kind of work. Not 100% sure yet. – Callat Apr 14 '17 at 02:26
  • 1
    @Caleb Oh, oops, FUSE-based, my apologies! – Ehab Elnabarawy Apr 14 '17 at 03:26
  • No problem thanks for the help though. I think I've managed to accomplish my goal exclusively with system calls but I still have some errors. I may post again in a few days if I cannot debug – Callat Apr 14 '17 at 03:45

1 Answers1

8

Short answer: you can't, not in standard C++ anyway. There is no official/portable way to do it.

You can, however, find some "work-around" solutions in these previous posts:

How to construct a c++ fstream from a POSIX file descriptor?

Getting a FILE* from a std::fstream

Retrieving file descriptor from a std::fstream

Community
  • 1
  • 1