示例#1
0
文件: ng_sscfu.c 项目: MarginC/kame
/*
 * CONTROL MESSAGES
 */
static int
text_status(node_p node, struct priv *priv, char *arg, u_int len)
{
	struct sbuf sbuf;

	sbuf_new(&sbuf, arg, len, 0);

	if (priv->upper)
		sbuf_printf(&sbuf, "upper hook: %s connected to %s:%s\n",
		    NG_HOOK_NAME(priv->upper),
		    NG_NODE_NAME(NG_HOOK_NODE(NG_HOOK_PEER(priv->upper))),
		    NG_HOOK_NAME(NG_HOOK_PEER(priv->upper)));
	else
		sbuf_printf(&sbuf, "upper hook: <not connected>\n");

	if (priv->lower)
		sbuf_printf(&sbuf, "lower hook: %s connected to %s:%s\n",
		    NG_HOOK_NAME(priv->lower),
		    NG_NODE_NAME(NG_HOOK_NODE(NG_HOOK_PEER(priv->lower))),
		    NG_HOOK_NAME(NG_HOOK_PEER(priv->lower)));
	else
		sbuf_printf(&sbuf, "lower hook: <not connected>\n");

	sbuf_printf(&sbuf, "sscf state: %s\n",
	    priv->enabled == NULL ? "<disabled>" :
	    sscfu_statename(sscfu_getstate(priv->sscf)));

	sbuf_finish(&sbuf);
	return (sbuf_len(&sbuf));
}
示例#2
0
static struct type_5_parser_context *
_ctx_alloc()
{
	struct type_5_parser_context *ctx;
	ctx = malloc(sizeof(struct type_5_parser_context));
	error_if(NULL == ctx, error, "malloc error: %s", strerror(errno));

	ctx->current_channel = _channel_order_alloc();
	error_if(NULL == ctx->current_channel, error, "malloc error: %s", strerror(errno));

	ctx->buffer = sbuf_new();
	error_if(NULL == ctx->buffer, error, "malloc error: %s", strerror(errno));

	ctx->channels = list_create();
	error_if(NULL == ctx->channels, error, "malloc error: %s", strerror(errno));

	ctx->in_valid_package = false;


	return ctx;

error:
	if (ctx) _ctx_free(ctx);
	return NULL;
}
示例#3
0
/*
 * Print a number of variable values for NcML
 */
