Fixed dll bug and macos compilation
This commit is contained in:
parent
cb4cc2bbe2
commit
b8ee53a4f5
2 changed files with 7 additions and 8 deletions
|
@ -34,7 +34,7 @@ struct gallery {
|
|||
};
|
||||
|
||||
static struct image_ll* find_by_name(struct gallery*, const char*);
|
||||
static uint32_t ntohl (uint32_t);
|
||||
static uint32_t my_ntohl (uint32_t);
|
||||
static struct image_ll* ll_remove(struct gallery*, struct image_ll*);
|
||||
|
||||
const size_t INIT_CAP = 128;
|
||||
|
@ -57,20 +57,19 @@ struct image_ll* ll_remove(struct gallery* g, struct image_ll* i) {
|
|||
|
||||
if (i->prev) {
|
||||
i->prev->next = i->next;
|
||||
} else {
|
||||
g->images = i->next;
|
||||
}
|
||||
|
||||
struct image_ll* n = i->next;
|
||||
free(i);
|
||||
g->size--;
|
||||
|
||||
if (g->size == 0) {
|
||||
g->images = NULL;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
// inspired by https://codereview.stackexchange.com/q/149751
|
||||
uint32_t ntohl (const uint32_t nlong) {
|
||||
uint32_t my_ntohl (const uint32_t nlong) {
|
||||
uint8_t* data = (uint8_t*) &nlong;
|
||||
|
||||
return ((uint32_t) data[3]) |
|
||||
|
@ -143,8 +142,8 @@ int gallery_add(struct gallery *g, char* filename) {
|
|||
return -2;
|
||||
}
|
||||
|
||||
new->first.width = ntohl(new->first.width);
|
||||
new->first.height = ntohl(new->first.height);
|
||||
new->first.width = my_ntohl(new->first.width);
|
||||
new->first.height = my_ntohl(new->first.height);
|
||||
new->first.name = filename;
|
||||
new->prev = NULL;
|
||||
new->next = g->images;
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include "gallery.h"
|
||||
|
||||
int myfilter(char *fn, int w, int h) { return w < 640; }
|
||||
int main() {
|
||||
struct gallery *g = gallery_new();
|
||||
|
||||
|
@ -25,7 +26,6 @@ int main() {
|
|||
assert(strcmp(gallery_bestfit(g, 640, 479), "480x320.png") == 0);
|
||||
assert(gallery_bestfit(g, 0, 0) == NULL);
|
||||
|
||||
int myfilter(char *fn, int w, int h) { return w < 640; }
|
||||
assert(gallery_filter(g, myfilter) == 1);
|
||||
assert(gallery_count(g) == 1);
|
||||
|
||||
|
|
Reference in a new issue