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


C++ write_all函数代码示例

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


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

示例1: input_callback

static gboolean
input_callback (GIOChannel   *source,
		GIOCondition  condition,
		gpointer      data)
{
  int val;
  GIOChannel *dest = (GIOChannel *)data;
  
  if (!read_all (source, (char *)&val, sizeof(val)))
    {
      fprintf (stderr, "Unexpected EOF\n");
      exit (1);
    }

  if (val)
    {
      write_all (dest, (char *)&val, sizeof(val));
      
      return TRUE;
    }
  else
    {
      g_io_channel_close (source);
      g_io_channel_close (dest);
      
      g_io_channel_unref (source);
      g_io_channel_unref (dest);

      n_active_children--;
      if (n_active_children == 0)
	g_main_loop_quit (loop);
      
      return FALSE;
    }
}
开发者ID:north0808,项目名称:haina,代码行数:35,代码来源:timeloop-closure.c

示例2: do_read

static int
do_read(void)
{
    int ret = -1;
    char name[MAX_FILE_NAME_LENGTH + 1];
    char *contents, *path;
    struct file *file;

    if (read_all(STDIN, name, MAX_FILE_NAME_LENGTH) != MAX_FILE_NAME_LENGTH)
        return -1;
    name[MAX_FILE_NAME_LENGTH] = '\0';

    if ((path = get_path_from_dir(&vfs, pwd)) == NULL)
        return -1;

    if ((path = append_to_path(path, name)) == NULL)
        goto free_path;

    if ((file = lookup_file(&vfs, path, 1)) == NULL)
        goto free_path;

    if (read_file(&vfs, USER_UID, path, (unsigned char **)&contents) != 0)
        goto free_path;

    write_all(STDOUT, contents, file->size);
    ret = 0;

free_path:
    free(path);
    return ret;
}
开发者ID:trailofbits,项目名称:cb-multios,代码行数:31,代码来源:service.c

示例3: grab_file

/* Be careful about trying to compile over running programs (parallel make).
 * temp_file helps here. */
char *compile_info(const void *ctx, const char *dir)
{
	char *info_c_file, *info, *compiled, *output;
	int fd;

	/* Copy it to a file with proper .c suffix. */
	info = grab_file(ctx, tal_fmt(ctx, "%s/_info", dir));
	if (!info)
		return NULL;

	info_c_file = temp_file(ctx, ".c", "_info");
	fd = open(info_c_file, O_WRONLY|O_CREAT|O_EXCL, 0600);
	if (fd < 0)
		return NULL;
	if (!write_all(fd, info, tal_count(info)-1))
		return NULL;

	if (close(fd) != 0)
		return NULL;

	compiled = temp_file(ctx, "", "info");
	if (compile_and_link(ctx, info_c_file, find_ccan_dir(dir), "",
			     compiler, cflags, "", compiled, &output))
		return compiled;
	return NULL;
}
开发者ID:dooglus,项目名称:ccan,代码行数:28,代码来源:depends.c

示例4: sun_write_disklabel

static int sun_write_disklabel(struct fdisk_context *cxt)
{
	struct sun_disklabel *sunlabel;
	unsigned short *ush;
	unsigned short csum = 0;
	const size_t sz = sizeof(struct sun_disklabel);

	assert(cxt);
	assert(cxt->label);
	assert(fdisk_is_disklabel(cxt, SUN));

	sunlabel = self_disklabel(cxt);

	/* Maybe geometry has been modified */
	sunlabel->nhead = cpu_to_be16(cxt->geom.heads);
	sunlabel->nsect = cpu_to_be16(cxt->geom.sectors);

	if (cxt->geom.cylinders != be16_to_cpu(sunlabel->ncyl))
		sunlabel->ncyl = cpu_to_be16( cxt->geom.cylinders
				      - be16_to_cpu(sunlabel->acyl) );

	ush = (unsigned short *) sunlabel;

	while(ush < (unsigned short *)(&sunlabel->csum))
		csum ^= *ush++;
	sunlabel->csum = csum;
	if (lseek(cxt->dev_fd, 0, SEEK_SET) < 0)
		return -errno;
	if (write_all(cxt->dev_fd, sunlabel, sz) != 0)
		return -errno;

	return 0;
}
开发者ID:Kynde,项目名称:util-linux,代码行数:33,代码来源:sun.c

