[or-cvs] Make tor build on windows again. More work still needed

Nick Mathewson nickm at seul.org
Tue Mar 9 22:01:18 UTC 2004


Update of /home/or/cvsroot/src/common
In directory moria.mit.edu:/tmp/cvs-serv14774/src/common

Modified Files:
	fakepoll.c log.c tortls.c util.c util.h 
Log Message:
Make tor build on windows again. More work still needed

Index: fakepoll.c
===================================================================
RCS file: /home/or/cvsroot/src/common/fakepoll.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- fakepoll.c	20 Feb 2004 23:41:45 -0000	1.16
+++ fakepoll.c	9 Mar 2004 22:01:16 -0000	1.17
@@ -32,7 +32,7 @@
 int
 tor_poll(struct pollfd *ufds, unsigned int nfds, int timeout)
 {
-        int idx, maxfd, fd;
+        unsigned int idx, maxfd, fd;
         int r;
 #ifdef MS_WINDOWS
         int any_fds_set = 0;

Index: log.c
===================================================================
RCS file: /home/or/cvsroot/src/common/log.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -d -r1.30 -r1.31
--- log.c	17 Dec 2003 21:14:13 -0000	1.30
+++ log.c	9 Mar 2004 22:01:16 -0000	1.31
@@ -2,7 +2,10 @@
 /* See LICENSE for licensing information */
 /* $Id$ */
 
-#include "../or/or.h"
+#include "../or/or.h"
+#ifdef MS_WINDOWS
+#define vsnprintf _vsnprintf
+#endif
 
 struct logfile_t;
 typedef struct logfile_t {
@@ -35,7 +38,7 @@
 {
   time_t t;
   struct timeval now;
-  int n;
+  size_t n;
 
   buf_len -= 2; /* subtract 2 characters so we have room for \n\0 */
 

Index: tortls.c
===================================================================
RCS file: /home/or/cvsroot/src/common/tortls.c,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -d -r1.36 -r1.37
--- tortls.c	28 Feb 2004 23:21:29 -0000	1.36
+++ tortls.c	9 Mar 2004 22:01:16 -0000	1.37
@@ -493,7 +493,7 @@
   lenout = X509_NAME_get_text_by_NID(name, nid, buf, buflen);
   if (lenout == -1)
     goto error;
-  if (strspn(buf, LEGAL_NICKNAME_CHARACTERS) != lenout) {
+  if (((int)strspn(buf, LEGAL_NICKNAME_CHARACTERS)) < lenout) {
     log_fn(LOG_WARN, "Peer certificate nickname has illegal characters.");
     goto error;
   }

Index: util.c
===================================================================
RCS file: /home/or/cvsroot/src/common/util.c,v
retrieving revision 1.55
retrieving revision 1.56
diff -u -d -r1.55 -r1.56
--- util.c	2 Mar 2004 04:59:52 -0000	1.55
+++ util.c	9 Mar 2004 22:01:16 -0000	1.56
@@ -283,7 +283,7 @@
 /* a wrapper for write(2) that makes sure to write all count bytes.
  * Only use if fd is a blocking fd. */
 int write_all(int fd, const char *buf, size_t count) {
-  int written = 0;
+  size_t written = 0;
   int result;
 
   while(written != count) {
@@ -298,7 +298,7 @@
 /* a wrapper for read(2) that makes sure to read all count bytes.
  * Only use if fd is a blocking fd. */
 int read_all(int fd, char *buf, size_t count) {
-  int numread = 0;
+  size_t numread = 0;
   int result;
 
   while(numread != count) {
@@ -506,7 +506,8 @@
 /* Check whether dirname exists and is private.  If yes returns
    0.  Else returns -1. */
 int check_private_dir(const char *dirname, int create)
-{
+{
+  int r;
   struct stat st;
   if (stat(dirname, &st)) {
     if (errno != ENOENT) {
@@ -518,8 +519,13 @@
       log(LOG_WARN, "Directory %s does not exist.", dirname);
       return -1;
     }
-    log(LOG_INFO, "Creating directory %s", dirname);
-    if (mkdir(dirname, 0700)) {
+    log(LOG_INFO, "Creating directory %s", dirname);
+#ifdef MS_WINDOWS
+	r = mkdir(dirname);
+#else
+	r = mkdir(dirname, 0700);
+#endif
+    if (r) {
       log(LOG_WARN, "Error creating directory %s: %s", dirname,
           strerror(errno));
       return -1;
@@ -530,7 +536,8 @@
   if (!(st.st_mode & S_IFDIR)) {
     log(LOG_WARN, "%s is not a directory", dirname);
     return -1;
-  }
+  }
+#ifndef MS_WINDOWS
   if (st.st_uid != getuid()) {
     log(LOG_WARN, "%s is not owned by this UID (%d)", dirname, (int)getuid());
     return -1;
@@ -544,7 +551,8 @@
     } else {
       return 0;
     }
-  }
+  }
+#endif
   return 0;
 }
 
@@ -787,7 +795,7 @@
 }
 #else
 /* defined(MS_WINDOWS) */
-void start_daemon(void) {}
+void start_daemon(char *cp) {}
 void finish_daemon(void) {}
 #endif
 
@@ -855,3 +863,22 @@
   return -1;
 }
 
+int tor_inet_aton(const char *c, struct in_addr* addr)
+{
+#ifndef MS_WINDOWS
+  /* XXXX WWWW Should be HAVE_INET_ATON */
+  return inet_aton(c, addr);
+#else
+  uint32_t r;
+  assert(c && addr);
+  if (strcmp(c, "255.255.255.255") == 0) {
+	addr->s_addr = 0xFFFFFFFFu;
+	return 1;
+  }
+  r = inet_addr(c);
+  if (r == INADDR_NONE)
+	return 0;
+  addr->s_addr = r;
+  return 1;
+#endif
+}
\ No newline at end of file

Index: util.h
===================================================================
RCS file: /home/or/cvsroot/src/common/util.h,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- util.h	28 Feb 2004 23:21:29 -0000	1.31
+++ util.h	9 Mar 2004 22:01:16 -0000	1.32
@@ -101,6 +101,9 @@
 
 void write_pidfile(char *filename);
 int switch_id(char *user, char *group);
+
+struct in_addr;
+int tor_inet_aton(const char *cp, struct in_addr *addr);
 
 /* For stupid historical reasons, windows sockets have an independent set of
  * errnos which they use as the fancy strikes them.



More information about the tor-commits mailing list