-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction_path.c
More file actions
49 lines (44 loc) · 1.19 KB
/
Copy pathaction_path.c
File metadata and controls
49 lines (44 loc) · 1.19 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
/**
* @file action_path.c
* Betriebssysteme MyFind Action-Path-File
* Beispiel 1
*
* @date 2020/02/22
*
* @version 1
*/
#include "action_path.h"
#include <fnmatch.h>
#include <errno.h>
#include <error.h>
#include <stdlib.h>
#include <string.h>
int doActionPath(char *filePath, char *params){
// Prevent errors about unused params; Delete once function is implemented!
filePath = filePath;
params = params;
// ------------------------------------------------------------------------
if(filePath != NULL && params != NULL){
const int pathLength = strlen(params);
if(*(params + (pathLength - 1)) == '/'){
error(0, errno, "Path %s will not match anything because it ends with /.", params);
return -1;
}
errno = 0;
int result = fnmatch(params, filePath, 0);
switch(result){
case 0:
// match
return 0;
case FNM_NOMATCH:
// no match
return 1;
default:
// error
error(0, errno, "Error while checking for name action");
return -1;
}
} else {
return -1;
}
}