[BACK]Return to buf.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / make

Diff for /src/usr.bin/make/buf.c between version 1.20 and 1.21

version 1.20, 2004/04/07 13:11:35 version 1.21, 2007/07/24 21:09:07
Line 91 
Line 91 
  *      the end of the buffer to terminate the string.  */   *      the end of the buffer to terminate the string.  */
 #define BufExpand(bp,nb)                                \  #define BufExpand(bp,nb)                                \
 do {                                                    \  do {                                                    \
     size_t   occupied = (bp)->inPtr - (bp)->buffer;     \          size_t   occupied = (bp)->inPtr - (bp)->buffer; \
     size_t   size = (bp)->endPtr - (bp)->buffer;        \          size_t   size = (bp)->endPtr - (bp)->buffer;    \
     DO_STAT_BUF(bp, nb);                                \          DO_STAT_BUF(bp, nb);                            \
                                                         \                                                          \
     do {                                                \          do {                                            \
         size *= 2 ;                                     \                  size *= 2 ;                             \
     } while (size - occupied < (nb)+1+BUF_MARGIN);      \          } while (size - occupied < (nb)+1+BUF_MARGIN);  \
     (bp)->buffer = (bp)->inPtr = (bp)->endPtr =         \          (bp)->buffer = (bp)->inPtr = (bp)->endPtr =     \
         erealloc((bp)->buffer, size);                   \                  erealloc((bp)->buffer, size);           \
     (bp)->inPtr += occupied;                            \          (bp)->inPtr += occupied;                        \
     (bp)->endPtr += size;                               \          (bp)->endPtr += size;                           \
 } while (0);  } while (0);
   
 #define BUF_DEF_SIZE    256     /* Default buffer size */  #define BUF_DEF_SIZE    256     /* Default buffer size */
Line 112 
Line 112 
 void  void
 BufOverflow(Buffer bp)  BufOverflow(Buffer bp)
 {  {
     BufExpand(bp, 1);          BufExpand(bp, 1);
 }  }
   
   
Line 120 
Line 120 
 Buf_AddChars(Buffer bp, size_t numBytes, const char *bytesPtr)  Buf_AddChars(Buffer bp, size_t numBytes, const char *bytesPtr)
 {  {
   
     if ((size_t)(bp->endPtr - bp->inPtr) < numBytes+1)          if ((size_t)(bp->endPtr - bp->inPtr) < numBytes+1)
         BufExpand(bp, numBytes);                  BufExpand(bp, numBytes);
   
     memcpy(bp->inPtr, bytesPtr, numBytes);          memcpy(bp->inPtr, bytesPtr, numBytes);
     bp->inPtr += numBytes;          bp->inPtr += numBytes;
 }  }
   
   
Line 132 
Line 132 
 Buf_Init(Buffer bp, size_t size)  Buf_Init(Buffer bp, size_t size)
 {  {
 #ifdef STATS_BUF  #ifdef STATS_BUF
     STAT_TOTAL_BUFS++;          STAT_TOTAL_BUFS++;
     if (size == 0)          if (size == 0)
         STAT_DEFAULT_BUFS++;                  STAT_DEFAULT_BUFS++;
     if (size == 1)          if (size == 1)
         STAT_WEIRD_BUFS++;                  STAT_WEIRD_BUFS++;
 #endif  #endif
     if (size == 0)          if (size == 0)
         size = BUF_DEF_SIZE;                  size = BUF_DEF_SIZE;
     bp->inPtr = bp->endPtr = bp->buffer = emalloc(size);          bp->inPtr = bp->endPtr = bp->buffer = emalloc(size);
     bp->endPtr += size;          bp->endPtr += size;
 }  }
   
 void  void
 Buf_KillTrailingSpaces(Buffer bp)  Buf_KillTrailingSpaces(Buffer bp)
 {  {
     while (bp->inPtr > bp->buffer + 1 && isspace(bp->inPtr[-1])) {          while (bp->inPtr > bp->buffer + 1 && isspace(bp->inPtr[-1])) {
         if (bp->inPtr[-2] == '\\')                  if (bp->inPtr[-2] == '\\')
             break;                      break;
         bp->inPtr--;                  bp->inPtr--;
     }          }
 }  }

Legend:
Removed from v.1.20  
changed lines
  Added in v.1.21