Browse Source

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

master
kevin 11 years ago
parent
commit
7e27581f78
1 changed files with 15 additions and 3 deletions
  1. 15
    3
      cmStrStream.c

+ 15
- 3
cmStrStream.c View File

24
   cmSsBlk_t*  elp;
24
   cmSsBlk_t*  elp;
25
 } cmOss_t;
25
 } cmOss_t;
26
 
26
 
27
+cmStrStreamH_t cmStrStreamNullHandle = cmSTATIC_NULL_HANDLE;
28
+
27
 cmOss_t* _cmOssHandleToPtr( cmStrStreamH_t h )
29
 cmOss_t* _cmOssHandleToPtr( cmStrStreamH_t h )
28
 {
30
 {
29
   cmOss_t* p = (cmOss_t*)h.h;
31
   cmOss_t* p = (cmOss_t*)h.h;
90
 cmSsRC_t cmOStrStreamWrite(     cmStrStreamH_t h, const void* vp, unsigned byteCnt )
92
 cmSsRC_t cmOStrStreamWrite(     cmStrStreamH_t h, const void* vp, unsigned byteCnt )
91
 {
93
 {
92
   cmSsRC_t rc = kOkSsRC;
94
   cmSsRC_t rc = kOkSsRC;
95
+
96
+  if( vp==NULL || byteCnt == 0 )
97
+    return rc;
98
+
93
   cmOss_t* p  = _cmOssHandleToPtr(h);
99
   cmOss_t* p  = _cmOssHandleToPtr(h);
94
   char*    cp = (char*)vp;
100
   char*    cp = (char*)vp;
101
+  unsigned j  = 0;
102
+
95
   do
103
   do
96
   {
104
   {
97
     // if a blk exists
105
     // if a blk exists
99
     {
107
     {
100
       // copy as much of vp[] as possible into the current end block
108
       // copy as much of vp[] as possible into the current end block
101
       unsigned n = cmMin(byteCnt, p->blkByteCnt -  p->elp->i);
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
       byteCnt    -= n;
111
       byteCnt    -= n;
104
-      p->elp->i  += n;      
112
+      p->elp->i  += n;   
113
+      j          += n;
105
     }
114
     }
106
     
115
     
107
     // if all of vp[] has been copied then we are done
116
     // if all of vp[] has been copied then we are done
116
     nbp->i    = 0;
125
     nbp->i    = 0;
117
     nbp->link = NULL;
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
     if( p->elp == NULL )
129
     if( p->elp == NULL )
121
       p->blp = nbp;
130
       p->blp = nbp;
122
     else
131
     else
137
   return cmOStrStreamWrite(h,str,strlen(str));
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
 cmSsRC_t cmOStrStreamVPrintf(   cmStrStreamH_t h, const cmChar_t* fmt, va_list vl )  
152
 cmSsRC_t cmOStrStreamVPrintf(   cmStrStreamH_t h, const cmChar_t* fmt, va_list vl )  
141
 {
153
 {
142
   cmChar_t* s = cmTsVPrintfP(NULL,fmt,vl);
154
   cmChar_t* s = cmTsVPrintfP(NULL,fmt,vl);

Loading…
Cancel
Save