ioLibrary_Driver icon indicating copy to clipboard operation
ioLibrary_Driver copied to clipboard

Conflict Between close() function in Socket.h and File.h

Open rndalteem opened this issue 4 years ago • 1 comments

Function with Similar Name Found in Socket.h and File.h due to which When Closing File close function from socket.h gets called falsely and Program Hangs.

rndalteem avatar Oct 16 '21 06:10 rndalteem

Hi rndalteem,

possibly there is a simple solution to your problem: Define a macro after including one of Socket.h or File.h and rename the close()-function name by defining a macro. After that you include the remaining header file.

// Include socket.h and rename close function
include <socket.h>
#define socket_close() close()
// Now include file.h
include <file.h>

You can now use socket_close() to close a socket and close() to close a file handle.

Optionally you can change the second block to:

include <file.h>
#define file_close() close()

By doing so there is no possible misuse as both functions are named unambiguously,

ulri-me avatar Feb 27 '22 09:02 ulri-me