blob: 4e67886c4c5210f860279e04ed1fbf936e235d94 [file] [log] [blame]
diff --git a/Makefile b/Makefile
--- a/Makefile
+++ b/Makefile
@@ -9,8 +9,8 @@
include resources/Makefile.in-os
-CPROG = civetweb
#CXXPROG = civetweb
+CPROG = civetweb
BUILD_DIR = out
@@ -92,7 +92,11 @@ LIB_OBJECTS = $(filter-out $(MAIN_OBJECTS), $(BUILD_OBJECTS))
LIBS = -lpthread -lm
-ifeq ($(TARGET_OS),LINUX)
+ifeq ($(TARGET_OS),NACL)
+ LIBS += -Wl,-uPSUserMainGet -lcli_main -lppapi_simple -lnacl_io -lppapi
+endif
+
+ifeq ($(TARGET_OS),LINUX)
LIBS += -ldl
endif
diff --git a/src/civetweb.c b/src/civetweb.c
--- a/src/civetweb.c
+++ b/src/civetweb.c
@@ -222,7 +222,7 @@ struct pollfd {
#else /* UNIX specific */
#include <sys/wait.h>
#include <sys/socket.h>
-#include <sys/poll.h>
+#include <poll.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/time.h>
@@ -330,6 +330,13 @@ typedef int socklen_t;
#define MGSQLEN 20
#endif
+#if defined(__native_client__) && defined(_NEWLIB_VERSION)
+// Newlib doesn't currently implemnt flockfile/funlockfile.
+// TODO(sbc): remove this once newlib is fixed.
+#define flockfile(x)
+#define funlockfile(x)
+#endif
+
static const char *http_500_error = "Internal Server Error";
#if defined(NO_SSL_DL)
diff --git a/src/main.c b/src/main.c
--- a/src/main.c
+++ b/src/main.c
@@ -69,9 +69,17 @@ extern char *_getcwd(char *buf, size_t size);
#include <unistd.h>
#define DIRSEP '/'
#define WINCDECL
+#ifdef __native_client__
+// realpath is currently broken under glibc at least:
+// TODO(sbc): remove once this gets fixed:
+// https://code.google.com/p/nativeclient/issues/detail?id=3717
+#define abs_path(rel, abs, abs_size) strncpy((abs), (rel), (abs_size))
+#else
#define abs_path(rel, abs, abs_size) realpath((rel), (abs))
+#endif
#endif /* _WIN32 */
+
#define MAX_OPTIONS 100
#define MAX_CONF_FILE_LINE_SIZE (8 * 1024)
@@ -1049,8 +1057,28 @@ int main(int argc, char *argv[])
return EXIT_SUCCESS;
}
#else
+
+#ifdef __native_client__
+#include <assert.h>
+#include <sys/mount.h>
+#define main nacl_main
+#endif
+
int main(int argc, char *argv[])
{
+#ifdef __native_client__
+ // Write index.html to HTML5 filesystem
+ int result = chdir("/tmp");
+ assert(result == 0);
+
+ struct stat buf;
+ if (stat("index.html", &buf) != 0) {
+ const char* index_html = "<h1>Civetweb is working!</h1>\n";
+ FILE* f = fopen("index.html", "w+");
+ fwrite(index_html, strlen(index_html), 1, f);
+ fclose(f);
+ }
+#endif
init_server_name();
start_civetweb(argc, argv);
printf("%s started on port(s) %s with web root [%s]\n",
@@ -1067,4 +1095,5 @@ int main(int argc, char *argv[])
return EXIT_SUCCESS;
}
+
#endif /* _WIN32 */