# HG changeset patch # User mmj # Date 1082802436 -36000 # Node ID 57cc975a4721b4c492ec9f94097d77ec6defae1d # Parent 6708b06cf9c98ec7b6bad7882ee6582872f53157 mmap the subscriber file diff -r 6708b06cf9c9 -r 57cc975a4721 src/subscriberfuncs.c --- a/src/subscriberfuncs.c Sat Apr 24 02:52:57 2004 +1000 +++ b/src/subscriberfuncs.c Sat Apr 24 20:27:16 2004 +1000 @@ -10,28 +10,54 @@ #include #include #include +#include +#include +#include +#include #include "mlmmj.h" #include "subscriberfuncs.h" #include "mygetline.h" #include "log_error.h" -int find_subscriber(int subfilefd, const char *address) +int find_subscriber(int fd, const char *address) { - char *buf; + char *start, *cur, *next; + struct stat st; + size_t len; - while ((buf = mygetline(subfilefd))) { - while (buf[0] && isspace(buf[strlen(buf)-1])) - buf[strlen(buf)-1] = '\0'; - if (strcasecmp(buf, address) == 0) { - free(buf); - return 0; - } - free(buf); + if(fstat(fd, &st) < 0) { + log_error(LOG_ARGS, "Could not stat fd"); + return 1; } - free(buf); - + if((start = mmap(0, st.st_size, PROT_READ, MAP_SHARED, fd, 0)) == + (void *)-1) { + log_error(LOG_ARGS, "Could not mmap fd"); return 1; } + for(next = cur = start; next < start + st.st_size; next++) { + if(*next == '\n') { + len = next - cur; + if((strlen(address) == len) && + (strncasecmp(address, cur, len) == 0)) { + munmap(start, st.st_size); + return 0; + } + cur = next + 1; + } + } + + if(next > cur) { + len = next - cur; + if((strlen(address) == len) && + (strncasecmp(address, cur, len) == 0)) { + munmap(start, st.st_size); + return 0; + } + } + + munmap(start, st.st_size); + return 1; +}