• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ putbuf函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中putbuf函数的典型用法代码示例。如果您正苦于以下问题:C++ putbuf函数的具体用法?C++ putbuf怎么用?C++ putbuf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了putbuf函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: end_delim

// Call to indicate the end of a delimited region.  We now know the length of
// the delimited region.  If we are not nested inside any other delimited
// regions, we can now emit all of the buffered data we accumulated.
static bool end_delim(upb_pb_encoder *e) {
  accumulate(e);
  size_t msglen = top(e)->msglen;

  if (e->top == e->stack) {
    // All lengths are now available, emit all buffered data.
    char buf[UPB_PB_VARINT_MAX_LEN];
    upb_pb_encoder_segment *s;
    const char *ptr = e->buf;
    for (s = e->segbuf; s <= e->segptr; s++) {
      size_t lenbytes = upb_vencode64(s->msglen, buf);
      putbuf(e, buf, lenbytes);
      putbuf(e, ptr, s->seglen);
      ptr += s->seglen;
    }

    e->ptr = e->buf;
    e->top = NULL;
  } else {
    // Need to keep buffering; propagate length info into enclosing submessages.
    --e->top;
    top(e)->msglen += msglen + upb_varint_size(msglen);
  }

  return true;
}
开发者ID:gityf,项目名称:upb,代码行数:29,代码来源:encoder.c


示例2: syscall_write

static int
syscall_write (int fd, const char *buffer, unsigned size) 
{
	struct file *f;

	/* if the FD is 1, write to STDOUT */
	if (fd == 1) {
		const int max_out = 256;
		int remained = size;

		while (remained > max_out) {
			putbuf(buffer, max_out);
			buffer += max_out;
			remained -= max_out;
		}
		putbuf(buffer, remained);
		
		// actuall size of bytes written is (size - i)
		return (int)size;
	}

	/* normal case */
	f = process_file_find (fd);
	if (f == NULL)
		return -1;
	return file_write(f, buffer, size);
}
开发者ID:LeeHyunJae,项目名称:pintostest,代码行数:27,代码来源:syscall.c


示例3: fwormwrite

int
fwormwrite(Device *d, Off b, void *c)
{
	Iobuf *p;
	Device *fdev;
	Devsize l;

	if(chatty > 1)
		fprint(2, "fworm write %lld\n", (Wideoff)b);
	fdev = FDEV(d);
	l = devsize(fdev);
	l -= l/(BUFSIZE*8) + 1;
	if(b >= l)
		panic("fworm: wbounds %lld", (Wideoff)b);
	l += b/(BUFSIZE*8);

	p = getbuf(fdev, l, Brd|Bmod|Bres);
	if(!p || checktag(p, Tvirgo, l))
		panic("fworm: checktag %lld", (Wideoff)l);
	l = b % (BUFSIZE*8);
	if((p->iobuf[l/8] & (1<<(l%8)))) {
		putbuf(p);
		fprint(2, "fworm: write %lld\n", (Wideoff)b);
		return 1;
	}
	p->iobuf[l/8] |= 1<<(l%8);
	putbuf(p);
	return devwrite(fdev, b, c);
}
开发者ID:Nurb432,项目名称:plan9front,代码行数:29,代码来源:fworm.c


示例4: indfetch

long
indfetch(Iobuf *p, Dentry *d, long addr, long a, int itag, int tag)
{
	Iobuf *bp;

	if(!addr)
		return 0;
	bp = getbuf(p->dev, addr, Bread);
	if(!bp || checktag(bp, itag, d->qid.path)) {
		if(!bp) {
			print("ind fetch bp = 0\n");
			return 0;
		}
		print("ind fetch tag\n");
		putbuf(bp);
		return 0;
	}
	addr = ((long*)bp->iobuf)[a];
	if(!addr && tag) {
		addr = balloc(p->dev, tag, d->qid.path);
		if(addr) {
			((long*)bp->iobuf)[a] = addr;
			bp->flags |= Bmod;
			if(localfs || tag == Tdir)
				bp->flags |= Bimm;
			settag(bp, itag, d->qid.path);
		}
	}
	putbuf(bp);
	return addr;
}
开发者ID:99years,项目名称:plan9,代码行数:31,代码来源:dentry.c


示例5: sysexit

