本文整理汇总了C++中sbuf_delete函数的典型用法代码示例。如果您正苦于以下问题:C++ sbuf_delete函数的具体用法?C++ sbuf_delete怎么用?C++ sbuf_delete使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sbuf_delete函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pkgdb_rquery_provide
struct pkgdb_it *
pkgdb_rquery_provide(struct pkgdb *db, const char *provide, const char *repo)
{
sqlite3_stmt *stmt;
struct sbuf *sql = NULL;
const char *reponame = NULL;
int ret;
const char basesql[] = ""
"SELECT p.id, p.origin, p.name, p.version, p.comment, "
"p.name || '~' || p.origin as uniqueid, "
"p.prefix, p.desc, p.arch, p.maintainer, p.www, "
"p.licenselogic, p.flatsize, p.pkgsize, "
"p.cksum, p.manifestdigest, p.path AS repopath, '%1$s' AS dbname "
"FROM '%1$s'.packages AS p, '%1$s'.pkg_provides AS pp, "
"'%1$s'.provides AS pr "
"WHERE p.id = pp.package_id "
"AND pp.provide_id = pr.id "
"AND pr.name = ?1;";
assert(db != NULL);
reponame = pkgdb_get_reponame(db, repo);
sql = sbuf_new_auto();
/*
* Working on multiple remote repositories
*/
if (reponame == NULL) {
/* duplicate the query via UNION for all the attached
* databases */
ret = pkgdb_sql_all_attached(db->sqlite, sql,
basesql, " UNION ALL ");
if (ret != EPKG_OK) {
sbuf_delete(sql);
return (NULL);
}
} else
sbuf_printf(sql, basesql, reponame);
sbuf_finish(sql);
pkg_debug(4, "Pkgdb: running '%s'", sbuf_get(sql));
ret = sqlite3_prepare_v2(db->sqlite, sbuf_get(sql), -1, &stmt, NULL);
if (ret != SQLITE_OK) {
ERROR_SQLITE(db->sqlite, sbuf_get(sql));
sbuf_delete(sql);
return (NULL);
}
sbuf_delete(sql);
sqlite3_bind_text(stmt, 1, provide, -1, SQLITE_TRANSIENT);
return (pkgdb_it_new(db, stmt, PKG_REMOTE, PKGDB_IT_FLAG_ONCE));
}
示例2: vfs_mountroot
void
vfs_mountroot(void)
{
struct mount *mp;
struct sbuf *sb;
struct thread *td;
time_t timebase;
int error;
td = curthread;
vfs_mountroot_wait();
sb = sbuf_new_auto();
vfs_mountroot_conf0(sb);
sbuf_finish(sb);
error = vfs_mountroot_devfs(td, &mp);
while (!error) {
error = vfs_mountroot_parse(sb, mp);
if (!error) {
error = vfs_mountroot_shuffle(td, mp);
if (!error) {
sbuf_clear(sb);
error = vfs_mountroot_readconf(td, sb);
sbuf_finish(sb);
}
}
}
sbuf_delete(sb);
/*
* Iterate over all currently mounted file systems and use
* the time stamp found to check and/or initialize the RTC.
* Call inittodr() only once and pass it the largest of the
* timestamps we encounter.
*/
timebase = 0;
mtx_lock(&mountlist_mtx);
mp = TAILQ_FIRST(&mountlist);
while (mp != NULL) {
if (mp->mnt_time > timebase)
timebase = mp->mnt_time;
mp = TAILQ_NEXT(mp, mnt_list);
}
mtx_unlock(&mountlist_mtx);
inittodr(timebase);
/* Keep prison0's root in sync with the global rootvnode. */
mtx_lock(&prison0.pr_mtx);
prison0.pr_root = rootvnode;
vref(prison0.pr_root);
mtx_unlock(&prison0.pr_mtx);
mtx_lock(&mountlist_mtx);
atomic_store_rel_int(&root_mount_complete, 1);
wakeup(&root_mount_complete);
mtx_unlock(&mountlist_mtx);
}
示例3: khttpd_ktr_logging_main
static void
khttpd_ktr_logging_main(void *arg)
{
struct sbuf *sbuf;
struct thread *td;
int error;
KHTTPD_ASSERT_CURPROC_IS_KHTTPD();
td = curthread;
khttpd_ktr_logging_idx = ktr_idx;
error = kern_openat(td, AT_FDCWD, KHTTPD_KTR_FILE, UIO_SYSSPACE,
O_CREAT | O_TRUNC | O_WRONLY, 0666);
if (error != 0) {
log(LOG_WARNING, "khttpd: failed to open ktr file '%s' "
"(error %d)", KHTTPD_KTR_FILE, error);
goto quit;
}
kern_close(td, td->td_retval[0]);
sbuf = sbuf_new_auto();
while (!khttpd_ktr_logging_shutdown) {
khttpd_ktr_logging(sbuf);
pause("khttpd-ktr-flush", hz);
}
sbuf_delete(sbuf);
quit:
khttpd_ktr_logging_thread = NULL;
kthread_exit();
}
示例4: 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;
}
示例5: 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);
}
示例6: sysctl_handle_dpi
static int
sysctl_handle_dpi(SYSCTL_HANDLER_ARGS)
{
struct ioat_softc *ioat;
struct sbuf sb;
#define PRECISION "1"
const uintmax_t factor = 10;
uintmax_t rate;
int error;
ioat = arg1;
sbuf_new_for_sysctl(&sb, NULL, 16, req);
if (ioat->stats.interrupts == 0) {
sbuf_printf(&sb, "NaN");
goto out;
}
rate = ioat->stats.descriptors_processed * factor /
ioat->stats.interrupts;
sbuf_printf(&sb, "%ju.%." PRECISION "ju", rate / factor,
rate % factor);
#undef PRECISION
out:
error = sbuf_finish(&sb);
sbuf_delete(&sb);
if (error != 0 || req->newptr == NULL)
return (error);
return (EINVAL);
}
示例7: 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);
}
示例8: sbuf_uionew
/*
* 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);
}
示例9: 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);
}
示例10: 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);
}
示例11: 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);
}
示例12: 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);
}
示例13: 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));
}
示例14: exec_add
int
exec_add(int argc, char **argv)
{
struct pkgdb *db = NULL;
struct sbuf *failedpkgs = sbuf_new_auto();
char path[MAXPATHLEN + 1];
char *file;
int retcode = EPKG_OK;
int i;
int failedpkgcount = 0;
struct pkg *p = NULL;
if (argc < 2) {
usage_add();
return (EX_USAGE);
}
if (geteuid() != 0) {
warnx("adding packages can only be done as root");
return (EX_NOPERM);
}
if (pkgdb_open(&db, PKGDB_DEFAULT) != EPKG_OK) {
return (EX_IOERR);
}
for (i = 1; i < argc; i++) {
if (is_url(argv[i]) == EPKG_OK) {
snprintf(path, sizeof(path), "./%s", basename(argv[i]));
if ((retcode = pkg_fetch_file(argv[i], path)) != EPKG_OK)
break;
file = path;
} else
file = argv[i];
pkg_open(&p, file, NULL);
if ((retcode = pkg_add(db, file, 0)) != EPKG_OK) {
sbuf_cat(failedpkgs, argv[i]);
if (i != argc - 1)
sbuf_printf(failedpkgs, ", ");
failedpkgcount++;
}
}
pkgdb_close(db);
if(failedpkgcount > 0) {
sbuf_finish(failedpkgs);
printf("Failed to install the following %d package(s): %s.\n", failedpkgcount, sbuf_data(failedpkgs));
}
sbuf_delete(failedpkgs);
return (retcode == EPKG_OK ? EX_OK : EX_SOFTWARE);
}
示例15: pkg_repo_binary_search
struct pkg_repo_it *
pkg_repo_binary_search(struct pkg_repo *repo, const char *pattern, match_t match,
pkgdb_field field, pkgdb_field sort)
{
sqlite3 *sqlite = PRIV_GET(repo);
sqlite3_stmt *stmt = NULL;
struct sbuf *sql = NULL;
int ret;
const char *multireposql = ""
"SELECT id, origin, name, version, comment, "
"prefix, desc, arch, maintainer, www, "
"licenselogic, flatsize, pkgsize, "
"cksum, path AS repopath, '%1$s' AS dbname, '%2$s' AS repourl "
"FROM packages ";
if (pattern == NULL || pattern[0] == '\0')
return (NULL);
sql = sbuf_new_auto();
sbuf_printf(sql, multireposql, repo->name, repo->url);
/* close the UNIONs and build the search query */
sbuf_cat(sql, "WHERE ");
pkg_repo_binary_build_search_query(sql, match, field, sort);
sbuf_cat(sql, ";");
sbuf_finish(sql);
pkg_debug(4, "Pkgdb: 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));
sbuf_delete(sql);
return (NULL);
}
sbuf_delete(sql);
sqlite3_bind_text(stmt, 1, pattern, -1, SQLITE_TRANSIENT);
return (pkg_repo_binary_it_new(repo, stmt, PKGDB_IT_FLAG_ONCE));
}