-
Notifications
You must be signed in to change notification settings - Fork 2
/
utils.c
68 lines (59 loc) · 1.14 KB
/
utils.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
/*
** utils.c for my_select in /home/sebastien/travaux/my_select
**
** Made by sebastien
** Login <[email protected]>
**
** Started on Tue Jan 14 17:32:39 2014 sebastien
** Last update Fri Jan 17 11:39:55 2014 sebastien
*/
#include <stdlib.h>
#include <unistd.h>
#include "my_select.h"
unsigned int my_strlen(char *s)
{
unsigned int size;
size = 0;
if (s == NULL)
return (0);
while (s[size])
size = size + 1;
return (size);
}
char *get_term(char **env)
{
int i;
char *ptr;
i = 0;
if (env == NULL || env[0] == NULL)
return (NULL);
while (env[i])
{
if (env[i][0] == 'T' && env[i][1] == 'E' && env[i][2] == 'R'
&& env[i][3] == 'M' && env[i][4] == '=')
return (&(env[i][5]));
i = i + 1;
}
return (NULL);
}
int my_strcmp(char *s1, char *s2)
{
return ((*s1 == *s2 && *s1) ? (my_strcmp(++s1, ++s2)) : (*s1 - *s2));
}
void buf_zero(char *buffer, int size)
{
int i;
i = 0;
while (i < size)
{
buffer[i] = 0;
i = i + 1;
}
}
int usage(void)
{
if ((close(fd_tty)) == -1)
my_putstr("error: could not close\n");
my_putstr("usage: ./my_select choice1 choice2 [...]\n");
return (-1);
}