-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinfo.c
34 lines (29 loc) · 798 Bytes
/
info.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
#include "header.h"
char* getHost(void) {
size_t hostsize = MAXLEN;
char* hostname = (char *) malloc(sizeof(char)*hostsize);
if (gethostname(hostname, hostsize) == -1) {
printf("Error Number: %d\n", errno);
perror("gethost: ");
return NULL;
} else {
return hostname;
}
}
char* getUser(void) {
struct passwd *username;
uid_t uid = getuid();
username = getpwuid(uid);
return username->pw_name;
}
void prompt() {
char* hostname = getHost();
char* username = getUser();
if (hostname == NULL || username == NULL) {
printf("Error Number: %d\n", errno);
perror("prompt: ");
}
char* abs = getAbsolute();
char* rel = getRelative(home, abs);
printf("<%s@%s:%s> ", username, hostname, rel);
}