]> Pileus Git - ~andy/fetchmail/commitdiff
STEP 3: File pointer arguments in SockGets()/SockPuts().
authorEric S. Raymond <esr@thyrsus.com>
Thu, 31 Oct 1996 06:29:49 +0000 (06:29 -0000)
committerEric S. Raymond <esr@thyrsus.com>
Thu, 31 Oct 1996 06:29:49 +0000 (06:29 -0000)
svn path=/trunk/; revision=446

driver.c
imap.c
pop2.c
pop3.c
socket.c

index 9e5b6f5686d2cc2fd18fa12f631a5525f1c24dca..5402fba9548f63cf866a700b7f5a93cc9536727a 100644 (file)
--- a/driver.c
+++ b/driver.c
@@ -506,7 +506,7 @@ struct query *ctl;  /* query control record */
     oldlen = 0;
     while (delimited || len > 0)
     {
-       if ((n = SockGets(fileno(sockfp),buf,sizeof(buf))) < 0)
+       if ((n = SockGets(buf,sizeof(buf),sockfp)) < 0)
            return(PS_SOCKET);
        vtalarm(ctl->timeout);
 
@@ -1073,7 +1073,7 @@ va_dcl {
     vsprintf(buf + strlen(buf), fmt, ap);
     va_end(ap);
 
-    SockPuts(fileno(sockfp), buf);
+    SockPuts(buf, sockfp);
 
     if (outlevel == O_VERBOSE)
     {
@@ -1114,7 +1114,7 @@ va_dcl {
   vsprintf(buf + strlen(buf), fmt, ap);
   va_end(ap);
 
-  SockPuts(fileno(sockfp), buf);
+  SockPuts(buf, sockfp);
   if (outlevel == O_VERBOSE)
   {
       char *cp;
diff --git a/imap.c b/imap.c
index 1c64bdc63b75ef0cb932cea8aff5c5d1c2433556..b0e3993670f3db846ea929da5610d9de0e4b07d4 100644 (file)
--- a/imap.c
+++ b/imap.c
@@ -27,7 +27,7 @@ FILE *sockfp;
 
     seen = 0;
     do {
-       if (SockGets(fileno(sockfp), buf, sizeof(buf)) < 0)
+       if (SockGets(buf, sizeof(buf), sockfp) < 0)
            return(PS_SOCKET);
 
        if (outlevel == O_VERBOSE)
@@ -121,7 +121,7 @@ int *sizes;
     char buf [POPBUFSIZE+1];
 
     gen_send(sockfp, "FETCH 1:%d RFC822.SIZE", count);
-    while (SockGets(fileno(sockfp), buf, sizeof(buf)) >= 0)
+    while (SockGets(buf, sizeof(buf), sockfp) >= 0)
     {
        int num, size;
 
@@ -165,7 +165,7 @@ int *lenp;
 
     /* looking for FETCH response */
     do {
-       if (SockGets(fileno(sockfp), buf,sizeof(buf)) < 0)
+       if (SockGets(buf, sizeof(buf), sockfp) < 0)
            return(PS_SOCKET);
     } while
            (sscanf(buf+2, "%d FETCH (RFC822 {%d}", &num, lenp) != 2);
@@ -184,7 +184,7 @@ int number;
 {
     char buf [POPBUFSIZE+1];
 
-    if (SockGets(fileno(sockfp), buf,sizeof(buf)) < 0)
+    if (SockGets(buf, sizeof(buf), sockfp) < 0)
        return(PS_SOCKET);
     else
        return(0);
diff --git a/pop2.c b/pop2.c
index 67313f886f8afdde9a94d04006d8e5f1f5e58fdb..a501c624ad0fecc8f05c6b926e1c9778b91afeaf 100644 (file)
--- a/pop2.c
+++ b/pop2.c
@@ -25,7 +25,7 @@ char *argbuf;
     char buf [POPBUFSIZE+1];
 
     pound_arg = equal_arg = -1;
-    if (SockGets(fileno(sockfp), buf, sizeof(buf)) >= 0) {
+    if (SockGets(buf, sizeof(buf), sockfp) >= 0) {
        if (outlevel == O_VERBOSE)
            fprintf(stderr,"%s\n",buf);
 
diff --git a/pop3.c b/pop3.c
index 74173c1fbd2d8695b7b57f2f4661f15cee398eae..0960085dca5bc4b321add60b7dffeb944ec9b08f 100644 (file)
--- a/pop3.c
+++ b/pop3.c
@@ -31,7 +31,7 @@ char *argbuf;
   char buf [POPBUFSIZE+1];
   char *bufp;
 
-  if (SockGets(fileno(sockfp), buf, sizeof(buf)) >= 0) {
+  if (SockGets(buf, sizeof(buf), sockfp) >= 0) {
     if (outlevel == O_VERBOSE)
       fprintf(stderr,"%s\n",buf);
 
@@ -171,7 +171,7 @@ int *countp, *newp;
                int     num;
 
                *newp = 0;
-               while (SockGets(fileno(sockfp), buf, sizeof(buf)) >= 0)
+               while (SockGets(buf, sizeof(buf), sockfp) >= 0)
                {
                    if (outlevel == O_VERBOSE)
                        fprintf(stderr,"%s\n",buf);
@@ -205,7 +205,7 @@ int *sizes;
     {
        char buf [POPBUFSIZE+1];
 
-       while (SockGets(fileno(sockfp), buf, sizeof(buf)) >= 0)
+       while (SockGets(buf, sizeof(buf), sockfp) >= 0)
        {
            int num, size;
 
index 5033ed451b7d4309d97ddf71d660979ffff46b4b..dff4be58ba0be1710d15981a1ecb3beb09c63c60 100644 (file)
--- a/socket.c
+++ b/socket.c
@@ -77,15 +77,15 @@ int clientPort;
     return sock;
 }
 
-int SockPuts(socket,buf)
-int socket;
+int SockPuts(buf, sockfp)
 char *buf;
+FILE *sockfp;
 {
     int rc;
     
-    if ((rc = SockWrite(socket, buf, strlen(buf))) != 0)
+    if ((rc = SockWrite(fileno(sockfp), buf, strlen(buf))) != 0)
         return rc;
-    return SockWrite(socket, "\r\n", 2);
+    return SockWrite(fileno(sockfp), "\r\n", 2);
 }
 
 int SockWrite(socket,buf,len)
@@ -172,16 +172,16 @@ int len;
     return 0;
 }
 
-int SockGets(socket,buf,len)
-int socket;
+int SockGets(buf, len, sockfp)
 char *buf;
 int len;
+FILE *sockfp;
 {
     int rdlen = 0;
 
     while (--len)
     {
-        if (SockInternalRead(socket, buf, 1) != 1)
+        if (SockInternalRead(fileno(sockfp), buf, 1) != 1)
             return -1;
         else
            rdlen++;
@@ -194,65 +194,6 @@ int len;
     return rdlen;
 }
 
-/* SockDataWaiting: Return a non-zero value if this socket is waiting
-  for data.   */
-int  SockDataWaiting(int socket)
-{
-    int flags;
-    char sbuf[INTERNAL_BUFSIZE];
-    int n;
-    flags = fcntl(socket,F_GETFL,0);
-  
-    /* set it to non-block */
-    if (fcntl(socket,F_SETFL,flags | O_NONBLOCK) == -1)
-       return -1;
-
-    n = recv(socket,sbuf,INTERNAL_BUFSIZE,MSG_PEEK);
-
-    /* reset it to block (or, whatever it was). */
-    fcntl(socket,F_SETFL,flags);
-
-    if (n == -1)
-    { 
-       /* No data to read. */
-       if (errno == EWOULDBLOCK)
-           return(0);
-       else
-           return(-1);
-    }
-    else
-       return(n);
-}
-
-
-/* SockClearHeader: call this procedure in order to kill off any
-   forthcoming Header info from the socket that we no longer want.
-   */
-int SockClearHeader(socket)
-int socket;
-{
-   char *bufp;
-   static char sbuf[INTERNAL_BUFSIZE];
-   int res;
-
-   if ((res = SockDataWaiting(socket)) <= 0)
-     return res;
-
-   while (1) 
-     {
-        if (SockGets(socket,sbuf,INTERNAL_BUFSIZE) < 0)
-         return 0;
-       bufp = sbuf;
-       if (*bufp == '.') {
-         bufp++;
-         if (*bufp == 0)
-           break;
-       }
-     }
-   sbuflen = 0;
-   return 0;
-}
-
 #if defined(HAVE_STDARG_H)
 int SockPrintf(int socket, char* format, ...)
 {