jmpenn 2a03ff5cf4
Replace sprintf with snprintf in all of Trick source. #1384 (#1392)
* Replace sprintf with snprintf in all of Trick source. #1384

* Don't add -Werror for MacOS because of deprecated sprintf warnings which we cant get rid of because SWIG. #1384

* Fixed an unbalanced parenthesis in S_overrides.mk. #1384
2022-11-15 15:00:05 -06:00

48 lines
1.3 KiB
C

/*
* Disconnect a device
*/
#ifndef __WIN32__
#include <unistd.h>
#endif
#include "trick/tc.h"
#include "trick/tc_proto.h"
int tc_disconnect(TCDevice * device)
{
char client_str[TC_TAG_LENGTH + 256];
if (!device) {
TrickErrorHndlr *temp_error_hndlr = NULL;
trick_error_report(temp_error_hndlr,
TRICK_ERROR_ALERT, __FILE__, __LINE__, "Trying to disconnect a NULL device");
return (TC_DRIVER_ALREADY_DISCONNECTED);
}
/* Status message */
snprintf(client_str, sizeof(client_str), "(ID = %d tag = %s)", device->client_id, device->client_tag);
trick_error_report(device->error_handler, TRICK_ERROR_TRIVIAL, __FILE__, __LINE__, "%s \n", client_str);
shutdown(device->socket, 2);
CLOSE_SOCKET(device->socket);
device->socket = TRICKCOMM_INVALID_SOCKET ;
#ifdef __WIN32__
/* Terminate use of the winsock DLL */
if (WSACleanup() != 0) {
trick_error_report(device->error_handler,
TRICK_ERROR_ALERT, __FILE__, __LINE__,
"%s: WSAStartup failed with error %d\n", client_str, WSAGetLastError());
MessageBox(NULL, "Error", "tc_StartWinSock", MB_OK);
return (TC_DRIVER_ALREADY_INSTALLED);
}
#endif
return (TC_SUCCESS);
}