Skip to content

Commit

Permalink
fix: memrchr() is non-POSIX, check for it on configure
Browse files Browse the repository at this point in the history
  • Loading branch information
slact committed Jun 28, 2018
1 parent 154b8da commit e023c63
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
20 changes: 19 additions & 1 deletion config
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,25 @@ _NCHAN_UTIL_SRCS=" \
$_nchan_util_dir/nchan_subrequest.c \
"

#do we have memrchr() on the platform?
ngx_feature="memrchr()"
ngx_feature_run=yes
ngx_feature_incs=" \
#include <string.h>
#include <stddef.h>
"
ngx_feature_test=" \
const char *str = \"aboobar\"; \
const void *place = &str[4]; \
const void *found = memrchr(str, 'b', strlen(str)); \
if(place != found) { return 1; } \
"
. auto/feature

if [ $ngx_found = no ]; then
_NCHAN_UTIL_SRCS="$_NCHAN_UTIL_SRCS $_nchan_util_dir/memrchr.c"
fi

_NCHAN_STORE_SRCS="\
${ngx_addon_dir}/src/store/spool.c \
${ngx_addon_dir}/src/store/ngx_rwlock.c \
Expand All @@ -101,7 +120,6 @@ _NCHAN_SRCS="\
$_NCHAN_STORE_SRCS \
"


ngx_module_incs=$ngx_addon_dir/src

have=NGX_HTTP_HEADERS . auto/have
Expand Down
1 change: 1 addition & 0 deletions src/store/redis/redis_nodeset_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "redis_nginx_adapter.h"

#include <util/nchan_msg.h>
#include <util/memrchr.h>
#include <store/store_common.h>
#include "redis_nodeset_parser.h"
#include "redis_nodeset.h"
Expand Down
11 changes: 11 additions & 0 deletions src/util/memrchr.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "memrchr.h"
void *memrchr(const void *s, int c, size_t n) {
const char *start = s;
const char *end = &start[n]; //one too much on purpose
while(--end >= start) { //and this is why
if(c == *end) {
return (void *)end;
}
}
return NULL;
}
8 changes: 8 additions & 0 deletions src/util/memrchr.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef NCHAN_MEMRCHR_H
#define NCHAN_MEMRCHR_H
#include <string.h>
#include <stddef.h>

void *memrchr(const void *s, int c, size_t n);

#endif /*NCHAN_MEMRCHR_H*/

0 comments on commit e023c63

Please sign in to comment.