示例5: write_block

static void write_block(const struct fs_control *ctl, int blk, char * buffer) {
	if (blk * MINIX_BLOCK_SIZE != lseek(ctl->device_fd, blk * MINIX_BLOCK_SIZE, SEEK_SET))
		errx(MKFS_EX_ERROR, _("%s: seek failed in write_block"), ctl->device_name);

	if (write_all(ctl->device_fd, buffer, MINIX_BLOCK_SIZE))
		errx(MKFS_EX_ERROR, _("%s: write failed in write_block"), ctl->device_name);
}
开发者ID:Kaligule,项目名称:util-linux,代码行数:7,代码来源:mkfs.minix.c

示例6: write_line

static int write_line(const char *line)
{
	if (write_all(sock, line, strlen(line)) == -1)
		die_errno("write");

	return read_answer();
}
开发者ID:kcrossan,项目名称:libcmus,代码行数:7,代码来源:main.c

示例7: copy_body

void copy_body(amqp_connection_state_t conn, int fd)
{
  size_t body_remaining;
  amqp_frame_t frame;

  int res = amqp_simple_wait_frame(conn, &frame);
  die_amqp_error(res, "waiting for header frame");
  if (frame.frame_type != AMQP_FRAME_HEADER) {
    die("expected header, got frame type 0x%X",
        frame.frame_type);
  }

  body_remaining = frame.payload.properties.body_size;
  while (body_remaining) {
    res = amqp_simple_wait_frame(conn, &frame);
    die_amqp_error(res, "waiting for body frame");
    if (frame.frame_type != AMQP_FRAME_BODY) {
      die("expected body, got frame type 0x%X",
          frame.frame_type);
    }

    write_all(fd, frame.payload.body_fragment);
    body_remaining -= frame.payload.body_fragment.len;
  }
}
开发者ID:TimSimpsonR,项目名称:rabbitmq-c,代码行数:25,代码来源:common.c

示例8: accel_map_print

static void
accel_map_print (gpointer        data,
		 const gchar    *accel_path,
		 guint           accel_key,
		 GdkModifierType accel_mods,
		 gboolean        changed)
{
  GString *gstring = g_string_new (changed ? NULL : "; ");
  gint fd = GPOINTER_TO_INT (data);
  gchar *tmp, *name;

  g_string_append (gstring, "(gtk_accel_path \"");

  tmp = g_strescape (accel_path, NULL);
  g_string_append (gstring, tmp);
  g_free (tmp);

  g_string_append (gstring, "\" \"");

  name = gtk_accelerator_name (accel_key, accel_mods);
  tmp = g_strescape (name, NULL);
  g_free (name);
  g_string_append (gstring, tmp);
  g_free (tmp);

  g_string_append (gstring, "\")\n");

  write_all (fd, gstring->str, gstring->len);

  g_string_free (gstring, TRUE);
}
开发者ID:3dfxmadscientist,项目名称:gtk,代码行数:31,代码来源:gtkaccelmap.c

示例9: log_lastlog

