Permalink
Browse files

Added missing strnlen. Fixes #2616.

  • Loading branch information...
brixen committed Sep 27, 2013
1 parent 185f80e commit bff14074dff56b27e3e96e0d6e7a93e2915c3d42
Showing with 33 additions and 0 deletions.
  1. +4 −0 configure
  2. +1 −0 vm/builtin/float.cpp
  3. +1 −0 vm/builtin/string.cpp
  4. +17 −0 vm/missing/string.cpp
  5. +10 −0 vm/missing/string.h
View
@@ -1333,6 +1333,10 @@ int main() { return tgetnum(""); }
@defines << "HAVE_POSIX_FADVISE"
end
+ if has_function("strnlen", ["string.h"])
+ @defines << "HAVE_STRNLEN"
+ end
+
if has_function("lchmod", ["sys/stat.h", "unistd.h"], ["-D_XOPEN_SOURCE", "-D_XOPEN_SOURCE_EXTENDED"])
@have_lchmod = true
end
View
@@ -11,6 +11,7 @@
#include "object_utils.hpp"
#include "ontology.hpp"
#include "util/local_buffer.hpp"
+#include "missing/string.h"
#include <double-conversion.h>
#include <ieee.h>
View
@@ -25,6 +25,7 @@
#include "util/siphash.h"
#include "util/spinlock.hpp"
#include "util/random.h"
+#include "missing/string.h"
#include <unistd.h>
#include <string.h>
View
@@ -0,0 +1,17 @@
+#include "vm/config.h"
+
+#include <string.h>
+
+extern "C" {
+
+#ifndef HAVE_STRNLEN
+ size_t strnlen(const char* s, size_t maxlen) {
+ for(size_t i = 0; i < maxlen; i++) {
+ if(s[i] == '\0') return i;
+ }
+
+ return maxlen;
+ }
+#endif
+
+}
View
@@ -0,0 +1,10 @@
+#ifndef RBX_VM_MISSING_STRING_H
+#define RBX_VM_MISSING_STRING_H
+
+extern "C" {
+#ifndef HAVE_STRNLEN
+ size_t strnlen(const char* s, size_t maxlen);
+#endif
+}
+
+#endif

0 comments on commit bff1407

Please sign in to comment.