-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmemory_handlers.c
More file actions
43 lines (39 loc) · 782 Bytes
/
Copy pathmemory_handlers.c
File metadata and controls
43 lines (39 loc) · 782 Bytes
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
#include "shell.h"
/**
* free_up - Fress memory based on the specified format.
*
* @format: A format string indicating the type of date to free.
* 'u' for user_input (char *).
* 't' for string array (char *).
* 'p' for path list (path_t **).
*
* @...: Variable arguments based on the format.
*/
void free_up(const char *format, ...)
{
int i;
va_list args;
char *user_input;
va_start(args, format);
i = 0;
while (format[i] != '\0')
{
switch (format[i])
{
case 'u':
user_input = va_arg(args, char *);
safefree(user_input);
break;
case 't':
free_string(va_arg(args, char ***));
break;
case 'p':
free_path_list(va_arg(args, path_t **));
break;
default:
break;
}
++i;
}
va_end(args);
}