static void
pr_any_valsx(
     const ncvar_t *vp,		/* variable */
     size_t len,		/* number of values to print */
     bool_t more,		/* true if more data for this row will
				 * follow, so add trailing comma */
     bool_t lastrow,		/* true if this is the last row for this
				 * variable, so terminate with ";" instead
				 * of "," */
     const void *vals		/* pointer to block of values */
     )
{
    long iel;
    safebuf_t *sb = sbuf_new();
    const char *valp = (const char *)vals;

    for (iel = 0; iel < len-1; iel++) {
	print_any_val(sb, vp, (void *)valp);
	valp += vp->tinfo->size; /* next value according to type */
	sbuf_cat(sb, " ");
	lput(sbuf_str(sb));
    }
    print_any_val(sb, vp, (void *)valp);
    lput(sbuf_str(sb));
    lastdelim2x (more, lastrow);
    sbuf_free(sb);
}
示例#4
0
文件: input.c 项目: ivoarch/ratpoison
/* Return the name of the keysym. caller must free returned pointer */
char *
keysym_to_string (KeySym keysym, unsigned int modifier)
{
  struct sbuf *name;
  char *tmp;

  name = sbuf_new (0);

  if (modifier & RP_SHIFT_MASK) sbuf_concat (name, "S-");
  if (modifier & RP_CONTROL_MASK) sbuf_concat (name, "C-");
  if (modifier & RP_META_MASK) sbuf_concat (name, "M-");
  if (modifier & RP_ALT_MASK) sbuf_concat (name, "A-");
  if (modifier & RP_HYPER_MASK) sbuf_concat (name, "H-");
  if (modifier & RP_SUPER_MASK) sbuf_concat (name, "s-");

  /* On solaris machines (perhaps other machines as well) this call
     can return NULL. In this case use the "NULL" string. */
  tmp = XKeysymToString (keysym);
  if (tmp == NULL)
    tmp = "NULL";

  sbuf_concat (name, tmp);

  return sbuf_free_struct (name);
}
示例#5
0
static int
sysctl_debug_ddb_scripting_scripts(SYSCTL_HANDLER_ARGS)
{
	struct sbuf sb;
	int error, i, len;
	char *buffer;

	/*
	 * Make space to include a maximum-length name, = symbol,
	 * maximum-length script, and carriage return for every script that
	 * may be defined.
	 */
	len = DB_MAXSCRIPTS * (DB_MAXSCRIPTNAME + 1 + DB_MAXSCRIPTLEN + 1);
	buffer = malloc(len, M_TEMP, M_WAITOK);
	(void)sbuf_new(&sb, buffer, len, SBUF_FIXEDLEN);
	mtx_lock(&db_script_mtx);
	for (i = 0; i < DB_MAXSCRIPTS; i++) {
		if (strlen(db_script_table[i].ds_scriptname) == 0)
			continue;
		(void)sbuf_printf(&sb, "%s=%s\n",
		    db_script_table[i].ds_scriptname,
		    db_script_table[i].ds_script);
	}
	mtx_unlock(&db_script_mtx);
	sbuf_finish(&sb);
	error = SYSCTL_OUT(req, sbuf_data(&sb), sbuf_len(&sb) + 1);
	sbuf_delete(&sb);
	free(buffer, M_TEMP);
	return (error);
}
static int
acpi_cpu_usage_sysctl(SYSCTL_HANDLER_ARGS)
{
    struct acpi_cpu_softc *sc;
    struct sbuf	 sb;
    char	 buf[128];
    int		 i;
    uintmax_t	 fract, sum, whole;

    sc = (struct acpi_cpu_softc *) arg1;
    sum = 0;
    for (i = 0; i < sc->cpu_cx_count; i++)
	sum += sc->cpu_cx_stats[i];
    sbuf_new(&sb, buf, sizeof(buf), SBUF_FIXEDLEN);
    for (i = 0; i < sc->cpu_cx_count; i++) {
	if (sum > 0) {
	    whole = (uintmax_t)sc->cpu_cx_stats[i] * 100;
	    fract = (whole % sum) * 100;
	    sbuf_printf(&sb, "%u.%02u%% ", (u_int)(whole / sum),
		(u_int)(fract / sum));
	} else
	    sbuf_printf(&sb, "0.00%% ");
    }
    sbuf_printf(&sb, "last %dus", sc->cpu_prev_sleep);
    sbuf_trim(&sb);
    sbuf_finish(&sb);
    sysctl_handle_string(oidp, sbuf_data(&sb), sbuf_len(&sb), req);
    sbuf_delete(&sb);

    return (0);
}
示例#7
0
/* construct path to node->name */
static char *
mtree_file_path(fsnode *node)
{
	fsnode *pnode;
	struct sbuf *sb;
	char *res, *rp[MAKEFS_MAX_TREE_DEPTH];
	int depth;

	depth = 0;
	rp[depth] = node->name;
	for (pnode = node->parent; pnode && depth < MAKEFS_MAX_TREE_DEPTH;
	     pnode = pnode->parent) {
		if (strcmp(pnode->name, ".") == 0)
			break;
		rp[++depth] = pnode->name;
	}
	
	sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND);
	if (sb == NULL) {
		errno = ENOMEM;
		return (NULL);
	}
	while (depth > 0) {
		sbuf_cat(sb, rp[depth--]);
		sbuf_putc(sb, '/');
	}
	sbuf_cat(sb, rp[depth]);
	sbuf_finish(sb);
	res = strdup(sbuf_data(sb));
	sbuf_delete(sb);
	if (res == NULL)
		errno = ENOMEM;
	return res;

}
示例#8
0
char *
frame_dump (rp_frame *frame, rp_screen *screen)
{
    rp_window *win;
    char *tmp;
    struct sbuf *s;

    /* rather than use win_number, use the X11 window ID. */
    win = find_window_number (frame->win_number);

    s = sbuf_new (0);
    sbuf_printf (s, "(frame :number %d :x %d :y %d :width %d :height %d :screenw %d :screenh %d :window %ld :last-access %d :dedicated %d)",
                 frame->number,
                 frame->x,
                 frame->y,
                 frame->width,
                 frame->height,
                 screen->width,
                 screen->height,
                 win ? win->w:0,
                 frame->last_access,
                 frame->dedicated);

    /* Extract the string and return it, and don't forget to free s. */
    tmp = sbuf_get (s);
    free (s);
    return tmp;
}
示例#9
0
文件: input.c 项目: xtaran/ratpoison
/* Return the name of the keysym. caller must free returned pointer */
char *
keysym_to_string (KeySym keysym, unsigned int modifier)
{
  static char *null_string = "NULL"; /* A NULL string. */
  struct sbuf *name;
  char *tmp;

  name = sbuf_new (0);

  if (modifier & RP_SHIFT_MASK) sbuf_concat (name, "S-");
  if (modifier & RP_CONTROL_MASK) sbuf_concat (name, "C-");
  if (modifier & RP_META_MASK) sbuf_concat (name, "M-");
  if (modifier & RP_ALT_MASK) sbuf_concat (name, "A-");
  if (modifier & RP_HYPER_MASK) sbuf_concat (name, "H-");
  if (modifier & RP_SUPER_MASK) sbuf_concat (name, "s-");

  /* On solaris machines (perhaps other machines as well) this call
     can return NULL. In this case use the "NULL" string. */
  tmp = XKeysymToString (keysym);
  if (tmp == NULL)
    tmp = null_string;

  sbuf_concat (name, tmp);

  /* Eat the nut and throw away the shells. */
  tmp = sbuf_get (name);
  free (name);

  return tmp;
}
示例#10
0
/* Note that we use marked_message_internal to avoid resetting the
   alarm. */
