-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetenv.c
More file actions
38 lines (33 loc) · 709 Bytes
/
setenv.c
File metadata and controls
38 lines (33 loc) · 709 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
#include "headers.h"
void setenvi(char * input_str)
{
long long int i,j,k=0,token_cnt=0;
char var[10000]="\0",value[10000]="\0";
char * token = strtok(input_str," ");
while(token!=NULL)
{
if(token_cnt==1)
{
strcpy(var,token);
}
else if(token_cnt==2)
{
strcpy(value,token);
}
token = strtok(NULL," ");
token_cnt++;
}
if(token_cnt==1 || token_cnt >=4)
{
printf("Inconsistent number of arguments provided\n");
return;
}
else
{
k = setenv(var,value,1);
if(k<0)
{
fprintf(stderr,"Variable cannot be set\n");
}
}
}