blob: 24d265cddb03db3aa83dbb0ff65f97276bdbf688 (
plain)
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
|
#define _XOPEN_SOURCE 700
#include <string.h>
#include <stdlib.h>
#include "maje.h"
struct majefile *insert_file(struct majefile *list, const char *path, const struct stat *st)
{
struct majefile *tmp = malloc(sizeof(*tmp) + strlen(path) + 1);
if (tmp == NULL) {
return NULL;
}
tmp->next = NULL;
tmp->prev = NULL;
if (st) {
tmp->st = *st;
} else {
tmp->st = (struct stat) { 0 };
}
strcpy(tmp->path, path);
if (list == NULL) {
return tmp;
}
tmp->next = list->next;
tmp->prev = list;
list->next = tmp;
if (tmp->next != NULL) {
tmp->next->prev = tmp;
}
return tmp;
}
|