we mustn't cut the string if we don't find a boundary.
[citadel.git] / libcitadel / lib / stringbuf.c
index 9bc1c8eb04aa9015ab7f5d62abdd50fe5b2d0175..a245c3c37ea81483f8bf1ffd4410e67f28097362 100644 (file)
@@ -1177,7 +1177,6 @@ void StrBufStripAllBut(StrBuf *Buf, char leftboundary, char rightboundary)
        const char *pRight;
 
        if ((Buf == NULL) || (Buf->buf == NULL)) {
-               StrBufCutAt(Buf, 0, Buf->buf);
                return;
        }
 
@@ -1185,19 +1184,11 @@ void StrBufStripAllBut(StrBuf *Buf, char leftboundary, char rightboundary)
        if (pRight != NULL) {
                StrBufCutAt(Buf, 0, pRight);
        }
-       else {
-               StrBufCutAt(Buf, 0, Buf->buf);
-               return;
-       }
 
        pLeft = strrchr(ChrPtr(Buf), leftboundary);
        if (pLeft != NULL) {
                StrBufCutLeft(Buf, pLeft - Buf->buf + 1);
        }
-       else {
-               StrBufCutAt(Buf, 0, Buf->buf);
-               return;
-       }
 }
 
 
@@ -3934,9 +3925,17 @@ long IOBufferStrLength(IOBuffer *FB)
        return StrLength(FB->Buf) - (FB->ReadWritePointer - FB->Buf->buf);
 }
 
-void FDIOBufferInit(FDIOBuffer *FDB, IOBuffer *IO, int FD, long TotalSendSize)
+inline static void FDIOBufferFlush(FDIOBuffer *FDB)
 {
        memset(FDB, 0, sizeof(FDIOBuffer));
+       FDB->OtherFD = -1;
+       FDB->SplicePipe[0] = -1;
+       FDB->SplicePipe[1] = -1;
+}
+
+void FDIOBufferInit(FDIOBuffer *FDB, IOBuffer *IO, int FD, long TotalSendSize)
+{
+       FDIOBufferFlush(FDB);
        FDB->ChunkSize = 
                FDB->TotalSendSize = TotalSendSize;
        FDB->IOB = IO;
@@ -3966,7 +3965,7 @@ void FDIOBufferDelete(FDIOBuffer *FDB)
        
        if (FDB->OtherFD > 0)
                close(FDB->OtherFD);
-       memset(FDB, 0, sizeof(FDIOBuffer));     
+       FDIOBufferFlush(FDB);
 }
 
 int FileSendChunked(FDIOBuffer *FDB, const char **Err)