-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcd.h
More file actions
57 lines (56 loc) · 876 Bytes
/
cd.h
File metadata and controls
57 lines (56 loc) · 876 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <sys/utsname.h>
#include <unistd.h>
#include <string.h>
#include<string.h>
#include<stdlib.h>
#include<unistd.h>
#include<fcntl.h>
#include <dirent.h>
#include<sys/types.h>
#include<sys/wait.h>
#include<grp.h>
#include<pwd.h>
#include <sys/stat.h>
#include <time.h>
#include <locale.h>
#include <langinfo.h>
#include <stdio.h>
#include <stdint.h>
int cd_command(char **str,int len)
{
char a3[]="cd";
if(strcmp(a3,str[0]) !=0)
{
return 0;
}
if(len ==1)
{
//CD (FOR HOME)
char* username = getenv("USER");
char home[] = "/home/";
char y[100000];
for(int i=0;i<6;i++)
{
y[i] = home[i];
}
for(int i=6;i<(6+strlen(username));i++)
{
y[i]=username[i-6];
}
chdir(y);
return 1;
}
//CD PATHNAME
else
{
char a4[]="~";
if(strcmp(a4,str[1]) ==0)
{
chdir(tilda);
}
else
chdir(str[1]);
return 1;
}
return 0;
}