void
update_window_names (rp_screen *s, char *fmt)
{
  struct sbuf *bar_buffer;
  int mark_start = 0;
  int mark_end = 0;

  if (s->bar_is_raised != BAR_IS_WINDOW_LIST) return;

  bar_buffer = sbuf_new (0);

  if(defaults.window_list_style == STYLE_ROW)
    {
      get_window_list (fmt, NULL, bar_buffer, &mark_start, &mark_end);
      marked_message_internal (sbuf_get (bar_buffer), mark_start, mark_end);
    }
  else
    {
      get_window_list (fmt, "\n", bar_buffer, &mark_start, &mark_end);
      marked_message_internal (sbuf_get (bar_buffer), mark_start, mark_end);
    }


/*   marked_message (sbuf_get (bar_buffer), mark_start, mark_end); */
  sbuf_free (bar_buffer);
}
示例#11
0
文件: globals.c 项目: melkior/nilwm
/* Lifted the code from rxvt. */
static char *
get_primary_selection(void)
{
  long            nread;
  unsigned long   bytes_after;
  XTextProperty   ct;
  struct sbuf *s = sbuf_new(0);

  for (nread = 0, bytes_after = 1; bytes_after > 0; nread += ct.nitems) {
    if ((XGetWindowProperty(dpy, current_screen()->input_window, rp_selection, (nread / 4), 4096,
                            True, AnyPropertyType, &ct.encoding,
                            &ct.format, &ct.nitems, &bytes_after,
                            &ct.value) != Success)) {
      XFree(ct.value);
      sbuf_free(s);
      return NULL;
    }
    if (ct.value == NULL)
      continue;
    /* Accumulate the data. FIXME: ct.value may not be NULL
       terminated. */
    sbuf_nconcat (s, ct.value, ct.nitems);
    XFree(ct.value);
  }
  return sbuf_free_struct (s);
}
示例#12
0
void
ctl_data_print(union ctl_io *io)
{
	char str[128];
	char path_str[64];
	struct sbuf sb;
	int i, j, len;

	if (io->io_hdr.io_type != CTL_IO_SCSI)
		return;
	if (io->io_hdr.flags & CTL_FLAG_BUS_ADDR)
		return;
	if (io->io_hdr.flags & CTL_FLAG_EDPTR_SGLIST)	/* XXX: Implement */
		return;
	ctl_scsi_path_string(io, path_str, sizeof(path_str));
	len = min(io->scsiio.kern_data_len, 4096);
	for (i = 0; i < len; ) {
		sbuf_new(&sb, str, sizeof(str), SBUF_FIXEDLEN);
		sbuf_cat(&sb, path_str);
		sbuf_printf(&sb, " %#6x:%04x:", io->scsiio.tag_num, i);
		for (j = 0; j < 16 && i < len; i++, j++) {
			if (j == 8)
				sbuf_cat(&sb, " ");
			sbuf_printf(&sb, " %02x", io->scsiio.kern_data_ptr[i]);
		}
		sbuf_cat(&sb, "\n");
		sbuf_finish(&sb);
		printf("%s", sbuf_data(&sb));
	}
}
示例#13
0
/*
 * Create an sbuf with uio data
 */
