On Wed, Jan 23, 2019 at 2:28 PM Huw Davies huw@codeweavers.com wrote:
On Wed, Jan 23, 2019 at 04:25:33AM +0530, Isira Seneviratne wrote:
From 5e4bd5880b74c8340a0b41fd0867c8ee70bd2817 Mon Sep 17 00:00:00 2001 From: Isira-Seneviratne isirasen96@gmail.com Date: Sat, 5 Jan 2019 10:46:15 +0530 Subject: [PATCH] ping: Add Ctrl+C event handling
Signed-off-by: Isira-Seneviratne isirasen96@gmail.com
programs/ping/ping_main.c | 48 +++++++++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 4 deletions(-)
diff --git a/programs/ping/ping_main.c b/programs/ping/ping_main.c index 9c4f23959e..5e7e7542bc 100644 --- a/programs/ping/ping_main.c +++ b/programs/ping/ping_main.c @@ -39,8 +39,35 @@
+/* Displays ping statistics when the interrupt signal is sent to the
program */
+BOOL WINAPI ping_interrupted(DWORD dwCtrlType) +{
- switch (dwCtrlType)
- {
case CTRL_C_EVENT:
printf("\nPing statistics for %s\n", ip);
printf("\tPackets: Sent = %d, Received = %d, Lost = %d
(%.0f%% loss)\n",
i, rec, lost, (float) lost / i * 100);
if (rec != 0)
{
avg /= rec;
printf("Approximate round trip times in
milli-seconds:\n");
printf("\tMinimum = %dms, Maximum = %dms, Average =
%.0fms\n",
min, max, avg);
}
exit(0);
default:
return FALSE;
- }
+}
So the printing code now appears twice in the file, here and at the bottom of main(). What you should do is to move the printing code to a separate function that can be called from both places.
Huw.
Okay, will do. Thank you.