MAP_FAILED, not NULL!
[blerg.git] / common / stringbucket.c
index ec827d1..7fd0bfa 100644 (file)
@@ -1,3 +1,6 @@
+/* Blerg is (C) 2011 The Dominion of Awesome, and is distributed under a
+ * BSD-style license.  Please see the COPYING file for details.
+ */
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/mman.h>
@@ -5,6 +8,7 @@
 #include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <unistd.h>
 #include <string.h>
 #include <stringbucket.h>
 
@@ -36,7 +40,7 @@ struct stringbucket * stringbucket_open(const char *filename) {
        flock(obj->fd, LOCK_UN);
        obj->size = st.st_size;
        obj->list = mmap(NULL, obj->size, PROT_READ | PROT_WRITE, MAP_SHARED, obj->fd, 0);
-       if (obj->list == NULL) {
+       if (obj->list == MAP_FAILED) {
                perror("stringbucket mmap");
                close(obj->fd);
                free(obj);
@@ -88,6 +92,7 @@ int stringbucket_delete(struct stringbucket *sb, const char *string) {
 
        /* We doin' it DOS style! */
        sb->list[pos] = 0;
+       return 1;
 }
 
 void stringbucket_iterate(struct stringbucket *sb, void (*iter)(char *, void *), void *stuff) {