struct sbuf *
sbuf_uionew(struct sbuf *s, struct uio *uio, int *error)
{

	KASSERT(uio != NULL,
	    ("%s called with NULL uio pointer", __func__));
	KASSERT(error != NULL,
	    ("%s called with NULL error pointer", __func__));

	s = sbuf_new(s, NULL, uio->uio_resid + 1, 0);
	if (s == NULL) {
		*error = ENOMEM;
		return (NULL);
	}
	*error = uiomove(s->s_buf, uio->uio_resid, uio);
	if (*error != 0) {
		sbuf_delete(s);
		return (NULL);
	}
	s->s_len = s->s_size - 1;
	if (SBUF_ISSECTION(s))
		s->s_sect_len = s->s_size - 1;
	*error = 0;
	return (s);
}
示例#14
0
文件: debug.c 项目: 2asoft/freebsd
static int
xendebug_attach(device_t dev)
{
	int i, error;

	mtx_init(&lock, "xen-dbg", NULL, MTX_SPIN);
	buf = sbuf_new(NULL, NULL, 1024, SBUF_FIXEDLEN);
	if (buf == NULL)
		panic("Unable to create sbuf for stack dump");
	sbuf_set_drain(buf, xendebug_drain, NULL);

	/* Bind an event channel to a VIRQ on each VCPU. */
	CPU_FOREACH(i) {
		error = xen_intr_bind_virq(dev, VIRQ_DEBUG, i, xendebug_filter,
		    NULL, NULL, INTR_TYPE_TTY,
		    DPCPU_ID_PTR(i, xendebug_handler));
		if (error != 0) {
			printf("Failed to bind VIRQ_DEBUG to vCPU %d: %d",
			    i, error);
			continue;
		}
		xen_intr_describe(DPCPU_ID_GET(i, xendebug_handler), "d%d", i);
	}

	return (0);
}
示例#15
0
void
virtio_describe(device_t dev, const char *msg,
    uint64_t features, struct virtio_feature_desc *feature_desc)
{
	struct sbuf sb;
	uint64_t val;
	char *buf;
	const char *name;
	int n;

	if ((buf = malloc(512, M_TEMP, M_NOWAIT)) == NULL) {
		device_printf(dev, "%s features: 0x%"PRIx64"\n", msg,
		    features);
		return;
	}

	sbuf_new(&sb, buf, 512, SBUF_FIXEDLEN);
	sbuf_printf(&sb, "%s features: 0x%"PRIx64, msg, features);

	for (n = 0, val = 1ULL << 63; val != 0; val >>= 1) {
		/*
		 * BAD_FEATURE is used to detect broken Linux clients
		 * and therefore is not applicable to FreeBSD.
		 */
		if (((features & val) == 0) || val == VIRTIO_F_BAD_FEATURE)
			continue;

		if (n++ == 0)
			sbuf_cat(&sb, " <");
		else
			sbuf_cat(&sb, ",");

		name = NULL;
		if (feature_desc != NULL)
			name = virtio_feature_name(val, feature_desc);
		if (name == NULL)
			name = virtio_feature_name(val,
			    virtio_common_feature_desc);

		if (name == NULL)
			sbuf_printf(&sb, "0x%"PRIx64, val);
		else
			sbuf_cat(&sb, name);
	}

	if (n > 0)
		sbuf_cat(&sb, ">");

#if __FreeBSD_version < 900020
	sbuf_finish(&sb);
	if (sbuf_overflowed(&sb) == 0)
#else
	if (sbuf_finish(&sb) == 0)
#endif
		device_printf(dev, "%s\n", sbuf_data(&sb));

	sbuf_delete(&sb);
	free(buf, M_TEMP);
}
示例#16
0
/*
 * Read a symbolic link
 */
