-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.c
More file actions
33 lines (26 loc) · 643 Bytes
/
util.c
File metadata and controls
33 lines (26 loc) · 643 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
/**
* @file util.c
* @brief Some tool functions
*
* @author Valérian Rousset
*/
#include <stdlib.h>
#include <string.h>
// ======================================================================
char *strdup(const char *str)
{
if (str == NULL)
return NULL;
const size_t size = strlen(str) + 1;
char *ret = malloc(size);
if (ret != NULL)
memcpy(ret, str, size);
return ret;
}
// ======================================================================
size_t argv_size(char **argv)
{
char **ptr = argv;
while (*ptr != NULL) ++ptr;
return (size_t) (ptr - argv); // we know ptr >= argv
}