-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse_environ_get_next_kv.test.c
44 lines (34 loc) · 1.37 KB
/
parse_environ_get_next_kv.test.c
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
#include "parse_environ.h"
#include <stdio.h>
int sub(const char* environ){
char buf[1048576] = {0};
int kvlen = 0;
uint32_t offset = 0;
kvlen = parse_environ_get_next_kv(environ, offset, buf, 1048576, NULL, NULL);
if(16 != kvlen) return -1;
if(0 != strncmp(buf, "LANG=en_US.UTF-8", kvlen)) return -1;
offset += 1 + kvlen;
kvlen = parse_environ_get_next_kv(environ, offset, buf, 1048576, NULL, NULL);
if(11 != kvlen) return -1;
if(0 != strncmp(buf, "USER=ubuntu", kvlen)) return -1;
offset += 1 + kvlen;
kvlen = parse_environ_get_next_kv(environ, offset, buf, 1048576, NULL, NULL);
if(17 != kvlen) return -1;
if(0 != strncmp(buf, "HOME=/home/ubuntu", kvlen)) return -1;
offset += 1 + kvlen;
kvlen = parse_environ_get_next_kv(environ, offset, buf, 1048576, NULL, NULL);
if(11 != kvlen) return -1;
if(0 != strncmp(buf, "TERM=screen", kvlen)) return -1;
offset += 1 + kvlen;
kvlen = parse_environ_get_next_kv(environ, offset, buf, 1048576, NULL, NULL);
if(15 != kvlen) return -1;
if(0 != strncmp(buf, "SHELL=/bin/bash", kvlen)) return -1;
offset += 1 + kvlen;
kvlen = parse_environ_get_next_kv(environ, offset, buf, 1048576, NULL, NULL);
if(0 != kvlen) return -1;
return 0;
}
int main(int argc, char** argv){
const char environ[] = "LANG=en_US.UTF-8\0USER=ubuntu\0HOME=/home/ubuntu\0TERM=screen\0SHELL=/bin/bash\0";
return sub(environ);
}