static int
pfs_readlink(struct vop_readlink_args *va)
{
	struct vnode *vn = va->a_vp;
	struct pfs_vdata *pvd = vn->v_data;
	struct pfs_node *pn = pvd->pvd_pn;
	struct uio *uio = va->a_uio;
	struct proc *proc = NULL;
	struct thread *td = curthread;
	char buf[PATH_MAX];
	struct sbuf sb;
	int error, locked;

	PFS_TRACE(("%s", pn->pn_name));
	pfs_assert_not_owned(pn);

	if (vn->v_type != VLNK)
		PFS_RETURN (EINVAL);
	KASSERT_PN_IS_LINK(pn);

	if (pn->pn_fill == NULL)
		PFS_RETURN (EIO);

	if (pvd->pvd_pid != NO_PID) {
		if ((proc = pfind(pvd->pvd_pid)) == NULL)
			PFS_RETURN (EIO);
		if (proc->p_flag & P_WEXIT) {
			PROC_UNLOCK(proc);
			PFS_RETURN (EIO);
		}
		_PHOLD(proc);
		PROC_UNLOCK(proc);
	}
	vhold(vn);
	locked = VOP_ISLOCKED(vn, td);
	VOP_UNLOCK(vn, 0, td);

	/* sbuf_new() can't fail with a static buffer */
	sbuf_new(&sb, buf, sizeof buf, 0);

	error = pn_fill(td, proc, pn, &sb, NULL);

	if (proc != NULL)
		PRELE(proc);
	vn_lock(vn, locked | LK_RETRY, td);
	vdrop(vn);

	if (error) {
		sbuf_delete(&sb);
		PFS_RETURN (error);
	}

	sbuf_finish(&sb);
	error = uiomove_frombuf(sbuf_data(&sb), sbuf_len(&sb), uio);
	sbuf_delete(&sb);
	PFS_RETURN (error);
}
示例#17
0
int
linux_sysctl(struct thread *td, struct linux_sysctl_args *args)
{
	struct l___sysctl_args la;
	struct sbuf *sb;
	l_int *mib;
	int error, i;

	error = copyin(args->args, &la, sizeof(la));
	if (error)
		return (error);

	if (la.nlen <= 0 || la.nlen > LINUX_CTL_MAXNAME)
		return (ENOTDIR);

	mib = malloc(la.nlen * sizeof(l_int), M_TEMP, M_WAITOK);
	error = copyin(PTRIN(la.name), mib, la.nlen * sizeof(l_int));
	if (error) {
		free(mib, M_TEMP);
		return (error);
	}

	switch (mib[0]) {
	case LINUX_CTL_KERN:
		if (la.nlen < 2)
			break;

		switch (mib[1]) {
		case LINUX_KERN_VERSION:
			error = handle_string(&la, version);
			free(mib, M_TEMP);
			return (error);
		default:
			break;
		}
		break;
	default:
		break;
	}

	sb = sbuf_new(NULL, NULL, 20 + la.nlen * 5, SBUF_AUTOEXTEND);
	if (sb == NULL) {
		linux_msg(td, "sysctl is not implemented");
	} else {
		sbuf_printf(sb, "sysctl ");
		for (i = 0; i < la.nlen; i++)
			sbuf_printf(sb, "%c%d", (i) ? ',' : '{', mib[i]);
		sbuf_printf(sb, "} is not implemented");
		sbuf_finish(sb);
		linux_msg(td, "%s", sbuf_data(sb));
		sbuf_delete(sb);
	}

	free(mib, M_TEMP);
	return (ENOTDIR);
}
示例#18
0
char *
ctl_io_string(union ctl_io *io, char *str, int str_len)
{
	struct sbuf sb;

	sbuf_new(&sb, str, str_len, SBUF_FIXEDLEN);
	ctl_io_sbuf(io, &sb);
	sbuf_finish(&sb);
	return (sbuf_data(&sb));
}
示例#19
0
char *
ctl_io_error_string(union ctl_io *io, struct scsi_inquiry_data *inq_data,
		    char *str, int str_len)
{
	struct sbuf sb;

	sbuf_new(&sb, str, str_len, SBUF_FIXEDLEN);
	ctl_io_error_sbuf(io, inq_data, &sb);
	sbuf_finish(&sb);
	return (sbuf_data(&sb));
}
示例#20
0
int
send_command (unsigned char interactive, unsigned char *cmd, int screen_num)
{
  Window w, root;
  int done = 0;
  struct sbuf *s;

  s = sbuf_new(0);
  sbuf_printf(s, "%c%s", interactive, cmd);


  /* If the user specified a specific screen, then send the event to
     that screen. */
  if (screen_num >= 0)
    root = RootWindow (dpy, screen_num);
  else
    root = DefaultRootWindow (dpy);

  w = XCreateSimpleWindow (dpy, root, 0, 0, 1, 1, 0, 0, 0);

  /* Select first to avoid race condition */
  XSelectInput (dpy, w, PropertyChangeMask);

  XChangeProperty (dpy, w, rp_command, XA_STRING,
                   8, PropModeReplace, sbuf_get(s), strlen ((char *)cmd) + 2);

  XChangeProperty (dpy, root,
                   rp_command_request, XA_WINDOW,
                   8, PropModeAppend, (unsigned char *)&w, sizeof (Window));

  sbuf_free (s);

  while (!done)
    {
      XEvent ev;

      XMaskEvent (dpy, PropertyChangeMask, &ev);
      if (ev.xproperty.atom == rp_command_result
          && ev.xproperty.state == PropertyNewValue)
        {
          receive_command_result(ev.xproperty.window);
          done = 1;
        }
    }

  XDestroyWindow (dpy, w);

  return 1;
}
示例#21
0
char *
ctl_scsi_sense_string(struct ctl_scsiio *ctsio,
		      struct scsi_inquiry_data *inq_data, char *str,
		      int str_len)
{
	struct sbuf sb;

	sbuf_new(&sb, str, str_len, 0);

	ctl_scsi_sense_sbuf(ctsio, inq_data, &sb, SSS_FLAG_PRINT_COMMAND);

	sbuf_finish(&sb);

	return(sbuf_data(&sb));
}
示例#22
0
void 
ctl_scsi_sense_print(struct ctl_scsiio *ctsio,
		     struct scsi_inquiry_data *inq_data)
{
	struct sbuf sb;
	char str[512];