static void log_lastlog(struct login_context *cxt)
{
	struct sigaction sa, oldsa_xfsz;
	struct lastlog ll;
	time_t t;
	int fd;

	if (!cxt->pwd)
		return;

	/* lastlog is huge on systems with large UIDs, ignore SIGXFSZ */
	memset(&sa, 0, sizeof(sa));
	sa.sa_handler = SIG_IGN;
	sigaction(SIGXFSZ, &sa, &oldsa_xfsz);

	fd = open(_PATH_LASTLOG, O_RDWR, 0);
	if (fd < 0)
		goto done;

	if (lseek(fd, (off_t) cxt->pwd->pw_uid * sizeof(ll), SEEK_SET) == -1)
		goto done;

	/*
	 * Print last log message.
	 */
	if (!cxt->quiet) {
		if (read(fd, (char *)&ll, sizeof(ll)) == sizeof(ll) &&
							ll.ll_time != 0) {
			time_t ll_time = (time_t) ll.ll_time;

			printf(_("Last login: %.*s "), 24 - 5, ctime(&ll_time));
			if (*ll.ll_host != '\0')
				printf(_("from %.*s\n"),
				       (int)sizeof(ll.ll_host), ll.ll_host);
			else
				printf(_("on %.*s\n"),
				       (int)sizeof(ll.ll_line), ll.ll_line);
		}
		if (lseek(fd, (off_t) cxt->pwd->pw_uid * sizeof(ll), SEEK_SET) == -1)
			goto done;
	}

	memset((char *)&ll, 0, sizeof(ll));

	time(&t);
	ll.ll_time = t;		/* ll_time is always 32bit */

	if (cxt->tty_name)
		xstrncpy(ll.ll_line, cxt->tty_name, sizeof(ll.ll_line));
	if (cxt->hostname)
		xstrncpy(ll.ll_host, cxt->hostname, sizeof(ll.ll_host));

	if (write_all(fd, (char *)&ll, sizeof(ll)))
		warn(_("write lastlog failed"));
done:
	if (fd >= 0)
		close(fd);

	sigaction(SIGXFSZ, &oldsa_xfsz, NULL);		/* restore original setting */
}
开发者ID:sebras,项目名称:util-linux,代码行数:60,代码来源:login.c

示例10: handle_connection

void handle_connection(void *pointer)
{
    connection_info info = *(connection_info *) pointer;
    free(pointer);
    //printf("New Connection\n");
    if(info.counter%100==0){
        char buff[256];
        sprintf(buff, "unikitty/net_%d.part", info.counter);
        // save_network(info.net, buff);
    }
    int fd = info.fd;
    network net = info.net;
    int i;
    for(i = 0; i < net.n; ++i){
        if(net.layers[i].type == CONVOLUTIONAL){
            convolutional_layer layer = net.layers[i];

            read_and_add_into(fd, layer.bias_updates, layer.n);
            int num = layer.n*layer.c*layer.size*layer.size;
            read_and_add_into(fd, layer.filter_updates, num);
        }
        if(net.layers[i].type == CONNECTED){
            connected_layer layer = net.layers[i];

            read_and_add_into(fd, layer.bias_updates, layer.outputs);
            read_and_add_into(fd, layer.weight_updates, layer.inputs*layer.outputs);
        }
    }
    for(i = 0; i < net.n; ++i){
        if(net.layers[i].type == CONVOLUTIONAL){
            convolutional_layer layer = net.layers[i];
            // update_convolutional_layer(layer);

            write_all(fd, (char*) layer.biases, layer.n*sizeof(float));
            int num = layer.n*layer.c*layer.size*layer.size;
            write_all(fd, (char*) layer.filters, num*sizeof(float));
        }
        if(net.layers[i].type == CONNECTED){
            connected_layer layer = net.layers[i];
            // update_connected_layer(layer);
            write_all(fd, (char *)layer.biases, layer.outputs*sizeof(float));
            write_all(fd, (char *)layer.weights, layer.outputs*layer.inputs*sizeof(float));
        }
    }
    //printf("Received updates\n");
    close(fd);
}
开发者ID:WildbookOrg,项目名称:pydarknet,代码行数:47,代码来源:server.c

示例11: resizetty

