本文整理汇总了C++中bsnprintf函数的典型用法代码示例。如果您正苦于以下问题:C++ bsnprintf函数的具体用法?C++ bsnprintf怎么用?C++ bsnprintf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了bsnprintf函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: bsnprintf
/*
* Edit a utime "duration" into ASCII
*/
char *edit_utime(utime_t val, char *buf, int buf_len)
{
char mybuf[200];
static const int32_t mult[] = {60*60*24*365, 60*60*24*30, 60*60*24, 60*60, 60};
static const char *mod[] = {"year", "month", "day", "hour", "min"};
int i;
uint32_t times;
*buf = 0;
for (i=0; i<5; i++) {
times = (uint32_t)(val / mult[i]);
if (times > 0) {
val = val - (utime_t)times * mult[i];
bsnprintf(mybuf, sizeof(mybuf), "%d %s%s ", times, mod[i], times>1?"s":"");
bstrncat(buf, mybuf, buf_len);
}
}
if (val == 0 && strlen(buf) == 0) {
bstrncat(buf, "0 secs", buf_len);
} else if (val != 0) {
bsnprintf(mybuf, sizeof(mybuf), "%d sec%s", (uint32_t)val, val>1?"s":"");
bstrncat(buf, mybuf, buf_len);
}
return buf;
}
开发者ID:AlD,项目名称:bareos,代码行数:28,代码来源:edit.c
示例2: bstrncpy
/*
* Authenticate Director
*/
bool BSOCK::authenticate_with_director(JCR *jcr,
const char *name, s_password &password, tls_t &tls,
char *response, int response_len)
{
char bashed_name[MAX_NAME_LENGTH];
BSOCK *dir = this; /* for readability */
response[0] = 0;
/*
* Send my name to the Director then do authentication
*/
bstrncpy(bashed_name, name, sizeof(bashed_name));
bash_spaces(bashed_name);
/*
* Timeout Hello after 5 mins
*/
dir->start_timer(60 * 5);
dir->fsend(hello, bashed_name);
if (!authenticate_outbound_connection(jcr, "Director", name, password, tls)) {
goto bail_out;
}
Dmsg1(6, ">dird: %s", dir->msg);
if (dir->recv() <= 0) {
dir->stop_timer();
bsnprintf(response, response_len, _("Bad response to Hello command: ERR=%s\n"
"The Director at \"%s:%d\" is probably not running.\n"),
dir->bstrerror(), dir->host(), dir->port());
return false;
}
dir->stop_timer();
Dmsg1(10, "<dird: %s", dir->msg);
if (!bstrncmp(dir->msg, OKhello, sizeof(OKhello) - 1)) {
bsnprintf(response, response_len, _("Director at \"%s:%d\" rejected Hello command\n"),
dir->host(), dir->port());
return false;
} else {
bsnprintf(response, response_len, "%s", dir->msg);
}
return true;
bail_out:
dir->stop_timer();
bsnprintf(response, response_len, _("Authorization problem with Director at \"%s:%d\"\n"
"Most likely the passwords do not agree.\n"
"If you are using TLS, there may have been a certificate "
"validation error during the TLS handshake.\n"
"Please see %s for help.\n"),
dir->host(), dir->port(), MANUAL_AUTH_URL);
return false;
}
开发者ID:gearsforwork,项目名称:bareos,代码行数:60,代码来源:bsock.c
示例3: pause_msg
void pause_msg(const char *file, const char *func, int line, const char *msg)
{
char buf[1000];
if (msg) {
bsnprintf(buf, sizeof(buf), "%s:%s:%d %s", file, func, line, msg);
} else {
bsnprintf(buf, sizeof(buf), "%s:%s:%d", file, func, line);
}
MessageBox(NULL, buf, "Pause", MB_OK);
}
开发者ID:AlD,项目名称:bareos,代码行数:10,代码来源:bfile.c
示例4: job_setattr
int job_setattr(PyObject *self, char *attrname, PyObject *value)
{
JCR *jcr;
bool found = false;
char *strval = NULL;
char buf[200];
char *errmsg;
int i;
Dmsg2(100, "In job_setattr=%s val=%p.\n", attrname, value);
if (value == NULL) { /* Cannot delete variables */
bsnprintf(buf, sizeof(buf), _("Cannot delete attribute %s"), attrname);
errmsg = buf;
goto bail_out;
}
jcr = get_jcr_from_PyObject(self);
if (!jcr) {
errmsg = _("Job pointer not found.");
goto bail_out;
}
/* Find attribute name in list */
for (i=0; setvars[i].name; i++) {
if (strcmp(setvars[i].name, attrname) == 0) {
found = true;
break;
}
}
if (!found) {
goto not_found;
}
/* Get argument value ***FIXME*** handle other formats */
if (setvars[i].fmt != NULL) {
if (!PyArg_Parse(value, (char *)setvars[i].fmt, &strval)) {
PyErr_SetString(PyExc_TypeError, _("Read-only attribute"));
return -1;
}
}
switch (i) {
case 0: /* JobReport */
Jmsg(jcr, M_INFO, 0, "%s", strval);
return 0;
}
not_found:
bsnprintf(buf, sizeof(buf), _("Cannot find attribute %s"), attrname);
errmsg = buf;
bail_out:
PyErr_SetString(PyExc_AttributeError, errmsg);
return -1;
}
开发者ID:halgandd,项目名称:bacula,代码行数:50,代码来源:pythonsd.c
示例5: queue_message_incoming_path
int
queue_message_incoming_path(uint32_t msgid, char *buf, size_t len)
{
return bsnprintf(buf, len, "%s/%08x",
PATH_INCOMING,
msgid);
}
开发者ID:clongeau,项目名称:opensmtpd,代码行数:7,代码来源:queue_backend.c
示例6: bsnprintf
void ItemFormatterBase::setPercent(int index, float value)
{
char buf[100];
bsnprintf(buf, sizeof(buf), "%.2f%%", value);
QString val = buf;
QString pix;
if (value < 8) {
pix = ":images/0p.png";
} else if (value < 24) {
pix = ":images/16p.png";
} else if (value < 40) {
pix = ":images/32p.png";
} else if (value < 56) {
pix = ":images/48p.png";
} else if (value < 72) {
pix = ":images/64p.png";
} else if (value < 88) {
pix = ":images/80p.png";
} else {
pix = ":images/96p.png";
}
setPixmap(index, QPixmap(pix), val);
//setSortValue(index, (int) value);
//setBackground(index, Qt::green);
}
开发者ID:anarexia,项目名称:bacula,代码行数:25,代码来源:fmtwidgetitem.cpp
示例7: dir_update_file_attributes
/**
* Update File Attribute data
* We do the following:
* 1. expand the bsock buffer to be large enough
* 2. Write a "header" into the buffer with serialized data
* VolSessionId
* VolSeesionTime
* FileIndex
* Stream
* data length that follows
* start of raw byte data from the Device record.
* Note, this is primarily for Attribute data, but can
* also handle any device record. The Director must know
* the raw byte data format that is defined for each Stream.
* Now Restore Objects pass through here STREAM_RESTORE_OBJECT
*/
bool dir_update_file_attributes(DCR *dcr, DEV_RECORD *rec)
{
JCR *jcr = dcr->jcr;
BSOCK *dir = jcr->dir_bsock;
ser_declare;
#ifdef NO_ATTRIBUTES_TEST
return true;
#endif
dir->msg = check_pool_memory_size(dir->msg, sizeof(FileAttributes) +
MAX_NAME_LENGTH + sizeof(DEV_RECORD) + rec->data_len + 1);
dir->msglen = bsnprintf(dir->msg, sizeof(FileAttributes) +
MAX_NAME_LENGTH + 1, FileAttributes, jcr->Job);
ser_begin(dir->msg + dir->msglen, 0);
ser_uint32(rec->VolSessionId);
ser_uint32(rec->VolSessionTime);
ser_int32(rec->FileIndex);
ser_int32(rec->Stream);
ser_uint32(rec->data_len);
ser_bytes(rec->data, rec->data_len);
dir->msglen = ser_length(dir->msg);
Dmsg1(1800, ">dird %s\n", dir->msg); /* Attributes */
return dir->send();
}
开发者ID:AlD,项目名称:bareos,代码行数:41,代码来源:askdir.c
示例8: sizeof
/*
* Edit an integer into "human-readable" format with four or fewer
* significant digits followed by a suffix that indicates the scale
* factor. The buf array inherits a 27 byte minimim length
* requirement from edit_unit64_with_commas(), although the output
* string is limited to eight characters.
*/
char *edit_uint64_with_suffix(uint64_t val, char *buf)
{
int commas = 0;
char *c, mbuf[50];
const char *suffix[] =
{ "", "K", "M", "G", "T", "P", "E", "Z", "Y", "FIX ME" };
int suffixes = sizeof(suffix) / sizeof(*suffix);
edit_uint64_with_commas(val, mbuf);
if ((c = strchr(mbuf, ',')) != NULL) {
commas++;
*c++ = '.';
while ((c = strchr(c, ',')) != NULL) {
commas++;
*c++ = '\0';
}
mbuf[5] = '\0'; // drop this to get '123.456 TB' rather than '123.4 TB'
}
if (commas >= suffixes)
commas = suffixes - 1;
bsnprintf(buf, 27, "%s %s", mbuf, suffix[commas]);
return buf;
}
开发者ID:AlD,项目名称:bareos,代码行数:32,代码来源:edit.c
示例9: Dmsg1
/* Return Job variables */
PyObject *job_getattr(PyObject *self, char *attrname)
{
JCR *jcr;
bool found = false;
int i;
char buf[10];
char errmsg[200];
Dmsg1(100, "In job_getattr=%s\n", attrname);
jcr = get_jcr_from_PyObject(self);
if (!jcr) {
bstrncpy(errmsg, _("Job pointer not found."), sizeof(errmsg));
goto bail_out;
}
for (i=0; getvars[i].name; i++) {
if (strcmp(getvars[i].name, attrname) == 0) {
found = true;
break;
}
}
if (!found) {
/* Try our methods */
return Py_FindMethod(JobMethods, self, attrname);
}
switch (i) {
case 0: /* Job */
return Py_BuildValue((char *)getvars[i].fmt, jcr->job_name); /* Non-unique name */
case 1: /* SD's name */
return Py_BuildValue((char *)getvars[i].fmt, my_name);
case 2: /* level */
return Py_BuildValue((char *)getvars[i].fmt, job_level_to_str(jcr->get_JobLevel()));
case 3: /* type */
return Py_BuildValue((char *)getvars[i].fmt, job_type_to_str(jcr->get_JobType()));
case 4: /* JobId */
return Py_BuildValue((char *)getvars[i].fmt, jcr->JobId);
case 5: /* Client */
return Py_BuildValue((char *)getvars[i].fmt, jcr->client_name);
case 6: /* Pool */
return Py_BuildValue((char *)getvars[i].fmt, jcr->dcr->pool_name);
case 7: /* MediaType */
return Py_BuildValue((char *)getvars[i].fmt, jcr->dcr->media_type);
case 8: /* JobName */
return Py_BuildValue((char *)getvars[i].fmt, jcr->Job);
case 9: /* JobStatus */
buf[1] = 0;
buf[0] = jcr->JobStatus;
return Py_BuildValue((char *)getvars[i].fmt, buf);
case 10:
return Py_BuildValue((char *)getvars[i].fmt, jcr->dcr->VolumeName);
case 11:
return Py_BuildValue((char *)getvars[i].fmt, jcr->dcr->dev_name);
}
bsnprintf(errmsg, sizeof(errmsg), _("Attribute %s not found."), attrname);
bail_out:
PyErr_SetString(PyExc_AttributeError, errmsg);
return NULL;
}
开发者ID:halgandd,项目名称:bacula,代码行数:59,代码来源:pythonsd.c
示例10: bsnprintf
const char *mode_to_str(int mode)
{
static char buf[100];
if (mode < 1 || mode > 4) {
bsnprintf(buf, sizeof(buf), "BAD mode=%d", mode);
return buf;
}
return modes[mode-1];
}
开发者ID:prelegalwonder,项目名称:bacula,代码行数:9,代码来源:dev.c
示例11: enqueue_offline
static int
enqueue_offline(int argc, char *argv[], FILE *ifile)
{
char path[SMTPD_MAXPATHLEN];
FILE *fp;
int i, fd, ch;
mode_t omode;
if (ckdir(PATH_SPOOL PATH_OFFLINE, 01777, 0, 0, 0) == 0)
errx(EX_UNAVAILABLE, "error in offline directory setup");
if (! bsnprintf(path, sizeof(path), "%s%s/%lld.XXXXXXXXXX", PATH_SPOOL,
PATH_OFFLINE, (long long int) time(NULL)))
err(EX_UNAVAILABLE, "snprintf");
omode = umask(7077);
if ((fd = mkstemp(path)) == -1 || (fp = fdopen(fd, "w+")) == NULL) {
warn("cannot create temporary file %s", path);
if (fd != -1)
unlink(path);
exit(EX_UNAVAILABLE);
}
umask(omode);
if (fchmod(fd, 0600) == -1) {
unlink(path);
exit(EX_SOFTWARE);
}
for (i = 1; i < argc; i++) {
if (strchr(argv[i], '|') != NULL) {
warnx("%s contains illegal character", argv[i]);
unlink(path);
exit(EX_SOFTWARE);
}
fprintf(fp, "%s%s", i == 1 ? "" : "|", argv[i]);
}
fprintf(fp, "\n");
while ((ch = fgetc(ifile)) != EOF)
if (fputc(ch, fp) == EOF) {
warn("write error");
unlink(path);
exit(EX_UNAVAILABLE);
}
if (ferror(ifile)) {
warn("read error");
unlink(path);
exit(EX_UNAVAILABLE);
}
fclose(fp);
return (EX_TEMPFAIL);
}
开发者ID:lucasad,项目名称:OpenSMTPD,代码行数:57,代码来源:enqueue.c
示例12: queue_envelope_incoming_path
int
queue_envelope_incoming_path(uint64_t evpid, char *buf, size_t len)
{
return bsnprintf(buf, len, "%s/%08x%s/%016" PRIx64,
PATH_INCOMING,
evpid_to_msgid(evpid),
PATH_ENVELOPES,
evpid);
}
开发者ID:clongeau,项目名称:opensmtpd,代码行数:9,代码来源:queue_backend.c
示例13: bsnprintf
void restorePage::fileDoubleClicked(QTreeWidgetItem *item, int column)
{
char cmd[1000];
statusLine->setText("");
if (column == 0) { /* mark/unmark */
mainWin->waitEnter();
if (item->data(0, Qt::UserRole).toBool()) {
bsnprintf(cmd, sizeof(cmd), "unmark \"%s\"", item->text(1).toUtf8().data());
item->setIcon(0, QIcon(QString::fromUtf8(":images/unchecked.png")));
item->setData(0, Qt::UserRole, false);
} else {
bsnprintf(cmd, sizeof(cmd), "mark \"%s\"", item->text(1).toUtf8().data());
item->setIcon(0, QIcon(QString::fromUtf8(":images/check.png")));
item->setData(0, Qt::UserRole, true);
}
m_console->write_dir(m_conn, cmd, false);
if (m_console->read(m_conn) > 0) {
strip_trailing_newline(m_console->msg(m_conn));
statusLine->setText(m_console->msg(m_conn));
}
m_console->displayToPrompt(m_conn);
mainWin->waitExit();
return;
}
/*
* Double clicking other than column 0 means to decend into
* the directory -- or nothing if it is not a directory.
*/
if (item->text(1).endsWith("/")) {
QString fullpath = m_cwd + item->text(1);
QTreeWidgetItem *item = m_dirPaths.value(fullpath);
if (mainWin->m_miscDebug) {
Pmsg1(dbglvl, "%s\n", fullpath.toUtf8().data());
}
if (item) {
directoryWidget->setCurrentItem(item);
} else {
QString msg = QString("DoubleClick else of item column %1 fullpath %2\n")
.arg(column,10)
.arg(fullpath);
if (mainWin->m_miscDebug) Pmsg1(dbglvl, "%s\n", msg.toUtf8().data());
}
}
}
开发者ID:aussendorf,项目名称:bareos,代码行数:44,代码来源:restore.cpp
示例14: main
int
main (int argc, char *const *argv)
{
int verbose = 0;
int status = 0;
int ch, i;
bool display_local = false;
bool display_all = false;
char drive='A';
char buf[16];
setlocale(LC_ALL, "");
bindtextdomain("bacula", LOCALEDIR);
textdomain("bacula");
while ((ch = getopt(argc, argv, "alv?")) != -1) {
switch (ch) {
case 'v':
verbose = 1;
break;
case 'l':
display_local = true;
break;
case 'a':
display_all = true;
break;
case '?':
default:
usage();
}
}
argc -= optind;
argv += optind;
OSDependentInit();
if (argc < 1 && display_all) {
/* Try all letters */
for (drive = 'A'; drive <= 'Z'; drive++) {
bsnprintf(buf, sizeof(buf), "%c:/", drive);
display_drive(buf, display_local, verbose);
}
exit(status);
}
if (argc < 1) {
usage();
}
for (i = 0; i < argc; --argc, ++argv) {
status += display_drive(*argv, display_local, verbose);
}
exit(status);
}
开发者ID:rkorzeniewski,项目名称:bacula,代码行数:55,代码来源:drivetype.c
示例15: bsnprintf
static const char *findex_to_str(int32_t index, char *buf, size_t bufsz)
{
if (index >= 0) {
bsnprintf(buf, bufsz, "<User> %d", index);
return buf;
}
FI_to_ascii(buf, index);
return buf;
}
开发者ID:wisre,项目名称:bareos,代码行数:11,代码来源:record.c
示例16: archive_name
/*
* Edit codes into (Un)MountCommand, Write(First)PartCommand
* %% = %
* %a = archive device name
* %e = erase (set if cannot mount and first part)
* %n = part number
* %m = mount point
* %v = last part name
*
* omsg = edited output message
* imsg = input string containing edit codes (%x)
*
*/
void DEVICE::edit_mount_codes(POOL_MEM &omsg, const char *imsg)
{
const char *p;
const char *str;
char add[20];
POOL_MEM archive_name(PM_FNAME);
omsg.c_str()[0] = 0;
Dmsg1(800, "edit_mount_codes: %s\n", imsg);
for (p=imsg; *p; p++) {
if (*p == '%') {
switch (*++p) {
case '%':
str = "%";
break;
case 'a':
str = dev_name;
break;
case 'e':
if (num_dvd_parts == 0) {
if (truncating || blank_dvd) {
str = "2";
} else {
str = "1";
}
} else {
str = "0";
}
break;
case 'n':
bsnprintf(add, sizeof(add), "%d", part);
str = add;
break;
case 'm':
str = device->mount_point;
break;
default:
add[0] = '%';
add[1] = *p;
add[2] = 0;
str = add;
break;
}
} else {
add[0] = *p;
add[1] = 0;
str = add;
}
Dmsg1(1900, "add_str %s\n", str);
pm_strcat(omsg, (char *)str);
Dmsg1(1800, "omsg=%s\n", omsg.c_str());
}
}
开发者ID:prelegalwonder,项目名称:bacula,代码行数:67,代码来源:dev.c
示例17: time
/*
* ANSI date
* ' 'YYDDD
*/
static char *ansi_date(time_t td, char *buf)
{
struct tm *tm;
if (td == 0) {
td = time(NULL);
}
tm = gmtime(&td);
bsnprintf(buf, 10, " %05d ", 1000 * (tm->tm_year + 1900 - 2000) + tm->tm_yday);
return buf;
}
开发者ID:halgandd,项目名称:bacula,代码行数:15,代码来源:ansi_label.c
示例18: sm_dump
/* SM_DUMP -- Print orphaned buffers (and dump them if BUFDUMP is
* True).
*/
void sm_dump(bool bufdump, bool in_use)
{
struct abufhead *ap;
P(mutex);
ap = (struct abufhead *)abqueue.qnext;
while (ap != (struct abufhead *) &abqueue) {
if ((ap == NULL) ||
(ap->abq.qnext->qprev != (struct b_queue *) ap) ||
(ap->abq.qprev->qnext != (struct b_queue *) ap)) {
Pmsg1(0, _(
"\nOrphaned buffers exist. Dump terminated following\n"
" discovery of bad links in chain of orphaned buffers.\n"
" Buffer address with bad links: %p\n"), ap);
break;
}
if (ap->abfname != NULL) {
char errmsg[500];
uint32_t memsize = ap->ablen - (HEAD_SIZE + 1);
char *cp = ((char *)ap) + HEAD_SIZE;
Pmsg6(0, "%s buffer: %s %d bytes at %p from %s:%d\n",
in_use?"In use":"Orphaned",
my_name, memsize, cp, get_basename(ap->abfname), ap->ablineno);
if (bufdump) {
char buf[20];
unsigned llen = 0;
errmsg[0] = EOS;
while (memsize) {
if (llen >= 16) {
bstrncat(errmsg, "\n", sizeof(errmsg));
llen = 0;
Pmsg1(0, "%s", errmsg);
errmsg[0] = EOS;
}
bsnprintf(buf, sizeof(buf), " %02X",
(*cp++) & 0xFF);
bstrncat(errmsg, buf, sizeof(errmsg));
llen++;
memsize--;
}
Pmsg1(0, "%s\n", errmsg);
}
}
ap = (struct abufhead *) ap->abq.qnext;
}
V(mutex);
}
开发者ID:rkorzeniewski,项目名称:bacula,代码行数:56,代码来源:smartall.c
示例19: bsnprintf
void selectDialog::accept()
{
char cmd[100];
this->hide();
bsnprintf(cmd, sizeof(cmd), "%d", m_index+1);
m_console->write_dir(m_conn, cmd);
m_console->displayToPrompt(m_conn);
this->close();
mainWin->resetFocus();
m_console->displayToPrompt(m_conn);
m_console->notify(m_conn, true);
}
开发者ID:rkorzeniewski,项目名称:bacula,代码行数:13,代码来源:select.cpp
示例20: addrtosymstr
static int addrtosymstr(void *pc, char *buffer, int size)
{
Dl_info info;
Sym *sym;
if (dladdr1(pc, &info, (void **)&sym, RTLD_DL_SYMENT) == 0) {
return (bsnprintf(buffer, size, "[0x%p]", pc));
}
if ((info.dli_fname != NULL && info.dli_sname != NULL) &&
((uintptr_t)pc - (uintptr_t)info.dli_saddr < sym->st_size)) {
return (bsnprintf(buffer, size, "%s'%s+0x%x [0x%p]",
info.dli_fname,
info.dli_sname,
(unsigned long)pc - (unsigned long)info.dli_saddr,
pc));
} else {
return (bsnprintf(buffer, size, "%s'0x%p [0x%p]",
info.dli_fname,
(unsigned long)pc - (unsigned long)info.dli_fbase,
pc));
}
}
开发者ID:pstray,项目名称:bareos,代码行数:23,代码来源:bsys.c
注:本文中的bsnprintf函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论