	sbuf_new(&sb, str, sizeof(str), 0);

	ctl_scsi_sense_sbuf(ctsio, inq_data, &sb, SSS_FLAG_PRINT_COMMAND);

	sbuf_finish(&sb);

	printf("%s", sbuf_data(&sb));
}
示例#23
0
static void
acpi_cst_support_list(struct acpi_cst_softc *sc)
{
    struct sbuf sb;
    int i;

    /*
     * Set up the list of Cx states
     */
    sbuf_new(&sb, sc->cst_cx_supported, sizeof(sc->cst_cx_supported),
	SBUF_FIXEDLEN);
    for (i = 0; i < sc->cst_cx_count; i++)
	sbuf_printf(&sb, "C%d/%d ", i + 1, sc->cst_cx_states[i].trans_lat);
    sbuf_trim(&sb);
    sbuf_finish(&sb);
}	
示例#24
0
/*
 * ctl_scsi_sense_sbuf() returns 0 for success and -1 for failure.
 */
int
ctl_scsi_sense_sbuf(struct ctl_scsiio *ctsio,
		    struct scsi_inquiry_data *inq_data, struct sbuf *sb,
		    scsi_sense_string_flags flags)
{
	char	  path_str[64];

	if ((ctsio == NULL) || (sb == NULL))
		return(-1);

	ctl_scsi_path_string((union ctl_io *)ctsio, path_str, sizeof(path_str));

	if (flags & SSS_FLAG_PRINT_COMMAND) {

		sbuf_cat(sb, path_str);

		ctl_scsi_command_string(ctsio, inq_data, sb);

		sbuf_printf(sb, "\n");
	}

	scsi_sense_only_sbuf(&ctsio->sense_data, ctsio->sense_len, sb,
			     path_str, inq_data, ctsio->cdb, ctsio->cdb_len);

	return(0);
}