void
sysexit(int status)
{
	// Print Process Termination Message
	// File Name	
	char* name = thread_current()->name;
	char* token, *save_ptr;
	token = strtok_r(name, " ", &save_ptr);
	putbuf (token, strlen(token));

	char* str1 = ": exit(";
	putbuf (str1, strlen(str1));

	// ExitStatus
	char strstatus[32];
	snprintf(strstatus, 32, "%d", status);
	putbuf (strstatus, strlen(strstatus));

	char* str2 = ")\n";
	putbuf (str2, strlen(str2));

	// EXIT Child Processes
	if(thread_current()->numchild > 0)
	{
		struct list_elem * e;
		while (!list_empty(&thread_current()->child_list))
		{
			e = list_pop_front(&thread_current()->child_list);
			struct childproc * childitem = list_entry (e, struct childproc, elem);
			if(!exit_remove(childitem->childid))
			{
				list_push_back(&ignore_list, &childitem->elem);
			}
			else
			{
				free(childitem);
			}
		}
	}

	// Save exit status
	struct exitstatus * es = (struct exitstatus *) malloc(sizeof(struct exitstatus));
	if(es != NULL && !ignore_remove(thread_current()->tid))
	{
		es->avail = true;
		es->status = status;
		es->childid = thread_current()->tid;
		list_push_back(&exit_list, &es->elem);

		struct list_elem * e;
		for (e = list_begin (&waitproc_list); e != list_end (&waitproc_list); e = list_next (e))
		{
			struct waitproc * item = list_entry (e, struct waitproc, elem);
			sema_up(&item->sema);	
		}
	}
开发者ID:rdspring1,项目名称:Porsche911,代码行数:56,代码来源:syscall.c


示例6: buffree

/*
 * free the block at `addr' on dev.
 * if it's an indirect block (d [depth] > 0),
 * first recursively free all the blocks it names.
 *
 * ts->relblk is the block number within the file of this
 * block (or the first data block eventually pointed to via
 * this indirect block).
 */
void
buffree(Device *dev, Off addr, int d, Truncstate *ts)
{
	Iobuf *p;
	Off a;
	int i, pastlast;

	if(!addr)
		return;
	pastlast = (ts == nil? 1: ts->pastlast);
	/*
	 * if this is an indirect block, recurse and free any
	 * suitable blocks within it (possibly via further indirect blocks).
	 */
	if(d > 0) {
		d--;
		p = getbuf(dev, addr, Brd);
		if(p) {
			if (ts == nil)		/* common case: create */
				for(i=INDPERBUF-1; i>=0; i--) {
					a = ((Off *)p->iobuf)[i];
					buffree(dev, a, d, nil);
				}
			else			/* wstat truncation */
				for (i = 0; i < INDPERBUF; i++)
					truncfree(ts, dev, d, p, i);
			putbuf(p);
		}
	}
	if (!pastlast)
		return;
	/*
	 * having zeroed the pointer to this block, add it to the free list.
	 * stop outstanding i/o
	 */
	p = getbuf(dev, addr, Bprobe);
	if(p) {
		p->flags &= ~(Bmod|Bimm);
		putbuf(p);
	}
	/*
	 * dont put written worm
	 * blocks into free list
	 */
	if(dev->type == Devcw) {
		i = cwfree(dev, addr);
		if(i)
			return;
	}
	p = getbuf(dev, superaddr(dev), Brd|Bmod);
	if(!p || checktag(p, Tsuper, QPSUPER))
		panic("buffree: super block");
	addfree(dev, addr, (Superb*)p->iobuf);
	putbuf(p);
}
开发者ID:npe9,项目名称:harvey,代码行数:64,代码来源:sub.c


示例7: rel2abs

long
rel2abs(Iobuf *p, Dentry *d, long a, int tag, int putb)
{
	long addr, qpath;
	Device dev;

	if(a < 0) {
		print("dnodebuf: neg\n");
		return 0;
	}
	qpath = d->qid.path;
	dev = p->dev;
	if(a < NDBLOCK) {
		addr = d->dblock[a];
		if(!addr && tag) {
			addr = balloc(dev, tag, qpath);
			d->dblock[a] = addr;
			p->flags |= Bmod|Bimm;
		}
		if(putb)
			putbuf(p);
		return addr;
	}
	a -= NDBLOCK;
	if(a < INDPERBUF) {
		addr = d->iblock;
		if(!addr && tag) {
			addr = balloc(dev, Tind1, qpath);
			d->iblock = addr;
			p->flags |= Bmod|Bimm;
		}
		if(putb)
			putbuf(p);
		addr = indfetch(p, d, addr, a, Tind1, tag);
		return addr;
	}
	a -= INDPERBUF;
	if(a < INDPERBUF2) {
		addr = d->diblock;
		if(!addr && tag) {
			addr = balloc(dev, Tind2, qpath);
			d->diblock = addr;
			p->flags |= Bmod|Bimm;
		}
		if(putb)
			putbuf(p);
		addr = indfetch(p, d, addr, a/INDPERBUF, Tind2, Tind1);
		addr = indfetch(p, d, addr, a%INDPERBUF, Tind1, tag);
		return addr;
	}
	if(putb)
		putbuf(p);
	print("dnodebuf: trip indirect\n");
	return 0;
}
开发者ID:99years,项目名称:plan9,代码行数:55,代码来源:dentry.c


示例8: dopush

static void dopush(poffHandle_t poffHandle, poffProgHandle_t poffProgHandle)
{
  int opcode;

  while (inch != EOF)
    {
      /* Search for a PUSHS opcode */

      if (inch != oPUSHS)
        {
          /* Its not PUSHS, just echo to the output file/buffer */

          putbuf(inch, poffProgHandle);

          /* Get the next byte from the input stream */

          opcode = inch;
          inch = poffGetProgByte(poffHandle);

          /* Check for an 8-bit argument */

          if ((opcode & o8) != 0)
            {
              /* Echo the 8-bit argument */

              putbuf(inch, poffProgHandle);
              inch = poffGetProgByte(poffHandle);
            }

          /* Check for a 16-bit argument */

          if ((opcode & o16) != 0)
            {
              /* Echo the 16-bit argument */

              putbuf(inch, poffProgHandle);
              inch = poffGetProgByte(poffHandle);
              putbuf(inch, poffProgHandle);
              inch = poffGetProgByte(poffHandle);
            }
        }
      else
        {
          /* We have found PUSHS.  No search for the next occurrence
           * of either and instruction that increments the string
           * stack or for the matching POPS
           */

          current_level++;
          dopop(poffHandle, poffProgHandle);
          current_level--;
        }
    }
}
开发者ID:0919061,项目名称:PX4NuttX,代码行数:54,代码来源:psopt.c


示例9: doclri

int
doclri(File *f)
{
	Iobuf *p, *p1;
	Dentry *d, *d1;
	int err;

	err = 0;
	p = 0;
	p1 = 0;
	if(f->fs->dev->type == Devro) {
		err = Eronly;
		goto out;
	}
	/*
	 * check on parent directory of file to be deleted
	 */
	if(f->wpath == 0 || f->wpath->addr == f->addr) {
		err = Ephase;
		goto out;
	}
	p1 = getbuf(f->fs->dev, f->wpath->addr, Brd);
	d1 = getdir(p1, f->wpath->slot);
	if(!d1 || checktag(p1, Tdir, QPNONE) || !(d1->mode & DALLOC)) {
		err = Ephase;
		goto out;
	}

	accessdir(p1, d1, FWRITE, 0);
	putbuf(p1);
	p1 = 0;

	/*
	 * check on file to be deleted
	 */
	p = getbuf(f->fs->dev, f->addr, Brd);
	d = getdir(p, f->slot);

	/*
	 * do it
	 */
	memset(d, 0, sizeof(Dentry));
	settag(p, Tdir, QPNONE);
	freewp(f->wpath);
	freefp(f);

out:
	if(p1)
		putbuf(p1);
	if(p)
		putbuf(p);
	return err;
}
开发者ID:Nurb432,项目名称:plan9front,代码行数:53,代码来源:console.c


示例10: ckfreelist

static
void
ckfreelist(Superb *sb)
{
	long a, lo, hi;
	int n, i;
	Iobuf *p;
	Fbuf *fb;


	strcpy(name, "free list");
	cprint("check %s\n", name);
	fb = &sb->fbuf;
	a = sbaddr;
	p = 0;
	lo = 0;
	hi = 0;
	for(;;) {
		n = fb->nfree;
		if(n < 0 || n > FEPERBUF) {
			cprint("check: nfree bad %ld\n", a);
			break;
		}
		for(i=1; i<n; i++) {
			a = fb->free[i];
			if(a && !fmark(a)) {
				if(!lo || lo > a)
					lo = a;
				if(!hi || hi < a)
					hi = a;
			}
		}
		a = fb->free[0];
		if(!a)
			break;
		if(fmark(a))
			break;
		if(!lo || lo > a)
			lo = a;
		if(!hi || hi < a)
			hi = a;
		if(p)
			putbuf(p);
		p = xtag(a, Tfree, QPNONE);
		if(!p)
			break;
		fb = (Fbuf*)p->iobuf;
	}
	if(p)
		putbuf(p);
	cprint("lo = %ld; hi = %ld\n", lo, hi);
}
开发者ID:99years,项目名称:plan9,代码行数:52,代码来源:chk.c


示例11: sys_write

/**
 * Skriver till fd (skärm eller fil)
 * Returnerar antalet skrivna tecken eller -1 om antalet tecken som ska skrivas
 * är 0 eller om filen inte finns.
 */
int sys_write(int fd, const void* buffer, unsigned length)
{
    if (fd == STDIN_FILENO) // Vi kan inte skriva till tangentbordet
    {
        return -1;
    }

    if (fd == STDOUT_FILENO) // skärmen
    {
        putbuf(buffer, length);
        return length;
    }
    else
    {
        // Skriva till fil
        struct file* write_to = map_find(get_filemap(), fd);
        if(write_to != NULL)
        {
            // Skriver buffer till write_to. Returnerar antalet skrivna tecken
            // Kan returnera ett antal tecken < length om filen är för liten
            return file_write(write_to, buffer, length);
        }
        else
        {
            return -1; // Filen finns inte, eller så ville vi skriva 0 tecken.
        }
    }
    // Hit ska vi inte komma!
}
开发者ID:blomqvist,项目名称:pintos,代码行数:34,代码来源:sys_file_calls.c


示例12: written

/* Writes up to size bytes from buffer to the file open with descriptor fd,
   and returns the actual number written (may be less than size if EOF is 
   reached), or -1 if no file is open as fd or the write fails for another
   reason.  Writing to 1 will print to standard output */
static int 
sys_write (int fd, const void *buffer, unsigned size) 
{
  int written;
  struct file_fd *ffd;
  
  check_ptr (buffer);
  
  switch (fd) {
  case 0:
    return 0;
  case 1:
    putbuf ((char *) buffer, size);
    return size;
  case 2:
    return 0;
  default:
    ffd = get_file_fd (fd);
    if (ffd == NULL)
      return 0;
    
    lock_acquire (&fs_lock);
    written = file_write (ffd->file, buffer, size);
    lock_release (&fs_lock);
    return written;
  }
}
开发者ID:blondiebytes,项目名称:OS-334,代码行数:31,代码来源:syscall.c


示例13: write

int write (int fd, const void *buffer, unsigned size)
{
  if (fd == STDIN_FILENO)
    return -1;

  if (fd == STDOUT_FILENO)
  {
    putbuf ((const char*)buffer, size);
    return size;
  }

  lock_acquire (&filesys_lock);

  struct file *f = process_get_file (fd);
  if (!f)
  {
    lock_release (&filesys_lock);
    return -1;
  }

  int bytes = file_write (f, buffer, size);

  lock_release (&filesys_lock);

  return bytes;
}
开发者ID:idoitlpg,项目名称:pintos,代码行数:26,代码来源:syscall.c


示例14: SYS_WRITE_handler

int SYS_WRITE_handler(int32_t* esp)
{
  // Default to error...
  int retVal = -1;

  int fd = *(esp + 1);
  char* buffer = (char*)*(esp + 2);
  int len = *(esp + 3);
	
  if(verify_fix_length(esp[2], esp[3]) == false){
	sys_exit(-1);
  }
  if(fd == STDOUT_FILENO){

    putbuf(buffer, len);
    // Since we wrote data, set return value to bytes written.
    retVal = len;
  } else if(fd > 1){

	// A file descriptor has been used.
	struct file* file = flist_get_process_file(fd);
	if(file != NULL){
		retVal = file_write(file, buffer, len);
	}
	
  }

  return retVal;
}
开发者ID:posijon,项目名称:PintOS,代码行数:29,代码来源:syscall.c


示例15: checkindir

static
int
checkindir(long a, Dentry *d, long qpath)
{
	Iobuf *p;
	int i, dmod;

	dmod = touch(a);
	p = xtag(a, Tind1, qpath);
	if(!p)
		return dmod;
	for(i=0; i<INDPERBUF; i++) {
		a = ((long*)p->iobuf)[i];
		if(!a)
			continue;
		if(amark(a)) {
			if(flags & Cbad) {
				((long*)p->iobuf)[i] = 0;
				p->flags |= Bmod;
			}
			continue;
		}
		if(d->mode & DDIR)
			dmod += checkdir(a, qpath);
		else if(flags & Crdall)
			xread(a, qpath);
	}
	putbuf(p);
	return dmod;
}
开发者ID:99years,项目名称:plan9,代码行数:30,代码来源:chk.c


示例16: sys_write

/* Write to a file. */
static int
sys_write (int fd, const void *buffer, unsigned size)
{
  struct user_file *f;
  int ret = -1;

#if PRINT_DEBUG
  printf ("[SYSCALL] SYS_WRITE: fd: %d, buffer: %p, size: %u\n", fd, buffer, size);
#endif

  if (fd == STDIN_FILENO)
    ret = -1;
  else if (fd == STDOUT_FILENO)
    {
      putbuf (buffer, size);
      ret = size;
    }
  else if (!is_user_vaddr (buffer) || !is_user_vaddr (buffer + size))
    sys_exit (-1);
  else
    {
      f = file_by_fid (fd);
      if (f == NULL)
        ret = -1;
      else
        {
          lock_acquire (&file_lock);
          ret = file_write (f->file, buffer, size);
          lock_release (&file_lock);
        }
    }
  return ret;
}
开发者ID:roooot,项目名称:pintos,代码行数:34,代码来源:syscall.c


示例17: syscall_write

/*
 * write to either file or console
 */
void
syscall_write (struct intr_frame *f)
{
  const int argz = 3;
  int args[argz];
  syscall_get_args(f,args,argz);
  syscall_check_arg_buffer_or_exit((const void *)args[1], (unsigned) args[2]);
  args[1] = syscall_user_to_kernel_vaddr((const void*) args[1]);

  if(args[0] == STDOUT_FILENO)
  {
    putbuf ((const void*) args[1], (size_t) args[2]);
    f->eax = (int) args[2];
    return;
  }
  lock_acquire (&flock);
  struct file *file = process_get_file (args[0]);
  if (file == NULL)
  {
    f->eax = -1;
    lock_release (&flock);
    return;
  }
  f->eax = file_write (file, (const void*) args[1], (off_t) args[2] );
  lock_release (&flock);
}
开发者ID:mandrizzle,项目名称:ASAP_OS,代码行数:29,代码来源:syscall.c


示例18: write

int
write(int fd, const void *buffer, unsigned size)
{
    if (fd == STDOUT_FILENO) {
        lock_acquire(&filesys_lock);
        putbuf(buffer, size);
        lock_release(&filesys_lock);
        return size;
    } else {
        struct thread *t = thread_current();
        uint8_t *buf = buffer;  // NEEDED???

        struct file_handle *fh = thread_get_fh(&t->files, fd);

        if (fh == NULL) {
            exit(-1);
        }

        lock_acquire(&filesys_lock);
        off_t wrote = file_write(fh->file, buf, size);
        lock_release(&filesys_lock);

        return wrote;
    }
}
开发者ID:ozensoydc,项目名称:OS-p3,代码行数:25,代码来源:syscall.c


示例19: sys_write

static int sys_write(int fd, const void *buffer,unsigned size)
{
  struct thread *curr = thread_current();
  struct opened_file_elem *opened_elem ;
  struct list_elem *e;
  int check_valid=0;
  if(fd<=0)
    return -1;
  else if(fd==1)
  {
    if(size>512)
      return -1;
    else
    {
      putbuf(buffer,size);
      return size;
    }
  }
  else
  {
    for( e = list_begin(&curr->openfile_list) ; e != list_end(&curr->openfile_list) ;
        e = list_next(e) )
    {
      opened_elem=list_entry(e,struct opened_file_elem,elem_f);
      if(opened_elem->fd==fd)
      {
        check_valid=1;
        return file_write(opened_elem->opened_file,buffer,size);
      }
    }
  }
  if(check_valid==0)
    return -1;
}
开发者ID:goodahn,项目名称:cs330_OperatingSystem,代码行数:34,代码来源:syscall.c


示例20: fwormream

void
fwormream(Device *d)
{
	Iobuf *p;
	Device *fdev;
	Off a, b;

	if(chatty)
		print("fworm ream\n");
	devinit(d);
	fdev = FDEV(d);
	a = fwormsize(d);
	b = devsize(fdev);
	if(chatty){
		print("\tfwsize = %lld\n", (Wideoff)a);
		print("\tbwsize = %lld\n", (Wideoff)b-a);
	}
	for(; a < b; a++) {
		p = getbuf(fdev, a, Bmod|Bres);
		if(!p)
			panic("fworm: init");
		memset(p->iobuf, 0, RBUFSIZE);
		settag(p, Tvirgo, a);
		putbuf(p);
	}
}
开发者ID:Nurb432,项目名称:plan9front,代码行数:26,代码来源:fworm.c



注:本文中的putbuf函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ putc函数代码示例发布时间:2022-05-30
下一篇:
C++ putback函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap