]> code.citadel.org Git - citadel.git/blobdiff - libcitadel/lib/stringbuf.c
BSD compatibility: add missing include for AF_INET
[citadel.git] / libcitadel / lib / stringbuf.c
index bc54f82cfa4956ec5cd819e916a5cb1ad8094daa..892963152b0c653c3f18449c9f51e247f96aef11 100644 (file)
@@ -3862,9 +3862,9 @@ int FileSendChunked(FDIOBuffer *FDB, const char **Err)
 
 int FileRecvChunked(FDIOBuffer *FDB, const char **Err)
 {
+       ssize_t sent, pipesize;
 
 #ifdef LINUX_SENDFILE
-       ssize_t sent, pipesize;
 
        pipesize = splice(FDB->IOB->fd, NULL, 
                          FDB->SplicePipe[1], NULL, 
@@ -3887,6 +3887,33 @@ int FileRecvChunked(FDIOBuffer *FDB, const char **Err)
        FDB->ChunkSendRemain -= sent;
        return sent;
 #else
+       
+       sent = read(FDB->IOB->fd, FDB->ChunkBuffer->buf, FDB->ChunkSendRemain);
+       if (sent > 0) {
+               int nWritten = 0;
+               int rc; 
+               
+               FDB->ChunkBuffer->BufUsed = sent;
+
+               while (nWritten < FDB->ChunkBuffer->BufUsed) {
+                       rc =  write(FDB->OtherFD, FDB->ChunkBuffer->buf + nWritten, FDB->ChunkBuffer->BufUsed - nWritten);
+                       if (rc < 0) {
+                               *Err = strerror(errno);
+                               return rc;
+                       }
+                       nWritten += rc;
+
+               }
+               FDB->ChunkBuffer->BufUsed = 0;
+               FDB->TotalSentAlready += sent;
+               FDB->ChunkSendRemain -= sent;
+               return FDB->ChunkSendRemain;
+       }
+       else if (sent < 0) {
+               *Err = strerror(errno);
+               return sent;
+       }
+
 #endif
        return 0;
 }
@@ -4628,9 +4655,10 @@ void StrBufStripSlashes(StrBuf *Dir, int RemoveTrailingSlash)
                        b++; a++;
                }
        }
-       if ((RemoveTrailingSlash) && (*(b - 1) != '/')){
-               *b = '/';
-               b++;
+       if ((RemoveTrailingSlash) &&
+           (b > Dir->buf) && 
+           (*(b - 1) == '/')){
+               b--;
        }
        *b = '\0';
        Dir->BufUsed = b - Dir->buf;