-
Notifications
You must be signed in to change notification settings - Fork 0
/
imp cmds.txt
70 lines (59 loc) · 2.13 KB
/
imp cmds.txt
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
#include "main.h"
struct utsname unameData;
int main(int argc, char *argv[])
{
###################### SPEC 1 #######################################################
uname(&unameData);
printf("%s\n", unameData.sysname);
printf("system name = %s\n", unameData.sysname);
printf("node name = %s\n", unameData.nodename);
printf("release = %s\n", unameData.release);
printf("version = %s\n", unameData.version);
printf("machine = %s\n", unameData.machine);
char hostname[1024];
gethostname(hostname, 1024);
printf("%s\n", getlogin());
printf("%s\n", getcwd(hostname, sizeof(hostname)));
###################### SPEC 2 #######################################################
char str[] = "This is a test for & break point";
const char s[] = "&";
char *token = strtok(str, s);
while(token != NULL){
printf("%s\n", token);
token = strtok(NULL, s);
}
###################### SPEC 3 #######################################################
###################### SPEC 4 #######################################################
struct dirent *de; // Pointer for directory entry
// opendir() returns a pointer of DIR type.
DIR *dr = opendir(".");
if (dr == NULL) // opendir returns NULL if couldn't open directory
{
printf("Could not open current directory" );
return 0;
}
// Refer http://pubs.opengroup.org/onlinepubs/7990989775/xsh/readdir.html
// for readdir()
while ((de = readdir(dr)) != NULL)
printf("%s\n", de->d_name);
closedir(dr);
###################### SPEC 5 #######################################################
void ls(){
struct dirent *de;
DIR *dr = opendir("/home/bassam/Documents/OS/Labs/MP1");
// if(dr == NULL)
char files[1024][1024];
int argc = 0;
while((de = readdir(dr)) != NULL){
str test = de->d_name;
strcpy(files[argc++], test);
// printf("%s, type: %hhu\n", de->d_name, de->d_type);
}
printf("\n");
qsort(files, argc, sizeof *files, cmpstr50);
for (size_t i = 0; i < argc; i++)
puts (files[i]);
closedir(dr);
}
return 0;
}