예제 #1
0
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;
    }
}
예제 #2
0
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;
}
예제 #3
0
파일: depends.c 프로젝트: dooglus/ccan
/* 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;
}
예제 #4
0
파일: sun.c 프로젝트: Kynde/util-linux
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;
}
예제 #5
0
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);
}
예제 #6
0
파일: main.c 프로젝트: kcrossan/libcmus
static int write_line(const char *line)
{
	if (write_all(sock, line, strlen(line)) == -1)
		die_errno("write");

	return read_answer();
}
예제 #7
0
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;
  }
}
예제 #8
0
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);
}
예제 #9
0
파일: login.c 프로젝트: sebras/util-linux
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 */
}
예제 #10
0
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);
}
예제 #11
0
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;
}
예제 #12
0
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;
}
예제 #13
0
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));
}
void SvgSubprocessCharacterGenerator::request( ) {
    const char *dummy = "";

    if (write_all(send_fd, dummy, 1) != 1) {
        throw std::runtime_error("dead subprocess?");
    }
    fsync(send_fd);
}
예제 #15
0
파일: tlv.c 프로젝트: bfontaine/Dazibao
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;
}
static gpointer
run_client_thread (gpointer data)
{
	gint *socket = data;
	GkdSshAgentCall call;
	EggBuffer req;
	EggBuffer resp;
	guchar op;

	g_assert (GP11_IS_MODULE (pkcs11_module));

	memset (&call, 0, sizeof (call));
	call.sock = g_atomic_int_get (socket);
	g_assert (call.sock != -1);

	egg_buffer_init_full (&req, 128, egg_secure_realloc);
	egg_buffer_init_full (&resp, 128, (EggBufferAllocator)g_realloc);
	call.req = &req;
	call.resp = &resp;
	call.module = g_object_ref (pkcs11_module);

	for (;;) {

		egg_buffer_reset (call.req);

		/* 1. Read in the request */
		if (!read_packet_with_size (&call))
			break;

		/* 2. Now decode the operation */
		if (!egg_buffer_get_byte (call.req, 4, NULL, &op))
			break;
		if (op >= GKD_SSH_OP_MAX)
			break;
		g_assert (gkd_ssh_agent_operations[op]);

		/* 3. Execute the right operation */
		egg_buffer_reset (call.resp);
		egg_buffer_add_uint32 (call.resp, 0);
		if (!(gkd_ssh_agent_operations[op]) (&call))
			break;
		if (!egg_buffer_set_uint32 (call.resp, 0, call.resp->len - 4))
			break;

		/* 4. Write the reply back out */
		if (!write_all (call.sock, call.resp->buf, call.resp->len))
			break;
	}

	egg_buffer_uninit (&req);
	egg_buffer_uninit (&resp);
	g_object_unref (call.module);

	close (call.sock);
	g_atomic_int_set (socket, -1);

	return NULL;
}
예제 #17
0
static void
send_error_packet(int to_peer, int err, const char* msg)
{
    size_t msg_size = strlen(msg);
    if (msg_size > UINT16_MAX)
        msg_size = UINT16_MAX;
    struct xfer_msg m = {
        .type = XFER_MSG_ERROR,
        .u.error.err = err,
        .u.error.msg_size = msg_size,
    };
    send_xfer_msg(to_peer, &m);
    write_all(to_peer, msg, msg_size);
}

int
xfer_stub_main(const struct cmd_xfer_stub_info* info)
{
    struct xfer_ctx ctx = {
        .from_peer = STDIN_FILENO,
        .to_peer = STDOUT_FILENO,
        .info = info,
    };

    struct errinfo ei = {
        .want_msg = true
    };

    if (catch_error(do_xfer, &ctx, &ei)) {
        send_error_packet(ctx.to_peer, ei.err, ei.msg);
        return 1;
    }

    return 0;
}