char *
ctl_scsi_sense_string(struct ctl_scsiio *ctsio,
		      struct scsi_inquiry_data *inq_data, char *str,
		      int str_len)
{
	struct sbuf sb;

	sbuf_new(&sb, str, str_len, 0);

	ctl_scsi_sense_sbuf(ctsio, inq_data, &sb, SSS_FLAG_PRINT_COMMAND);

	sbuf_finish(&sb);

	return(sbuf_data(&sb));
}

#ifdef _KERNEL
void 
ctl_scsi_sense_print(struct ctl_scsiio *ctsio,
		     struct scsi_inquiry_data *inq_data)
{
	struct sbuf sb;
	char str[512];

	sbuf_new(&sb, str, sizeof(str), 0);

	ctl_scsi_sense_sbuf(ctsio, inq_data, &sb, SSS_FLAG_PRINT_COMMAND);

	sbuf_finish(&sb);

	printf("%s", sbuf_data(&sb));
}

#else /* _KERNEL */
void
ctl_scsi_sense_print(struct ctl_scsiio *ctsio,
		     struct scsi_inquiry_data *inq_data, FILE *ofile)
{
	struct sbuf sb;
	char str[512];

	if ((ctsio == NULL) || (ofile == NULL))
		return;

	sbuf_new(&sb, str, sizeof(str), 0);

	ctl_scsi_sense_sbuf(ctsio, inq_data, &sb, SSS_FLAG_PRINT_COMMAND);

	sbuf_finish(&sb);

	fprintf(ofile, "%s", sbuf_data(&sb));
}
示例#25
0
文件: vardata.c 项目: mmase/wgrib2
/*
 * Print a number of variable values, where the optional comments
 * for each value identify the variable, and each dimension index.
 */
