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
|
#include "config.h"
#include <stdlib.h>
#include <string.h>
#include "backup.h"
#include "alpm_list.h"
#include "log.h"
#include "util.h"
int _alpm_split_backup(const char *string, alpm_backup_t **backup)
{
char *str, *ptr;
STRDUP(str, string, return -1);
ptr = strchr(str, '\t');
if(ptr == NULL) {
(*backup)->name = str;
(*backup)->hash = NULL;
return 0;
}
*ptr = '\0';
ptr++;
STRDUP((*backup)->name, str, return -1);
STRDUP((*backup)->hash, ptr, return -1);
FREE(str);
return 0;
}
alpm_backup_t *_alpm_needbackup(const char *file, const alpm_list_t *backup_list)
{
const alpm_list_t *lp;
if(file == NULL || backup_list == NULL) {
return NULL;
}
for(lp = backup_list; lp; lp = lp->next) {
alpm_backup_t *backup = lp->data;
if(strcmp(file, backup->name) == 0) {
return backup;
}
}
return NULL;
}
void _alpm_backup_free(alpm_backup_t *backup)
{
free(backup->name);
free(backup->hash);
free(backup);
}
alpm_backup_t *_alpm_backup_dup(const alpm_backup_t *backup)
{
alpm_backup_t *newbackup;
CALLOC(newbackup, 1, sizeof(alpm_backup_t), return NULL);
STRDUP(newbackup->name, backup->name, return NULL);
STRDUP(newbackup->hash, backup->hash, return NULL);
return newbackup;
}
|