0

I‘m writing a file transfer program in C++ on Unix that works via TCP Sockets. But whenever the client receives the binary bytes and tries to save them into a file, then I‘m asked whether I allow the program to access the Desktop. If the user denies access, then how do you catch this exception ?

FILE *binaryFile = fopen(absolutePath, “wb“);
fwrite(&buffer, sizeof(buffer), 1, binaryFile);

Do you have any ideas, websites ... ?

Thx

Alan Birtles
  • 32,622
  • 4
  • 31
  • 60
AES2048
  • 13
  • 5
  • check the result of `fopen` then `errno` to see why it failed? – Alan Birtles Jul 26 '20 at 06:40
  • The asking is a function of whatever desktop environment you're using. If you want to handle this case specifically, you need to write a program specifically for that desktop environment. – molbdnilo Jul 26 '20 at 07:15

1 Answers1

1

Have you tried simply putting it in a try catch I changed this to c++

try 
{ 
    std::ofstream outfile;
    outfile.exceptions ( std::ifstream::failbit | std::ifstream::badbit );
    uint8_t bytes[] = { 0x55, 0x48, 0x89, 0xe5, 0xbf, 0x00, 00, 00, 00, 0xe8, 00, 00, 00, 00, 0xb8, 00, 00, 00, 00, 0x5d, 0xc3 };
    
    outfile.open("binfile.bin", std::ios::binary | std::ios::out);  
    outfile.write(reinterpret_cast<char*>(bytes), sizeof bytes);
}   
catch (const std::exception& e) 
{ 
    std::cout << "exception caught" << std::endl;
}
Paul Baxter
  • 1,054
  • 12
  • 22