static void
pr_any_vals(
     const ncvar_t *vp,		/* variable */
     size_t len,		/* number of values to print */
     boolean more,		/* true if more data for this row will
				 * follow, so add trailing comma */
     boolean lastrow,		/* true if this is the last row for this
				 * variable, so terminate with ";" instead
				 * of "," */
     const void *vals,		/* pointer to block of values */
     const fspec_t* fsp,	/* formatting specs */
     const size_t *cor		/* corner coordinates */
     )
{
    long iel;
    safebuf_t *sb = sbuf_new();
    const char *valp = (const char *)vals;

    for (iel = 0; iel < len-1; iel++) {
	print_any_val(sb, vp, (void *)valp);
	valp += vp->tinfo->size; /* next value according to type */
	if (fsp->full_data_cmnts) {
	    printf(sb->buf);
	    printf(",");
	    annotate (vp, fsp, cor, iel);
	} else {
	    sbuf_cat(sb, ", ");
	    lput(sbuf_str(sb));
	}
    }
    print_any_val(sb, vp, (void *)valp);
    valp += vp->tinfo->size;	/* next value according to type */
    if (fsp->full_data_cmnts) {
	printf(sbuf_str(sb));
	lastdelim (more, lastrow);
	annotate (vp, fsp, cor, iel);
    } else {
	lput(sbuf_str(sb));
	lastdelim2 (more, lastrow);
    }
    sbuf_free(sb);
}
示例#26
0
文件: globals.c 项目: melkior/nilwm
static char *
get_cut_buffer (void)
{
  int nbytes;
  char *data;

  PRINT_DEBUG (("trying the cut buffer\n"));

  data = XFetchBytes (dpy, &nbytes);

  if (data)
    {
      struct sbuf *s = sbuf_new (0);
      sbuf_nconcat (s, data, nbytes);
      XFree (data);
      return sbuf_free_struct (s);
    }
  else
    return NULL;
}
示例#27
0
static void
acpi_cpu_cx_list(struct acpi_cpu_softc *sc)
{
    struct sbuf sb;
    int i;

    /*
     * Set up the list of Cx states
     */
    sc->cpu_non_c3 = 0;
    sbuf_new(&sb, sc->cpu_cx_supported, sizeof(sc->cpu_cx_supported),
	SBUF_FIXEDLEN);
    for (i = 0; i < sc->cpu_cx_count; i++) {
	sbuf_printf(&sb, "C%d/%d ", i + 1, sc->cpu_cx_states[i].trans_lat);
	if (sc->cpu_cx_states[i].type < ACPI_STATE_C3)
	    sc->cpu_non_c3 = i;
    }
    sbuf_trim(&sb);
    sbuf_finish(&sb);
}	
示例#28
0
/*
 * Create an sbuf with uio data
 */
struct sbuf *
sbuf_uionew(struct sbuf *s, struct uio *uio, int *error)
{
	KASSERT(uio != NULL);
	KASSERT(error != NULL);

	s = sbuf_new(s, NULL, uio->uio_resid + 1, 0);
	if (s == NULL) {
		*error = ENOMEM;
		return (NULL);
	}
	*error = uiomove(s->s_buf, uio->uio_resid, uio);
	if (*error != 0) {
		sbuf_delete(s);
		return (NULL);
	}
	s->s_len = s->s_size - 1;
	*error = 0;
	return (s);
}
示例#29
0
/*
 * Print a number of attribute values
 */
void
pr_any_att_vals(
     const ncatt_t *ap,		/* attribute */
     const void *vals		/* pointer to block of values */
     )
{
    size_t iel;
    size_t len = ap->len;		/* number of values to print */
    const char *valp = (const char *)vals;
    safebuf_t *sb = sbuf_new();

    for (iel = 0; iel < len - 1; iel++) {
	print_any_att_val(sb, ap, (void *)valp);
	valp += ap->tinfo->size; /* next value according to type */
	sbuf_cat(sb, iel == len - 1 ? "" : ", ");
	lput(sbuf_str(sb));
    }
    print_any_att_val(sb, ap, (void *)valp);
    lput(sbuf_str(sb));
    sbuf_free(sb);
}
示例#30
0
char *
epg_to_m3u(const list_s *channels, enum epg_m3u_format format)
{
    sbuf_s *buffer = sbuf_new();
    error_if(buffer == NULL, error, "Error Allocating sbuf_s");

    error_if(channels == NULL, error, "Params Error");
    trace("There are %zu channels", list_count(channels));

    list_apply_with_state_cb func =
        (format == epg_m3u_format_simpletv) ?
        _gen_m3u_simpletv : _gen_m3u_tvheadend;

    list_walk_with_state((list_s *)channels, func, (void *)buffer);

    char *s = sbuf_detach(buffer);
    sbuf_delete(buffer);
    return s;

error:
    if (buffer)
        sbuf_delete(buffer);
    return NULL;
}