本文整理汇总了C++中sbuf_data函数的典型用法代码示例。如果您正苦于以下问题:C++ sbuf_data函数的具体用法?C++ sbuf_data怎么用?C++ sbuf_data使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sbuf_data函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: testStaticBuffer
void testStaticBuffer(
Test * pTest)
{
STATIC_BUFFER sbuffer;
char *data1 = "Joshua";
char *data2 = "Anna";
char *data3 = "Christopher";
char *data4 = "Mary";
char data_buffer[480] = "";
char test_data_buffer[480] = "";
char *data;
unsigned count;
sbuf_init(&sbuffer, NULL, 0);
ct_test(pTest, sbuf_empty(&sbuffer) == true);
ct_test(pTest, sbuf_data(&sbuffer) == NULL);
ct_test(pTest, sbuf_size(&sbuffer) == 0);
ct_test(pTest, sbuf_count(&sbuffer) == 0);
ct_test(pTest, sbuf_append(&sbuffer, data1, strlen(data1)) == false);
sbuf_init(&sbuffer, data_buffer, sizeof(data_buffer));
ct_test(pTest, sbuf_empty(&sbuffer) == true);
ct_test(pTest, sbuf_data(&sbuffer) == data_buffer);
ct_test(pTest, sbuf_size(&sbuffer) == sizeof(data_buffer));
ct_test(pTest, sbuf_count(&sbuffer) == 0);
ct_test(pTest, sbuf_append(&sbuffer, data1, strlen(data1)) == true);
ct_test(pTest, sbuf_append(&sbuffer, data2, strlen(data2)) == true);
ct_test(pTest, sbuf_append(&sbuffer, data3, strlen(data3)) == true);
ct_test(pTest, sbuf_append(&sbuffer, data4, strlen(data4)) == true);
strcat(test_data_buffer, data1);
strcat(test_data_buffer, data2);
strcat(test_data_buffer, data3);
strcat(test_data_buffer, data4);
ct_test(pTest, sbuf_count(&sbuffer) == strlen(test_data_buffer));
data = sbuf_data(&sbuffer);
count = sbuf_count(&sbuffer);
ct_test(pTest, memcmp(data, test_data_buffer, count) == 0);
ct_test(pTest, count == strlen(test_data_buffer));
ct_test(pTest, sbuf_truncate(&sbuffer, 0) == true);
ct_test(pTest, sbuf_count(&sbuffer) == 0);
ct_test(pTest, sbuf_size(&sbuffer) == sizeof(data_buffer));
ct_test(pTest, sbuf_append(&sbuffer, data4, strlen(data4)) == true);
data = sbuf_data(&sbuffer);
count = sbuf_count(&sbuffer);
ct_test(pTest, memcmp(data, data4, count) == 0);
ct_test(pTest, count == strlen(data4));
return;
}
开发者ID:beh9540,项目名称:bacnetwx2,代码行数:52,代码来源:sbuf.c
示例2: pkg_repo_binary_stat
int64_t
pkg_repo_binary_stat(struct pkg_repo *repo, pkg_stats_t type)
{
sqlite3 *sqlite = PRIV_GET(repo);
sqlite3_stmt *stmt = NULL;
int64_t stats = 0;
struct sbuf *sql = NULL;
int ret;
sql = sbuf_new_auto();
switch(type) {
case PKG_STATS_LOCAL_COUNT:
goto out;
break;
case PKG_STATS_LOCAL_SIZE:
goto out;
break;
case PKG_STATS_REMOTE_UNIQUE:
sbuf_printf(sql, "SELECT COUNT(id) FROM main.packages;");
break;
case PKG_STATS_REMOTE_COUNT:
sbuf_printf(sql, "SELECT COUNT(id) FROM main.packages;");
break;
case PKG_STATS_REMOTE_SIZE:
sbuf_printf(sql, "SELECT SUM(pkgsize) FROM main.packages;");
break;
case PKG_STATS_REMOTE_REPOS:
goto out;
break;
}
sbuf_finish(sql);
pkg_debug(4, "binary_repo: running '%s'", sbuf_data(sql));
ret = sqlite3_prepare_v2(sqlite, sbuf_data(sql), -1, &stmt, NULL);
if (ret != SQLITE_OK) {
ERROR_SQLITE(sqlite, sbuf_data(sql));
goto out;
}
while (sqlite3_step(stmt) != SQLITE_DONE) {
stats = sqlite3_column_int64(stmt, 0);
}
out:
sbuf_free(sql);
if (stmt != NULL)
sqlite3_finalize(stmt);
return (stats);
}
开发者ID:baitisj,项目名称:pkg,代码行数:51,代码来源:query.c
示例3: ctl_data_print
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));
}
}
开发者ID:Lxg1582,项目名称:freebsd,代码行数:30,代码来源:ctl_util.c
示例4: progressbar_start
void
progressbar_start(const char *pmsg)
{
free(progress_message);
progress_message = NULL;
if (quiet)
return;
if (pmsg != NULL)
progress_message = strdup(pmsg);
else {
sbuf_finish(msg_buf);
progress_message = strdup(sbuf_data(msg_buf));
}
last_progress_percent = -1;
last_tick = 0;
begin = last_update = time(NULL);
bytes_per_second = 0;
stalled = 0;
progress_started = true;
progress_interrupted = false;
if (!isatty(STDOUT_FILENO))
printf("%s: ", progress_message);
else
printf("%s: 0%%", progress_message);
}
开发者ID:dotike,项目名称:pkg,代码行数:27,代码来源:event.c
示例5: mtree_file_path
/* 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_auto();
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;
}
开发者ID:Alkzndr,项目名称:freebsd,代码行数:36,代码来源:mtree.c
示例6: procfs_doosrel
int
procfs_doosrel(PFS_FILL_ARGS)
{
const char *pp;
int ov, osrel, i;
if (uio == NULL)
return (EOPNOTSUPP);
if (uio->uio_rw == UIO_READ) {
sbuf_printf(sb, "%d\n", p->p_osrel);
} else {
sbuf_trim(sb);
sbuf_finish(sb);
pp = sbuf_data(sb);
osrel = 0;
i = sbuf_len(sb);
while (i--) {
if (*pp < '0' || *pp > '9')
return (EINVAL);
ov = osrel * 10 + *pp++ - '0';
if (ov < osrel)
return (EINVAL);
osrel = ov;
}
p->p_osrel = osrel;
}
return (0);
}
开发者ID:edgar-pek,项目名称:PerspicuOS,代码行数:28,代码来源:procfs_osrel.c
示例7: acpi_cpu_usage_sysctl
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);
}
开发者ID:DangerDexter,项目名称:FreeBSD-8.0-dyntick,代码行数:31,代码来源:acpi_cpu.c
示例8: sysctl_debug_ddb_scripting_scripts
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);
}
开发者ID:oza,项目名称:FreeBSD-7.3-dyntick,代码行数:30,代码来源:db_script.c
示例9: sbuf_copy_lines
static int
sbuf_copy_lines(struct sbuf *to, const char *from, int N)
{
int cnt = 0;
int i;
if (N == 0)
return (0);
for (i = 0; from[i] != '\0'; i++) {
if (from[i] == '\n') {
cnt++;
continue;
}
if (cnt == N)
break;
}
if (to == NULL)
return (i);
if (sbuf_len(to) > 0 &&
sbuf_data(to)[sbuf_len(to)-1] != '\n')
sbuf_putc(to, '\n');
sbuf_bcat(to, from, i);
sbuf_finish(to);
return (i);
}
开发者ID:TetragrammatonHermit,项目名称:pkg,代码行数:29,代码来源:merge3.c
示例10: job_status_end
void
job_status_end(struct sbuf *msg)
{
sbuf_finish(msg);
printf("%s\n", sbuf_data(msg));
/*printf("\033]0; %s\007", sbuf_data(msg));*/
sbuf_clear(msg);
}
开发者ID:dotike,项目名称:pkg,代码行数:8,代码来源:event.c
示例11: print_and_set_term_title
static void
print_and_set_term_title(struct sbuf *msg)
{
sbuf_finish(msg);
printf("%s", sbuf_data(msg));
/*printf("\033]0; %s\007", sbuf_data(msg));*/
sbuf_delete(msg);
}
开发者ID:renchap,项目名称:pkg,代码行数:8,代码来源:event.c
示例12: sbuf_get
const char *
sbuf_get(struct sbuf *buf)
{
if (buf == NULL)
return (NULL);
return sbuf_data(buf);
}
开发者ID:flz,项目名称:pkgng,代码行数:8,代码来源:pkg_util.c
示例13: print_status_end
static void
print_status_end(struct sbuf *msg)
{
sbuf_finish(msg);
printf("%s", sbuf_data(msg));
/*printf("\033]0; %s\007", sbuf_data(msg));*/
sbuf_delete(msg);
}
开发者ID:dschossig,项目名称:pkg,代码行数:8,代码来源:event.c
示例14: pkg_set_files_from_object
static int
pkg_set_files_from_object(struct pkg *pkg, ucl_object_t *obj)
{
ucl_object_t *cur;
ucl_object_iter_t it = NULL;
const char *sum = NULL;
const char *uname = NULL;
const char *gname = NULL;
void *set = NULL;
mode_t perm = 0;
struct sbuf *fname = NULL;
const char *key, *okey;
okey = ucl_object_key(obj);
if (okey == NULL)
return (EPKG_FATAL);
urldecode(okey, &fname);
while ((cur = ucl_iterate_object(obj, &it, true))) {
key = ucl_object_key(cur);
if (key == NULL)
continue;
if (!strcasecmp(key, "uname") && cur->type == UCL_STRING)
uname = ucl_object_tostring(cur);
else if (!strcasecmp(key, "gname") && cur->type == UCL_STRING)
gname = ucl_object_tostring(cur);
else if (!strcasecmp(key, "sum") && cur->type == UCL_STRING &&
strlen(ucl_object_tostring(cur)) == 64)
sum = ucl_object_tostring(cur);
else if (!strcasecmp(key, "perm") &&
(cur->type == UCL_STRING || cur->type == UCL_INT)) {
if ((set = setmode(ucl_object_tostring_forced(cur))) == NULL)
pkg_emit_error("Not a valid mode: %s",
ucl_object_tostring(cur));
else
perm = getmode(set, 0);
} else {
pkg_emit_error("Skipping unknown key for file(%s): %s",
sbuf_data(fname), ucl_object_tostring(cur));
}
}
pkg_addfile_attr(pkg, sbuf_data(fname), sum, uname, gname, perm, false);
sbuf_delete(fname);
return (EPKG_OK);
}
开发者ID:grtodd,项目名称:pkg,代码行数:46,代码来源:pkg_manifest.c
示例15: pkg_script_run
int
pkg_script_run(struct pkg *pkg, pkg_script_t type)
{
struct pkg_script *script = NULL;
pkg_script_t stype;
struct sbuf *script_cmd = sbuf_new_auto();
size_t i;
struct {
const char *arg;
const pkg_script_t b;
const pkg_script_t a;
} const map[] = {
/* a implies b with argument arg */
{"PRE-INSTALL", PKG_SCRIPT_INSTALL, PKG_SCRIPT_PRE_INSTALL},
{"POST-INSTALL", PKG_SCRIPT_INSTALL, PKG_SCRIPT_POST_INSTALL},
{"PRE-UPGRADE", PKG_SCRIPT_UPGRADE, PKG_SCRIPT_PRE_UPGRADE},
{"POST-UPGRADE", PKG_SCRIPT_UPGRADE, PKG_SCRIPT_POST_UPGRADE},
{"DEINSTALL", PKG_SCRIPT_DEINSTALL, PKG_SCRIPT_PRE_DEINSTALL},
{"POST-DEINSTALL", PKG_SCRIPT_DEINSTALL, PKG_SCRIPT_POST_DEINSTALL},
};
for (i = 0; i < sizeof(map) / sizeof(map[0]); i++) {
if (map[i].a == type)
break;
}
if (map[i].a != type)
return (ERROR_BAD_ARG("type"));
while (pkg_scripts(pkg, &script) == EPKG_OK) {
stype = pkg_script_type(script);
if (stype == map[i].a || stype == map[i].b) {
sbuf_reset(script_cmd);
sbuf_printf(script_cmd, "PKG_PREFIX=%s\nset -- %s-%s",
pkg_get(pkg, PKG_PREFIX), pkg_get(pkg, PKG_NAME),
pkg_get(pkg, PKG_VERSION));
if (stype == map[i].b) {
/* add arg **/
sbuf_cat(script_cmd, " ");
sbuf_cat(script_cmd, map[i].arg);
}
sbuf_cat(script_cmd, "\n");
sbuf_cat(script_cmd, pkg_script_data(script));
sbuf_finish(script_cmd);
system(sbuf_data(script_cmd));
}
}
sbuf_delete(script_cmd);
return (EPKG_OK);
}
开发者ID:philpep,项目名称:pkgng,代码行数:58,代码来源:scripts.c
示例16: xenbusb_back_enumerate_type
/**
* \brief Enumerate all devices of the given type on this bus.
*
* \param dev NewBus device_t for this XenBus backend bus instance.
* \param type String indicating the device sub-tree (e.g. "vfb", "vif")
* to enumerate.
*
* \return On success, 0. Otherwise an errno value indicating the
* type of failure.
*
* Devices that are found are entered into the NewBus hierarchy via
* xenbusb_add_device(). xenbusb_add_device() ignores duplicate detects
* and ignores duplicate devices, so it can be called unconditionally
* for any device found in the XenStore.
*
* The backend XenStore hierarchy has the following format:
*
* backend/<device type>/<frontend vm id>/<device id>
*
*/
static int
xenbusb_back_enumerate_type(device_t dev, const char *type)
{
struct xenbusb_softc *xbs;
const char **vms;
u_int vm_idx;
u_int vm_count;
int error;
xbs = device_get_softc(dev);
error = xs_directory(XST_NIL, xbs->xbs_node, type, &vm_count, &vms);
if (error)
return (error);
for (vm_idx = 0; vm_idx < vm_count; vm_idx++) {
struct sbuf *vm_path;
const char *vm;
const char **devs;
u_int dev_idx;
u_int dev_count;
vm = vms[vm_idx];
vm_path = xs_join(type, vm);
error = xs_directory(XST_NIL, xbs->xbs_node, sbuf_data(vm_path),
&dev_count, &devs);
sbuf_delete(vm_path);
if (error)
break;
for (dev_idx = 0; dev_idx < dev_count; dev_idx++) {
const char *dev_num;
struct sbuf *id;
dev_num = devs[dev_idx];
id = xs_join(vm, dev_num);
xenbusb_add_device(dev, type, sbuf_data(id));
sbuf_delete(id);
}
free(devs, M_XENSTORE);
}
free(vms, M_XENSTORE);
return (0);
}
开发者ID:JabirTech,项目名称:Source,代码行数:65,代码来源:xenbusb_back.c
示例17: pkg_repo_binary_query
struct pkg_repo_it *
pkg_repo_binary_query(struct pkg_repo *repo, const char *pattern, match_t match)
{
sqlite3 *sqlite = PRIV_GET(repo);
sqlite3_stmt *stmt = NULL;
struct sbuf *sql = NULL;
const char *comp = NULL;
int ret;
char basesql[BUFSIZ] = ""
"SELECT id, origin, name, name as uniqueid, version, comment, "
"prefix, desc, arch, maintainer, www, "
"licenselogic, flatsize, pkgsize, "
"cksum, manifestdigest, path AS repopath, '%s' AS dbname "
"FROM packages AS p";
if (match != MATCH_ALL && (pattern == NULL || pattern[0] == '\0'))
return (NULL);
sql = sbuf_new_auto();
comp = pkgdb_get_pattern_query(pattern, match);
if (comp && comp[0])
strlcat(basesql, comp, sizeof(basesql));
sbuf_printf(sql, basesql, repo->name);
sbuf_cat(sql, " ORDER BY name;");
sbuf_finish(sql);
pkg_debug(4, "Pkgdb: running '%s' query for %s", sbuf_data(sql),
pattern == NULL ? "all": pattern);
ret = sqlite3_prepare_v2(sqlite, sbuf_data(sql), sbuf_len(sql), &stmt,
NULL);
if (ret != SQLITE_OK) {
ERROR_SQLITE(sqlite, sbuf_data(sql));
sbuf_delete(sql);
return (NULL);
}
sbuf_delete(sql);
if (match != MATCH_ALL && match != MATCH_CONDITION)
sqlite3_bind_text(stmt, 1, pattern, -1, SQLITE_TRANSIENT);
return (pkg_repo_binary_it_new(repo, stmt, PKGDB_IT_FLAG_ONCE));
}
开发者ID:baitisj,项目名称:pkg,代码行数:45,代码来源:query.c
示例18: khttpd_ktr_logging
static void
khttpd_ktr_logging(struct sbuf *sbuf)
{
struct uio auio;
struct iovec aiov;
struct ktr_entry *ep;
struct thread *td;
int error, fd, i, n;
KHTTPD_ASSERT_CURPROC_IS_KHTTPD();
td = curthread;
error = kern_openat(td, AT_FDCWD, KHTTPD_KTR_FILE,
UIO_SYSSPACE, O_WRONLY | O_APPEND, 0666);
if (error != 0) {
log(LOG_WARNING,
"khttpd: failed to open ktr file '%s' (error %d)",
KHTTPD_KTR_FILE, error);
return;
}
fd = td->td_retval[0];
sbuf_clear(sbuf);
n = ktr_entries;
for (i = khttpd_ktr_logging_idx; i != ktr_idx;
i = i == n - 1 ? 0 : i + 1) {
ep = &ktr_buf[i];
sbuf_printf(sbuf, "%lld %p %d ",
(long long)ep->ktr_timestamp, ep->ktr_thread,
ep->ktr_cpu);
sbuf_printf(sbuf, ep->ktr_desc, ep->ktr_parms[0],
ep->ktr_parms[1], ep->ktr_parms[2],
ep->ktr_parms[3], ep->ktr_parms[4],
ep->ktr_parms[5]);
sbuf_cat(sbuf, "\n");
}
sbuf_finish(sbuf);
khttpd_ktr_logging_idx = i;
aiov.iov_base = sbuf_data(sbuf);
aiov.iov_len = sbuf_len(sbuf);
auio.uio_iov = &aiov;
auio.uio_iovcnt = 1;
auio.uio_resid = aiov.iov_len;
auio.uio_segflg = UIO_SYSSPACE;
error = kern_writev(td, fd, &auio);
if (error != 0)
log(LOG_WARNING, "khttpd: KTR flush failed "
"(error: %d)", error);
kern_close(td, fd);
}
开发者ID:Taketsuru,项目名称:khttpd,代码行数:57,代码来源:khttpd_ktr.c
示例19: ctl_io_string
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));
}
开发者ID:Lxg1582,项目名称:freebsd,代码行数:10,代码来源:ctl_util.c
示例20: sbuf_get
char *
sbuf_get(struct sbuf *buf)
{
assert(buf != NULL);
if (sbuf_done(buf) == 0)
sbuf_finish(buf);
return (sbuf_data(buf));
}
开发者ID:baloo,项目名称:pkgng,代码行数:10,代码来源:utils.c
注:本文中的sbuf_data函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论