-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsign_handler.c
More file actions
55 lines (45 loc) · 1.08 KB
/
sign_handler.c
File metadata and controls
55 lines (45 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "main.h"
/**
* sigint_handler - handles SIGINT signal
* @sig: the exact signal number (unused)
*
* Description: Handles the SIGINT signal (Ctrl+C) by freeing global_buffer
* if it's not NULL, printing a newline character, and exiting
* with status 130.
*/
void sigint_handler(int sig)
{
char *global_buffer = NULL;
(void)sig; /* Unused parameter */
/* Free global_buffer if not NULL */
if (global_buffer != NULL)
{
free(global_buffer);
global_buffer = NULL;
}
/* Print newline character */
our_putchar('\n');
/* Exit with status 130 */
exit(130);
}
/**
* flush_buffer - checks whether buffer contains spaces or is empty
*
* Return: 0 if buffer contains non-space characters, 1 if buffer is empty
*/
int flush_buffer(void)
{
char *global_buffer = NULL;
int i = 0;
/* Iterate through global_buffer */
for (; global_buffer[i]; i++)
{
/* If non-space character is found, return 0 */
if (global_buffer[i] != ' ')
return (0);
}
/* Free global_buffer */
free(global_buffer);
/* Return 1 if buffer is empty */
return (1);
}