-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutilities.h
More file actions
140 lines (117 loc) · 3.1 KB
/
utilities.h
File metadata and controls
140 lines (117 loc) · 3.1 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#ifndef SLASH_UTILITIES_H
#define SLASH_UTILITIES_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <errno.h>
#include <unistd.h>
#include <sys/wait.h>
#include <ctype.h>
#define MAX_ARGS_NUMBER 4096
#define MAX_ARGS_STRLEN 4096
#define BUFSIZE 1024
// Variables globales :
extern int errorCode;
extern char * pwd;
extern char * oldpwd;
extern char * pwdPhy;
extern char * home;
/**
* A structure of command with a list of string and the size of this list.
*/
typedef struct cmd_struct{
char** cmd_array;
size_t taille_array;
}cmd_struct;
/**
* A structure of commands with a list cmd_struct and the size of this list.
*/
typedef struct cmds_struct{
cmd_struct* cmds_array;
size_t taille_array;
}cmds_struct;
/**
* Exec perror with a message and exit with error status 1
* @param msg the perror message
*/
void perror_exit(char* msg);
/**
* Checks if a malloc has failed.
* @param ptr pointer to check
*/
void testMalloc(void * ptr);
/**
* Free an instance of struct cmd_struct.
* @param array cmds_struct
*/
void freeCmdArray(cmd_struct array);
/**
* Free an instance of struct cmds_struct
* @param array
*/
void freeCmdsArray(cmds_struct array);
/**
* Copy an array of string and NULL terminate it
* @param liste the array to copy
* @return the new array of strings
*/
char** copyStringArray(char** liste);
/**
* Same as copyStringArray() but with n string copied
* @param liste array
* @param n the amount of string to copy
* @return the new array of strings
*/
char** copyNStringArray(char** liste,size_t n);
/**
* Free an array of string
* @param array double pointer of char
*/
void freeArray(char** array);
/**
* Double the size allocated to the variable if necessary.
* @param array string array
* @param taille_array array size
* @param taille_array_initiale initial array size
* @return array parameter after reallocation
*/
char** checkArraySize(char** array,size_t taille_array,size_t* taille_array_initiale);
/**
* Checks that a path is valid physically.
* @param path relative or absolute path
* @return int val to represent boolean value. 0 = True, 1 = False
*/
int isPathValidPhy(char * path);
/**
* Checks that a path is valid logically.
* @param path absolute path for a directory
* @return int val to represent boolean value. 0 = True, 1 = False
*/
int isPathValidLo(char* path);
/**
* Function to combine two char** variables into a single char**
* @param arr1 char ** null terminated
* @param arr2 char ** null terminated
* @return char ** null terminated
*/
char** combine_char_array(char** arr1, char** arr2);
/**
* A function that return the number of char
* inside a char ** null terminated.
* @param strings
* @return count of char in strings
*/
int count_chars(char **strings);
/**
* If the line contains more than MAX_ARGS_STRLEN, the program is exited.
* @param strings arguments of command line
*/
void test_Arg_Len(char ** strings);
/**
* Check if the line contains only whitespaces
* @param ligne the line to check from
* @return 1 if empty else 0
*/
int is_empty(char* ligne);
#endif //SLASH_UTILITIES_H