Skip to content

Instantly share code, notes, and snippets.

@bnoordhuis
Created April 5, 2012 17:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bnoordhuis/ddfdd701f172dd8af63f to your computer and use it in GitHub Desktop.
Save bnoordhuis/ddfdd701f172dd8af63f to your computer and use it in GitHub Desktop.
diff --git a/src/node_file.cc b/src/node_file.cc
index 60c094b..b6518d2 100644
--- a/src/node_file.cc
+++ b/src/node_file.cc
@@ -682,12 +682,14 @@ static Handle<Value> Open(const Arguments& args) {
#ifndef _LARGEFILE_SOURCE
#define ASSERT_OFFSET(a) \
+ STATIC_ASSERT(sizeof(off_t) * CHAR_BIT >= 64); \
if (!(a)->IsUndefined() && !(a)->IsNull() && !(a)->IsInt32()) { \
return ThrowException(Exception::TypeError(String::New("Not an integer"))); \
}
#define GET_OFFSET(a) ((a)->IsNumber() ? (a)->Int32Value() : -1)
#else
#define ASSERT_OFFSET(a) \
+ STATIC_ASSERT(sizeof(off_t) * CHAR_BIT >= 64); \
if (!(a)->IsUndefined() && !(a)->IsNull() && !IsInt64((a)->NumberValue())) { \
return ThrowException(Exception::TypeError(String::New("Not an integer"))); \
}
diff --git a/src/node_internals.h b/src/node_internals.h
index 8d07392..2f9611c 100644
--- a/src/node_internals.h
+++ b/src/node_internals.h
@@ -60,6 +60,10 @@ inline static int snprintf(char* buf, unsigned int len, const char* fmt, ...) {
# define ROUND_UP(a, b) ((a) % (b) ? ((a) + (b)) - ((a) % (b)) : (a))
#endif
+#ifndef STATIC_ASSERT
+# define STATIC_ASSERT(expr) static_cast<void>((sizeof(char[-1 + !!(expr)])))
+#endif
+
// this would have been a template function were it not for the fact that g++
// sometimes fails to resolve it...
#define THROW_ERROR(fun) \
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment