-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.c
More file actions
47 lines (42 loc) · 672 Bytes
/
util.c
File metadata and controls
47 lines (42 loc) · 672 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
47
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include "util.h"
void print_bits(char* str, int len)
{
char a;
int i,j;
for (j=0; j<len; j++){
a = str[j];
for (i = 0; i < 8; i++) {
printf("%d", !!((a << i) & 0x80));
}
}
printf("\n");
}
void exit_if_error(int ret, char *msg)
{
if (ret==-1){
perror(msg);
exit(EXIT_FAILURE);
}
}
bool dir_exist(char *path)
{
DIR* dir = opendir(path);
if (dir){
closedir(dir);
return true;
}
return false;
}
void filepaths_free(struct files_paths *files)
{
int i;
if (files==NULL) return;
for (i=0; i<files->num_files; i++){
free(files->files[i]);
}
free(files->files);
free(files);
}