当前位置: 首页>>代码示例>>C++>>正文


C++ xread函数代码示例

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


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

示例1: screen_read_close

static void screen_read_close(void)
{
	unsigned i, j;
	int vcsa_fd;
	char *data;

	// Close & re-open vcsa in case they have swapped virtual consoles
	vcsa_fd = xopen(G.vcsa_name, O_RDONLY);
	xread(vcsa_fd, &G.remote, 4);
	i = G.remote.cols * 2;
	G.first_line_offset = G.y * i;
	i *= G.remote.lines;
	if (G.data == NULL) {
		G.size = i;
		G.data = xzalloc(2 * i);
	}
	else if (G.size != i) {
		cleanup(1);
	}
	data = G.data + G.current;
	xread(vcsa_fd, data, G.size);
	close(vcsa_fd);
	for (i = 0; i < G.remote.lines; i++) {
		for (j = 0; j < G.remote.cols; j++, NEXT(data)) {
			unsigned x = j - G.x; // if will catch j < G.x too
			unsigned y = i - G.y; // if will catch i < G.y too

			if (CHAR(data) < ' ')
				CHAR(data) = ' ';
			if (y >= G.height || x >= G.width)
				DATA(data) = 0;
		}
	}
}
开发者ID:Ayyayay,项目名称:busybox,代码行数:34,代码来源:conspy.c

示例2: siemens_meas_setup

static bool siemens_meas_setup(int fd, struct hdr_s* hdr)
{
	off_t start = 0;

	xseek(fd, start);
	xread(fd, hdr, sizeof(struct hdr_s));

	// check for VD version
	bool vd = ((hdr->offset < 10000) && (hdr->nscans < 64));

	if (vd) {
	
		debug_printf(DP_INFO, "VD Header. MeasID: %d FileID: %d Scans: %d\n",
					hdr->measid, hdr->fileid, hdr->nscans);

		start += hdr->datoff;

		xseek(fd, start);

		// reread offset
		xread(fd, &hdr->offset, sizeof(hdr->offset));

	} else {

		debug_printf(DP_INFO, "VB Header.\n");
		hdr->nscans = 1;
	}

	start += hdr->offset;

	xseek(fd, start);

        return vd;
}
开发者ID:jaeseung16,项目名称:bart,代码行数:34,代码来源:twixread.c

示例3: unpackExtent

