-
Notifications
You must be signed in to change notification settings - Fork 0
/
Unix_functions3.c
89 lines (80 loc) · 1.6 KB
/
Unix_functions3.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
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include "shell.h"
/**
* _strncmp - function compares the first @num character
* of @str1 and @str2
* @str1: pointer to first string character
* @str2: pointer to second string character
* @num: number of bytes to compare
* Return: 1 - if @str1 > @str2
* Else: -1
*/
int _strncmp(const char *str1, const char *str2, size_t num)
{
size_t i;
for (i = 0; i < num; ++i)
{
if (str1[i] != str2[i])
{
return ((str1[i] < str2[i]) ? -1 : 1);
}
else if (str1[i] == '\0')
{
return (0);
}
}
return (0);
}
/**
* exit_prompt - function exits the command line prompt
* @exit_command: command argument entered
* @exit_status: integer coversion of message displayed on exit
* Return: NULL
* Else: Exit the shell prompt
*/
void exit_prompt(char **exit_command, int exit_status)
{
if (exit_command[1])
{
exit_status = _atoi(exit_command[1]);
}
free_array_vectors(exit_command);
exit(exit_status);
}
/**
* create_env - creates an environment variable
* @env_name: name of the variable
* @env_value: value of the variable
*
* Return: the new variable
*/
char *create_env(char *env_name, char *env_value)
{
char *var = NULL, *new_var = NULL;
new_var = _strcat(env_name, "=");
if (new_var == NULL)
return (NULL);
var = _strcat(new_var, env_value);
if (var == NULL)
{
free(new_var);
return (NULL);
}
free(new_var);
return (var);
}
/**
* _echo - Functions executes echo command
* @args: Argument variable pointer
* Return: 1 - if succesful
* Else: -1
**/
int _echo(char *args)
{
char *value;
value = _getenv(args);
if (value)
{
write(1, value, _strlen(value));
}
return (1);
}