#if FBADB_MAIN
int
xfer_handle_command(
    const struct start_peer_info* spi,
    const struct cmd_xfer_stub_info* local,
    const struct cmd_xfer_stub_info* remote)
{
    struct child* peer = start_peer(
        spi,
        make_args_cmd_xfer_stub(
            CMD_ARG_NAME | CMD_ARG_FORWARDED,
            remote));

    struct xfer_ctx ctx = {
        .from_peer = peer->fd[1]->fd,
        .to_peer = peer->fd[0]->fd,
        .info = local,
    };

    do_xfer(&ctx);
    return child_status_to_exit_code(child_wait(peer));
}
예제 #18
0
void d8x8matrix_cls(const device_info_t *device_info) {
	write_all(device_info, MAX7219_REG_DIGIT0, 0);
	write_all(device_info, MAX7219_REG_DIGIT1, 0);
	write_all(device_info, MAX7219_REG_DIGIT2, 0);
	write_all(device_info, MAX7219_REG_DIGIT3, 0);
	write_all(device_info, MAX7219_REG_DIGIT4, 0);
	write_all(device_info, MAX7219_REG_DIGIT5, 0);
	write_all(device_info, MAX7219_REG_DIGIT6, 0);
	write_all(device_info, MAX7219_REG_DIGIT7, 0);
}
예제 #19
0
파일: http.c 프로젝트: 340211173/httptunnel
static ssize_t
http_write_header (int fd, Http_header *header)
{
  ssize_t n = 0, m;

  if (header == NULL)
    return write_all (fd, "\r\n", 2);

  m = write_all (fd, (void *)header->name, strlen (header->name));
  if (m == -1)
    {
      return -1;
    }
  n += m;

  m = write_all (fd, ": ", 2);
  if (m == -1)
    {
      return -1;
    }
  n += m;

  m = write_all (fd, (void *)header->value, strlen (header->value));
  if (m == -1)
    {
      return -1;
    }
  n += m;

  m = write_all (fd, "\r\n", 2);
  if (m == -1)
    {
      return -1;
    }
  n += m;

  m = http_write_header (fd, header->next);
  if (m == -1)
    {
      return -1;
    }
  n += m;

  return n;
}
예제 #20
0
static struct io_plan *simple_write(struct io_conn *conn,
				    const void *data, size_t len,
				    struct io_plan *(*next)(struct io_conn *, void *),
				    void *arg)
{
	if (!write_all(conn->fd, data, len))
		err(1, "Writing data");
	return next(conn, arg);
}
예제 #21
0
int eof_ui_deregister(int sockfd)
{
   /* submit deregister command: cmd_2101.c */
   if(write_all(sockfd, EOF_CMD_UI_DEREGISTER, EOF_L_CMD) != EOF_L_CMD) {
      return 0;
   }

    return 1;
}
예제 #22
0
파일: server.c 프로젝트: eworm-de/abduco
static bool server_write_pty(Packet *pkt) {
	print_packet("server-write-pty:", pkt);
	size_t size = pkt->len;
	if (write_all(server.pty, pkt->u.msg, size) == size)
		return true;
	debug("FAILED\n");
	server.running = false;
	return false;
}
예제 #23
0
파일: io.c 프로젝트: elitak/mfs-utils
static void vserver_read_req(u32 sec, u32 count)
{
    struct vserver_cmd cmd;

    cmd.command = htonl(MFS_CMD_READ);
    cmd.param1 = htonl(sec);
    cmd.param2 = htonl(count);
    write_all(vserver, &cmd, sizeof(cmd));
}
예제 #24
0
파일: io.c 프로젝트: elitak/mfs-utils
static void vserver_list_sectors_req(u32 sec, u32 count)
{
    struct vserver_cmd cmd;

    cmd.command = htonl(MFS_CMD_LIST_SECTORS);
    cmd.param1 = htonl(sec);
    cmd.param2 = htonl(count);
    write_all(vserver, &cmd, sizeof(cmd));
}
예제 #25
0
파일: read_all.c 프로젝트: trws/flux-core
/* Test for bad args.
 */
