forked from mecomonteshbtn/C-low_level_programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshell_init.c
More file actions
46 lines (40 loc) · 783 Bytes
/
Copy pathshell_init.c
File metadata and controls
46 lines (40 loc) · 783 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
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
/**
* main - prints the environment
* Return: Always 0.
*/
int main(void)
{
char *buffer;
size_t buf_size = 32;
size_t characters;
char *av[] = {"/bin/ls", "-l", "/./", NULL};
buffer = (char *)malloc(buf_size * sizeof(char));
if (buffer == NULL)
{
perror("Unable to allocate buffer");
free(buffer);
exit(1);
}
prmpt();
char_size = getline(&buffer, &buf_size, stdin);
printf("%zu characters were read.\n", char_size);
printf("You typed: '%s'\n", buffer);
av[0] = *buffer;
if (execve(av[0], av, NULL) == -1)
{
perror("Error:");
}
return (0);
}
/**
* prompt - A function that prints the prompt
* Return: Nothing.
*/
void prompt(void)
{
write(STDOUT_FILENO, "$ ", 2);
}