qcopy()

qcopy()

概要

引数

実装

  740: /*
  741:  *  copy from offset in the queue
  742:  */
  743: Block*
  744: qcopy(Queue *q, int len, ulong offset)
  745: {
  746:         int sofar;
  747:         int n;
  748:         Block *b, *nb;
  749:         uchar *p;
  750: 
  751:         nb = allocb(len);
  752: 
  753:         ilock(q);
  754: 
  755:         /* go to offset */
  756:         b = q->bfirst;
  757:         for(sofar = 0; ; sofar += n){
  758:                 if(b == nil){
  759:                         iunlock(q);
  760:                         return nb;
  761:                 }
  762:                 n = BLEN(b);
  763:                 if(sofar + n > offset){
  764:                         p = b->rp + offset - sofar;
  765:                         n -= offset - sofar;
  766:                         break;
  767:                 }
  768:                 QDEBUG checkb(b, "qcopy");
  • 詳細はcheckb()?を参照
  769:                 b = b->next;
  770:         }
  771: 
  772:         /* copy bytes from there */
  773:         for(sofar = 0; sofar < len;){
  774:                 if(n > len - sofar)
  775:                         n = len - sofar;
  776:                 memmove(nb->wp, p, n);
  777:                 qcopycnt += n;
  778:                 sofar += n;
  779:                 nb->wp += n;
  780:                 b = b->next;
  781:                 if(b == nil)
  782:                         break;
  783:                 n = BLEN(b);
  784:                 p = b->rp;
  785:         }
  786:         iunlock(q);
  787: 
  788:         return nb;
  789: }