static int resizetty(void)
{
	/* 
	 * \e7        Save current state (cursor coordinates, attributes,
	 *                character sets pointed at by G0, G1).
	 * \e[r       Set scrolling region; parameters are top and bottom row.
	 * \e[32766E  Move cursor down 32766 (INT16_MAX - 1) rows.
	 * \e[32766C  Move cursor right 32766 columns.
	 * \e[6n      Report cursor position.
	 * \e8        Restore state most recently saved by \e7.
	 */
	static const char *getpos = "\e7\e[r\e[32766E\e[32766C\e[6n\e8";
	char retstr[32];
	int row, col;
	size_t pos;
	ssize_t rc;
	struct winsize ws;
	struct termios saved_attributes;
	int saved_fl;

	if (!isatty(STDIN_FILENO))
		errx(EXIT_FAILURE, _("stdin does not refer to a terminal"));

	tty_raw(&saved_attributes, &saved_fl);
	if (write_all(STDIN_FILENO, getpos, strlen(getpos)) < 0) {
		warn(_("write failed"));
		tty_restore(&saved_attributes, &saved_fl);
		return 1;
	}
	for (pos = 0; pos < sizeof(retstr) - 1;) {
		if (0 == select_wait())
			break;
		if ((rc =
		     read(STDIN_FILENO, retstr + pos,
			  sizeof(retstr) - 1 - pos)) < 0) {
			if (errno == EINTR)
				continue;
			warn(_("read failed"));
			tty_restore(&saved_attributes, &saved_fl);
			return 1;
		}
		pos += rc;
		if (retstr[pos - 1] == 'R')
			break;
	}
	retstr[pos] = 0;
	tty_restore(&saved_attributes, &saved_fl);
	rc = sscanf(retstr, "\033[%d;%dR", &row, &col);
	if (rc != 2) {
		warnx(_("invalid cursor position: %s"), retstr);
		return 1;
	}
	memset(&ws, 0, sizeof(struct winsize));
	ioctl(STDIN_FILENO, TIOCGWINSZ, &ws);
	ws.ws_row = row;
	ws.ws_col = col;
	ioctl(STDIN_FILENO, TIOCSWINSZ, &ws);
	return 0;
}
开发者ID:Webster-WXH,项目名称:util-linux,代码行数:59,代码来源:setterm.c

示例12: bash_completion_main

int
bash_completion_main(const struct cmd_bash_completion_info* info)
{
    const char* fb_adb_binary = orig_argv0;
#ifdef HAVE_REALPATH
    // If argv0 isn't a relative or absolute path, assume we got it
    // from PATH and don't touch it.
    if (strchr(fb_adb_binary, '/'))
        fb_adb_binary = xrealpath(fb_adb_binary);
#endif
    char* argv0_line = xaprintf(
        ": ${_fb_adb:=%s}\n",
        xshellquote(fb_adb_binary));
    write_all(STDOUT_FILENO, argv0_line, strlen(argv0_line));
    write_all(STDOUT_FILENO, bash_completion, sizeof (bash_completion));
    return 0;
}
开发者ID:Learn-Android-app,项目名称:fb-adb,代码行数:17,代码来源:cmd_bash_completion.c

示例13: send_xfer_msg

static void
send_xfer_msg(int to_peer, const struct xfer_msg* m)
{
    dbg("sending xfer message type=%u size=%u",
        (unsigned) m->type,
        (unsigned) xfer_msg_size(m->type));
    write_all(to_peer, m, xfer_msg_size(m->type));
}
开发者ID:liyongming1982,项目名称:fb-adb,代码行数:8,代码来源:xfer.c

示例14: request

void SvgSubprocessCharacterGenerator::request( ) {
    const char *dummy = "";

    if (write_all(send_fd, dummy, 1) != 1) {
        throw std::runtime_error("dead subprocess?");
    }
    fsync(send_fd);
}
开发者ID:pymlofy,项目名称:exagl,代码行数:8,代码来源:svg_subprocess_character_generator.cpp

示例15: tlv_fwrite

int tlv_fwrite(tlv_t *tlv, int fd) {
        unsigned int to_write = TLV_SIZEOF(tlv);
        int status = write_all(fd, *tlv, to_write);
        if (status == -1 || (unsigned int)status != to_write) {
                ERROR("write", -1);
        }
        return 0;
}
开发者ID:bfontaine,项目名称:Dazibao,代码行数:8,代码来源:tlv.c


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