void test_badargs (void)
{
    char *buf;

    errno = 0;
    ok (write_all (-1, "", 1) < 0 && errno == EINVAL,
        "write_all fd=-1 fails with EINVAL");
    errno = 0;
    ok (write_all (STDOUT_FILENO, NULL, 1) < 0 && errno == EINVAL,
        "write_all buf=NULL fails with EINVAL");

    errno = 0;
    ok (read_all (-1, (void **)&buf) < 0 && errno == EINVAL,
        "read_all fd=-1 fails with EINVAL");
    errno = 0;
    ok (read_all (STDIN_FILENO, NULL) < 0 && errno == EINVAL,
        "read_all buf=NULL fails with EINVAL");
}
예제 #26
0
파일: audio.c 프로젝트: sedwards/xmms3
static void oss_write_audio(gpointer data, int length)
{
	audio_buf_info abuf_info;
	AFormat new_format;
	int new_frequency, new_channels;
	EffectPlugin *ep;
	
	new_format = input.format.xmms;
	new_frequency = input.frequency;
	new_channels = input.channels;
	
	ep = get_current_effect_plugin();
	if(effects_enabled() && ep && ep->query_format)
	{
		ep->query_format(&new_format,&new_frequency,&new_channels);
	}
	
	if (new_format != effect.format.xmms ||
	    new_frequency != effect.frequency ||
	    new_channels != effect.channels)
	{
		output_time_offset += (output_bytes * 1000) / output.bps;
		output_bytes = 0;
		close(fd);
		fd = open(device_name,O_WRONLY);
		oss_setup_format(new_format, new_frequency, new_channels);
	}
	if (effects_enabled() && ep && ep->mod_samples)
		length = ep->mod_samples(&data, length,
					 input.format.xmms,
					 input.frequency,
					 input.channels);
	if (realtime && !ioctl(fd, SNDCTL_DSP_GETOSPACE, &abuf_info))
	{
		while (abuf_info.bytes < length)
		{
			xmms_usleep(10000);
			if (ioctl(fd, SNDCTL_DSP_GETOSPACE, &abuf_info))
				break;
		}
	}

	if (oss_convert_func != NULL)
		length = oss_convert_func(&data, length);

	if (oss_stereo_convert_func != NULL)
		length = oss_stereo_convert_func(&data, length,
						 output.format.oss);

	if (effect.frequency == output.frequency)
		output_bytes += write_all(fd, data, length);
	else
		output_bytes += oss_downsample(data, length,
					       effect.frequency,
					       output.frequency);
}
예제 #27
0
파일: sgi.c 프로젝트: TacheR/util-linux
static int sgi_write_disklabel(struct fdisk_context *cxt)
{
	struct sgi_disklabel *sgilabel;
	struct sgi_info *info = NULL;

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

	sgilabel = self_disklabel(cxt);
	sgilabel->csum = 0;
	sgilabel->csum = cpu_to_be32(sgi_pt_checksum(sgilabel));

	assert(sgi_pt_checksum(sgilabel) == 0);

	if (lseek(cxt->dev_fd, 0, SEEK_SET) < 0)
		goto err;
	if (write_all(cxt->dev_fd, sgilabel, DEFAULT_SECTOR_SIZE))
		goto err;
	if (!strncmp((char *) sgilabel->volume[0].name, "sgilabel", 8)) {
		/*
		 * keep this habit of first writing the "sgilabel".
		 * I never tested whether it works without (AN 981002).
		 */
		int infostartblock
			= be32_to_cpu(sgilabel->volume[0].block_num);

		if (lseek(cxt->dev_fd, (off_t) infostartblock *
					DEFAULT_SECTOR_SIZE, SEEK_SET) < 0)
			goto err;
		info = sgi_new_info();
		if (!info)
			goto err;
		if (write_all(cxt->dev_fd, info, sizeof(*info)))
			goto err;
	}

	sgi_free_info(info);
	return 0;
err:
	sgi_free_info(info);
	return -errno;
}
예제 #28
0
파일: libdevs.c 프로젝트: WolfieNuke/f3
static int bdev_write_block(struct device *dev, const char *buf, int length,
	uint64_t offset)
{
	struct block_device *bdev = dev_bdev(dev);
	off_t off_ret = lseek(bdev->fd, offset, SEEK_SET);
	if (off_ret < 0)
		return - errno;
	assert((uint64_t)off_ret == offset);
	return write_all(bdev->fd, buf, length);
}
예제 #29
0
void send_status_and_crc(int code, const char *last_filename) {
	struct result_header hdr;
	struct result_header_ext hdr_ext;
	int saved_errno;

	saved_errno = errno;
	hdr.error_code = code;
	hdr.crc32 = crc32_sum;
	if (!write_all(1, &hdr, sizeof(hdr)))
		perror("write status");
	if (last_filename) {
		hdr_ext.last_namelen = strlen(last_filename);
		if (!write_all(1, &hdr_ext, sizeof(hdr_ext)))
			perror("write status ext");
		if (!write_all(1, last_filename, hdr_ext.last_namelen))
			perror("write last_filename");
	}
	errno = saved_errno;
}
예제 #30
0
/*
  re-initialise, using current mem_buffer
 */
bool AP_FlashStorage::re_initialise(void)
{
    if (!flash_erase_ok()) {
        return false;
    }
    if (!erase_all()) {
        return false;        
    }
    return write_all();
}