This repository has been archived by the owner on Jun 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.h
87 lines (70 loc) · 1.5 KB
/
utils.h
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
* Copyright 2015 Horváth Henrich
*
* Sudo security plugin is free software
* released under GNU Lesser General Public License.
*
*/
#ifndef UTILS_H_INCLUDED
#define UTILS_H_INCLUDED
#define _GNU_SOURCE
#define QUOTE(name) #name
#define STR(macro) QUOTE(macro)
#include <ctype.h>
#include <limits.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
/*
Check if strings starts with substring
*/
bool str_starts(const char * a, const char * b);
/*
Check if strings starts with substring, not case sensitive
*/
bool str_case_starts(const char * a, const char * b);
/*
Check if array contains string
*/
bool array_null_contains(char ** array, const char * str);
/*
Concaterate string arrays to one string, with separators
*/
char * concat(char ** array, char * separator);
/*
Add string to string array
*/
char ** add_string(char ** array, char * str);
/*
Removes whitespaces from string
*/
char * rem_whitespace(char * str);
/*
Return array length
*/
size_t str_array_len(char ** array);
/*
Frees 2D array
*/
void free_2d_null(char ** array);
/*
Convert bytes to inteteger variable
*/
size_t convert_from_bytes(unsigned char * array, size_t bytes);
/*
Search for file in a PWD or PATH
*/
char * find_in_path(char * command, char ** envp, int mode);
/*
Getenv from envp array
*/
char * getenv_from_envp(char * name, char ** envp);
/*
Find editor for sudoedit
*/
char * find_editor(char ** envp);
#endif // UTILS_H_INCLUDED