]> code.citadel.org Git - citadel.git/blobdiff - citadel/clientsocket.c
- port to Cygwin (DLL support, etc.)
[citadel.git] / citadel / clientsocket.c
index f645e9261cd231e205ab6f8ab7449cccb2251063..286659aef946e8e4787c3253972ae740d196a51c 100644 (file)
@@ -8,6 +8,10 @@
  *
  */
 
+#ifdef DLL_EXPORT
+#define IN_LIBCIT
+#endif
+
 #include "sysdep.h"
 #include <stdlib.h>
 #include <unistd.h>
@@ -23,6 +27,8 @@
 #include <errno.h>
 #include <stdarg.h>
 #include "citadel.h"
+#include "server.h"
+#include "dynloader.h"
 #ifndef HAVE_SNPRINTF
 #include "snprintf.h"
 #endif
@@ -138,13 +144,13 @@ int sock_gets(int sock, char *buf)
         */
        for (i = 0;; i++) {
                if (sock_read(sock, &buf[i], 1) < 0) return(-1);
-               if (buf[i] == '\n' || i == 255)
+               if (buf[i] == '\n' || i == (SIZ-1))
                        break;
        }
 
        /* If we got a long line, discard characters until the newline.
         */
-       if (i == 255)
+       if (i == (SIZ-1))
                while (buf[i] != '\n')
                        if (sock_read(sock, &buf[i], 1) < 0) return(-1);
 
@@ -169,8 +175,8 @@ int ml_sock_gets(int sock, char *buf) {
        int g;
 
        g = sock_gets(sock, buf);
-       if (g < 0) return(g);
-       if ( (g < 4) || (buf[3] != '-')) return(g);
+       if (g < 4) return(g);
+       if (buf[3] != '-') return(g);
 
        do {
                g = sock_gets(sock, bigbuf);
@@ -195,3 +201,19 @@ int sock_puts(int sock, char *buf)
        if (j<0) return(j);
        return(i+j);
 }
+
+
+/*
+ * sock_puts_crlf() - same as sock_puts() but ends line with CRLF, not LF
+ * Returns the number of bytes written, or -1 for error.
+ */
+int sock_puts_crlf(int sock, char *buf)
+{
+       int i, j;
+
+       i = sock_write(sock, buf, strlen(buf));
+       if (i<0) return(i);
+       j = sock_write(sock, "\r\n", 2);
+       if (j<0) return(j);
+       return(i+j);
+}