diff options
-rw-r--r-- | core/picture.c | 21 | ||||
-rw-r--r-- | core/picture.h | 1 |
2 files changed, 15 insertions, 7 deletions
diff --git a/core/picture.c b/core/picture.c index 727500afd..df1304ab8 100644 --- a/core/picture.c +++ b/core/picture.c @@ -58,14 +58,21 @@ void add_picture(struct picture_table *t, struct picture newpic) add_to_picture_table(t, idx, newpic); } -// Return true if picture was found and deleted -bool remove_picture(struct picture_table *t, const char *filename) +int get_picture_idx(const struct picture_table *t, const char *filename) { for (int i = 0; i < t->nr; ++i) { - if (same_string(t->pictures[i].filename, filename)) { - remove_from_picture_table(t, i); - return true; - } + if (same_string(t->pictures[i].filename, filename)) + return i; } - return false; + return -1; +} + +// Return true if picture was found and deleted +bool remove_picture(struct picture_table *t, const char *filename) +{ + int idx = get_picture_idx(t, filename); + if (idx < 0) + return false; + remove_from_picture_table(t, idx); + return true; } diff --git a/core/picture.h b/core/picture.h index da1a42acd..4e42052a4 100644 --- a/core/picture.h +++ b/core/picture.h @@ -34,6 +34,7 @@ extern void add_to_picture_table(struct picture_table *, int idx, struct picture extern void copy_pictures(const struct picture_table *s, struct picture_table *d); extern void add_picture(struct picture_table *, struct picture newpic); extern bool remove_picture(struct picture_table *, const char *filename); +extern int get_picture_idx(const struct picture_table *, const char *filename); /* Return -1 if not found */ #ifdef __cplusplus } |