static void
unpackExtent(
    Extent *const xi,  // input
    Extent *const xo,  // output
    f_expand *const f_decompress,
    f_unfilter *f_unf
)
{
    while (xo->size) {
        struct b_info h;
        //   Note: if h.sz_unc == h.sz_cpr then the block was not
        //   compressible and is stored in its uncompressed form.

        // Read and check block sizes.
        xread(xi, (char *)&h, sizeof(h));
        if (h.sz_unc == 0) {                     // uncompressed size 0 -> EOF
            if (h.sz_cpr != UPX_MAGIC_LE32)      // h.sz_cpr must be h->magic
                err_exit(2);
            if (xi->size != 0)                 // all bytes must be written
                err_exit(3);
            break;
        }
        if (h.sz_cpr <= 0) {
            err_exit(4);
ERR_LAB
        }
        if (h.sz_cpr > h.sz_unc
        ||  h.sz_unc > xo->size ) {
            err_exit(5);
        }
        // Now we have:
        //   assert(h.sz_cpr <= h.sz_unc);
        //   assert(h.sz_unc > 0 && h.sz_unc <= blocksize);
        //   assert(h.sz_cpr > 0 && h.sz_cpr <= blocksize);

        if (h.sz_cpr < h.sz_unc) { // Decompress block
            nrv_uint out_len = h.sz_unc;  // EOF for lzma
            int const j = (*f_decompress)((unsigned char *)xi->buf, h.sz_cpr,
                (unsigned char *)xo->buf, &out_len, *(int *)(void *)&h.b_method );
            if (j != 0 || out_len != (nrv_uint)h.sz_unc)
                err_exit(7);
            // Skip Ehdr+Phdrs: separate 1st block, not filtered
            if (h.b_ftid!=0 && f_unf  // have filter
            &&  ((512 < out_len)  // this block is longer than Ehdr+Phdrs
              || (xo->size==(unsigned)h.sz_unc) )  // block is last in Extent
            ) {
                (*f_unf)((unsigned char *)xo->buf, out_len, h.b_cto8, h.b_ftid);
            }
            xi->buf  += h.sz_cpr;
            xi->size -= h.sz_cpr;
        }
        else { // copy literal block
            xread(xi, xo->buf, h.sz_cpr);
        }
        xo->buf  += h.sz_unc;
        xo->size -= h.sz_unc;
    }
开发者ID:tfauck,项目名称:upx,代码行数:57,代码来源:amd64-linux.elf-main.c

示例4: do_epoch_log_read

static int do_epoch_log_read(uint32_t epoch, struct sd_node *nodes, int len,
			     time_t *timestamp)
{
	int fd, ret, nr_nodes;
	char path[PATH_MAX];
	struct stat epoch_stat;

	snprintf(path, sizeof(path), "%s%08u", epoch_path, epoch);
	fd = open(path, O_RDONLY);
	if (fd < 0) {
		sd_eprintf("failed to open epoch %"PRIu32" log, %m", epoch);
		goto err;
	}

	memset(&epoch_stat, 0, sizeof(epoch_stat));
	ret = fstat(fd, &epoch_stat);
	if (ret < 0) {
		sd_eprintf("failed to stat epoch %"PRIu32" log, %m", epoch);
		goto err;
	}

	if (len < epoch_stat.st_size - sizeof(*timestamp)) {
		sd_eprintf("invalid epoch %"PRIu32" log", epoch);
		goto err;
	}

	ret = xread(fd, nodes, epoch_stat.st_size - sizeof(*timestamp));
	if (ret < 0) {
		sd_eprintf("failed to read epoch %"PRIu32" log, %m", epoch);
		goto err;
	}

	/* Broken epoch, just ignore */
	if (ret % sizeof(struct sd_node) != 0) {
		sd_eprintf("invalid epoch %"PRIu32" log", epoch);
		goto err;
	}

	nr_nodes = ret / sizeof(struct sd_node);

	if (timestamp) {
		ret = xread(fd, timestamp, sizeof(*timestamp));
		if (ret != sizeof(*timestamp)) {
			sd_eprintf("invalid epoch %"PRIu32" log", epoch);
			goto err;
		}
	}

	close(fd);
	return nr_nodes;
err:
	if (fd >= 0)
		close(fd);
	return -1;
}
开发者ID:zplambert,项目名称:sheepdog,代码行数:55,代码来源:store.c

示例5: decode

void decode(int fd, dataset_t* bek_data, external_info_header_t* header, key_header_t* key_header)
{
	memset (bek_data, 0, sizeof(dataset_t));
	memset (header, 0, sizeof(external_info_header_t));
	memset (key_header, 0, sizeof(key_header_t));
	
	
	xread (fd, bek_data, sizeof(dataset_t));
	
	xread (fd, header, sizeof(external_info_header_t));
	
	xread (fd, key_header, sizeof(key_header_t));
}
开发者ID:aoighost,项目名称:dislocker,代码行数:13,代码来源:read_bekfile.c

示例6: unpackExtent

static void
unpackExtent(
    struct Extent *const xi,  // input
    struct Extent *const xo,  // output
    f_expand *const f_decompress
)
{
    while (xo->size) {
        struct b_info h;
        //   Note: if h.sz_unc == h.sz_cpr then the block was not
        //   compressible and is stored in its uncompressed form.

        // Read and check block sizes.
        xread(xi, (char *)&h, sizeof(h));
        if (h.sz_unc == 0) {                     // uncompressed size 0 -> EOF
            if (h.sz_cpr != UPX_MAGIC_LE32)      // h.sz_cpr must be h->magic
                err_exit(2);
            if (xi->size != 0)                 // all bytes must be written
                err_exit(3);
            break;
        }
        if (h.sz_cpr <= 0) {
            err_exit(4);
ERR_LAB
        }
        if (h.sz_cpr > h.sz_unc
        ||  h.sz_unc > xo->size ) {
            err_exit(5);
        }
        // Now we have:
        //   assert(h.sz_cpr <= h.sz_unc);
        //   assert(h.sz_unc > 0 && h.sz_unc <= blocksize);
        //   assert(h.sz_cpr > 0 && h.sz_cpr <= blocksize);

        if (h.sz_cpr < h.sz_unc) { // Decompress block
            nrv_uint out_len = h.sz_unc;  // EOF for lzma
            int const j = (*f_decompress)((unsigned char *)xi->buf, h.sz_cpr,
                (unsigned char *)xo->buf, &out_len, *(int *)(void *)&h.b_method );
            if (j != 0 || out_len != (nrv_uint)h.sz_unc)
                err_exit(7);
            xi->buf  += h.sz_cpr;
            xi->size -= h.sz_cpr;
        }
        else { // copy literal block
            xread(xi, xo->buf, h.sz_cpr);
        }
        xo->buf  += h.sz_unc;
        xo->size -= h.sz_unc;
    }
开发者ID:tfauck,项目名称:upx,代码行数:49,代码来源:i386-linux.elf.shell-main.c

示例7: get_char

/* wait for a character on the serial port */
unsigned char get_char(void)
{
	unsigned char c;
	assert(portfd >= 0);
	xread(portfd, &c, 1);
	return c;
}
开发者ID:korneliuszo,项目名称:shoehorn,代码行数:8,代码来源:serial.c

示例8: getclust

static Ioclust*
getclust(Xdata *dev, long addr, ulong tag)
{
	Ioclust *c, *f;

	f = nil;
	for(c=iohead; c; c=c->next){
		if(!c->busy && c->tag == tag)
			f = c;
		if(c->addr == addr && c->dev == dev){
			c->busy++;
			return c;
		}
	}

	if(f == nil)
		panic(0, "out of buffers");

	f->addr = addr;
	f->dev = dev;
	f->busy++;
	if(waserror()){
		f->addr = -1;	/* stop caching */
		putclust(f);
		nexterror();
	}
	xread(f);
	poperror();
	return f;
}
开发者ID:srk-cmu,项目名称:9problems,代码行数:30,代码来源:iobuf.c

示例9: xmalloc

char *xreadstr(int fd)
{
    int size = 0;
    int len = 0;
    char *str = NULL;
    int n;

    do {
        if (size - len - 1 <= 0) {
            str = (size == 0) ? xmalloc(CHUNKSIZE)
                              : xrealloc(str, size + CHUNKSIZE);
            size += CHUNKSIZE;
        }
        //n = xread(fd, str + len, size - len - 1);
        n = xread(fd, str + len, 1);
        if (n < 0)
            err_exit (TRUE, "read");
        if (n == 0)
            err_exit (FALSE, "EOF on read");
        len += n;
        str[len] = '\0';
    } while (len < 2 || strcmp(&str[len - 2], "\r\n") != 0);

    str[len - 2] = '\0';
    return str;
}
开发者ID:chaos,项目名称:powerman,代码行数:26,代码来源:xread.c

示例10: get_header_tar_gz

char get_header_tar_gz(archive_handle_t *archive_handle)
{
#if BB_MMU
	unsigned char magic[2];
#endif

	/* Can't lseek over pipes */
	archive_handle->seek = seek_by_read;

	/* Check gzip magic only if open_transformer will invoke unpack_gz_stream (MMU case).
	 * Otherwise, it will invoke an external helper "gunzip -cf" (NOMMU case) which will
	 * need the header. */
#if BB_MMU
	xread(archive_handle->src_fd, &magic, 2);
	if ((magic[0] != 0x1f) || (magic[1] != 0x8b)) {
		bb_error_msg_and_die("invalid gzip magic");
	}
#endif

	archive_handle->src_fd = open_transformer(archive_handle->src_fd, unpack_gz_stream, "gunzip");
	archive_handle->offset = 0;
	while (get_header_tar(archive_handle) == EXIT_SUCCESS)
		continue;

	/* Can only do one file at a time */
	return EXIT_FAILURE;
}
开发者ID:NikhilNJ,项目名称:screenplay-dx,代码行数:27,代码来源:get_header_tar_gz.c

示例11: strbuf_read

ssize_t strbuf_read(struct strbuf *sb, int fd, size_t hint)
{
	size_t oldlen = sb->len;
	size_t oldalloc = sb->alloc;

	strbuf_grow(sb, hint ? hint : 8192);
	for (;;) {
		ssize_t cnt;

		cnt = xread(fd, sb->buf + sb->len, sb->alloc - sb->len - 1);
		if (cnt < 0) {
			if (oldalloc == 0)
				strbuf_release(sb);
			else
				strbuf_setlen(sb, oldlen);
			return -1;
		}
		if (!cnt)
			break;
		sb->len += cnt;
		strbuf_grow(sb, 8192);
	}

	sb->buf[sb->len] = '\0';
	return sb->len - oldlen;
}
开发者ID:AmyOrchid188,项目名称:git,代码行数:26,代码来源:strbuf.c

示例12: send_local_file

static void send_local_file(const char *the_type, const char *name)
{
	const char *p = git_path("%s", name);
	size_t buf_alloc = 8192;
	char *buf = xmalloc(buf_alloc);
	int fd;
	struct stat sb;

	fd = open(p, O_RDONLY);
	if (fd < 0)
		not_found("Cannot open '%s': %s", p, strerror(errno));
	if (fstat(fd, &sb) < 0)
		die_errno("Cannot stat '%s'", p);

	hdr_int(content_length, sb.st_size);
	hdr_str(content_type, the_type);
	hdr_date(last_modified, sb.st_mtime);
	end_headers();

	for (;;) {
		ssize_t n = xread(fd, buf, buf_alloc);
		if (n < 0)
			die_errno("Cannot read '%s'", p);
		if (!n)
			break;
		write_or_die(1, buf, n);
	}
	close(fd);
	free(buf);
}
开发者ID:120011676,项目名称:git,代码行数:30,代码来源:http-backend.c

示例13: init_config_file

int init_config_file(void)
{
	int fd, ret;

	check_tmp_config();

	fd = open(config_path, O_RDONLY);
	if (fd < 0) {
		if (errno != ENOENT) {
			sd_eprintf("failed to read config file, %m");
			return -1;
		}
		goto create;
	}

	ret = xread(fd, &config, sizeof(config));
	if (ret == 0) {
		close(fd);
		goto create;
	}
	if (ret < 0) {
		sd_eprintf("failed to read config file, %m");
		goto out;
	}

	if (config.version != SD_FORMAT_VERSION) {
		sd_eprintf("This sheep version is not compatible with"
			   " the existing data layout, %d", config.version);
		if (sys->upgrade) {
			/* upgrade sheep store */
			ret = sd_migrate_store(config.version, SD_FORMAT_VERSION);
			if (ret == 0) {
				/* reload config file */
				ret = xpread(fd, &config, sizeof(config), 0);
				if (ret != sizeof(config)) {
					sd_eprintf("failed to reload config"
						   " file, %m");
					ret = -1;
				} else
					ret = 0;
			}
			goto out;
		}

		sd_eprintf("use '-u' option to upgrade sheep store");
		ret = -1;
		goto out;
	}
	ret = 0;
out:
	close(fd);

	return ret;
create:
	config.version = SD_FORMAT_VERSION;
	if (write_config() != SD_RES_SUCCESS)
		return -1;

	return 0;
}
开发者ID:rdndnl,项目名称:sheepdog,代码行数:60,代码来源:config.c

示例14: qmp_read

/*
 * read over a non-block fd
 */
static int 
qmp_read(int fd, void *buf, size_t *len)
{
        struct pollfd pfd;
        size_t tread = 0, nread;
        int r;

        pfd.fd = fd;
        pfd.events = POLLIN;

        while ((r = poll(&pfd, 1, QMP_POLL_TIMEOUT)) != 0) {

                if (r == -1)
                        return -1;

                if (pfd.revents & POLLIN) {
                        /* read at max 1k at a time */
                        nread = xread(fd, buf, 1024);
                        tread += nread;
                        buf += nread;
                }
        }

        *len = tread;
        return 0;
}
开发者ID:mv0,项目名称:qemu-qmp,代码行数:29,代码来源:qmp.c

示例15: get_header_tar_gz

char FAST_FUNC get_header_tar_gz(archive_handle_t *archive_handle)
{
#if BB_MMU
    uint16_t magic;
#endif

    /* Can't lseek over pipes */
    archive_handle->seek = seek_by_read;

    /* Check gzip magic only if open_transformer will invoke unpack_gz_stream (MMU case).
     * Otherwise, it will invoke an external helper "gunzip -cf" (NOMMU case) which will
     * need the header. */
#if BB_MMU
    xread(archive_handle->src_fd, &magic, 2);
    /* Can skip this check, but error message will be less clear */
    if (magic != GZIP_MAGIC) {
        bb_error_msg_and_die("invalid gzip magic");
    }
#endif

    open_transformer(archive_handle->src_fd, unpack_gz_stream, "gunzip");
    archive_handle->offset = 0;
    while (get_header_tar(archive_handle) == EXIT_SUCCESS)
        continue;

    /* Can only do one file at a time */
    return EXIT_FAILURE;
}
开发者ID:xieshaohua,项目名称:rootfs,代码行数:28,代码来源:get_header_tar_gz.c


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