瀏覽代碼

cmStrStream.c : Completed initial tests and fixed bugs in cmOStrStreamWrite().

master
kevin 11 年之前
父節點
當前提交
7e27581f78
共有 1 個檔案被更改,包括 15 行新增3 行删除
  1. 15
    3
      cmStrStream.c

+ 15
- 3
cmStrStream.c 查看文件

@@ -24,6 +24,8 @@ typedef struct
24 24
   cmSsBlk_t*  elp;
25 25
 } cmOss_t;
26 26
 
27
+cmStrStreamH_t cmStrStreamNullHandle = cmSTATIC_NULL_HANDLE;
28
+
27 29
 cmOss_t* _cmOssHandleToPtr( cmStrStreamH_t h )
28 30
 {
29 31
   cmOss_t* p = (cmOss_t*)h.h;
@@ -90,8 +92,14 @@ bool     cmOStrStreamIsValid( cmStrStreamH_t h )
90 92
 cmSsRC_t cmOStrStreamWrite(     cmStrStreamH_t h, const void* vp, unsigned byteCnt )
91 93
 {
92 94
   cmSsRC_t rc = kOkSsRC;
95
+
96
+  if( vp==NULL || byteCnt == 0 )
97
+    return rc;
98
+
93 99
   cmOss_t* p  = _cmOssHandleToPtr(h);
94 100
   char*    cp = (char*)vp;
101
+  unsigned j  = 0;
102
+
95 103
   do
96 104
   {
97 105
     // if a blk exists
@@ -99,9 +107,10 @@ cmSsRC_t cmOStrStreamWrite(     cmStrStreamH_t h, const void* vp, unsigned byteC
99 107
     {
100 108
       // copy as much of vp[] as possible into the current end block
101 109
       unsigned n = cmMin(byteCnt, p->blkByteCnt -  p->elp->i);
102
-      memcpy(p->elp->blk,cp,n);
110
+      memcpy(p->elp->blk + p->elp->i,cp + j,n);
103 111
       byteCnt    -= n;
104
-      p->elp->i  += n;      
112
+      p->elp->i  += n;   
113
+      j          += n;
105 114
     }
106 115
     
107 116
     // if all of vp[] has been copied then we are done
@@ -116,7 +125,7 @@ cmSsRC_t cmOStrStreamWrite(     cmStrStreamH_t h, const void* vp, unsigned byteC
116 125
     nbp->i    = 0;
117 126
     nbp->link = NULL;
118 127
 
119
-    // end the new blk onto the end of the list
128
+    // append the new blk onto the end of the list
120 129
     if( p->elp == NULL )
121 130
       p->blp = nbp;
122 131
     else
@@ -137,6 +146,9 @@ cmSsRC_t cmOStrStreamWriteStr(  cmStrStreamH_t h, const cmChar_t* str )
137 146
   return cmOStrStreamWrite(h,str,strlen(str));
138 147
 }
139 148
 
149
+cmSsRC_t cmOStrStreamWriteStrN( cmStrStreamH_t h, const cmChar_t* str, unsigned n )
150
+{ return cmOStrStreamWrite(h,str,n); }
151
+
140 152
 cmSsRC_t cmOStrStreamVPrintf(   cmStrStreamH_t h, const cmChar_t* fmt, va_list vl )  
141 153
 {
142 154
   cmChar_t* s = cmTsVPrintfP(NULL,fmt,vl);

Loading…
取消
儲存