本文整理汇总了C++中xsnprintf函数的典型用法代码示例。如果您正苦于以下问题:C++ xsnprintf函数的具体用法?C++ xsnprintf怎么用?C++ xsnprintf使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了xsnprintf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: spu_store_registers
/* Override the to_store_registers routine. */
static void
spu_store_registers (struct target_ops *ops,
struct regcache *regcache, int regno)
{
struct gdbarch *gdbarch = get_regcache_arch (regcache);
struct target_ops *ops_beneath = find_target_beneath (ops);
int spufs_fd;
CORE_ADDR spufs_addr;
/* This version applies only if we're currently in spu_run. */
if (gdbarch_bfd_arch_info (gdbarch)->arch != bfd_arch_spu)
{
while (ops_beneath && !ops_beneath->to_fetch_registers)
ops_beneath = find_target_beneath (ops_beneath);
gdb_assert (ops_beneath);
ops_beneath->to_store_registers (ops_beneath, regcache, regno);
return;
}
/* We must be stopped on a spu_run system call. */
if (!parse_spufs_run (inferior_ptid, &spufs_fd, &spufs_addr))
return;
/* The NPC register is found in PPC memory at SPUFS_ADDR. */
if (regno == -1 || regno == SPU_PC_REGNUM)
{
gdb_byte buf[4];
regcache_raw_collect (regcache, SPU_PC_REGNUM, buf);
target_write (ops_beneath, TARGET_OBJECT_MEMORY, NULL,
buf, spufs_addr, sizeof buf);
}
/* The GPRs are found in the "regs" spufs file. */
if (regno == -1 || (regno >= 0 && regno < SPU_NUM_GPRS))
{
gdb_byte buf[16 * SPU_NUM_GPRS];
char annex[32];
int i;
for (i = 0; i < SPU_NUM_GPRS; i++)
regcache_raw_collect (regcache, i, buf + i*16);
xsnprintf (annex, sizeof annex, "%d/regs", spufs_fd);
target_write (ops_beneath, TARGET_OBJECT_SPU, annex,
buf, 0, sizeof buf);
}
}
示例2: style_tostring
/* Convert style to a string. */
const char *
style_tostring(struct grid_cell *gc)
{
int c, off = 0, comma = 0;
static char s[256];
*s = '\0';
if (gc->fg != 8 || gc->flags & GRID_FLAG_FG256) {
if (gc->flags & GRID_FLAG_FG256)
c = gc->fg | 0x100;
else
c = gc->fg;
off += xsnprintf(s, sizeof s, "fg=%s", colour_tostring(c));
comma = 1;
}
if (gc->bg != 8 || gc->flags & GRID_FLAG_BG256) {
if (gc->flags & GRID_FLAG_BG256)
c = gc->bg | 0x100;
else
c = gc->bg;
off += xsnprintf(s + off, sizeof s - off, "%sbg=%s",
comma ? "," : "", colour_tostring(c));
comma = 1;
}
if (gc->attr != 0 && gc->attr != GRID_ATTR_CHARSET) {
xsnprintf(s + off, sizeof s - off, "%s%s",
comma ? "," : "", attributes_tostring(gc->attr));
}
if (*s == '\0')
return ("default");
return (s);
}
示例3: safe_strerror
char *
safe_strerror (int errnum)
{
char *msg;
msg = strerror (errnum);
if (msg == NULL)
{
static char buf[32];
xsnprintf (buf, sizeof buf, "(undocumented errno %d)", errnum);
msg = buf;
}
return (msg);
}
示例4: server_fill_environ
void
server_fill_environ(struct session *s, struct environ *env)
{
char tmuxvar[MAXPATHLEN], *term;
u_int idx;
if (session_index(s, &idx) != 0)
fatalx("session not found");
xsnprintf(tmuxvar, sizeof tmuxvar,
"%s,%ld,%u", socket_path, (long) getpid(), idx);
environ_set(env, "TMUX", tmuxvar);
term = options_get_string(&s->options, "default-terminal");
environ_set(env, "TERM", term);
}
示例5: send_sideband
/*
* fd is connected to the remote side; send the sideband data
* over multiplexed packet stream.
*/
void send_sideband(int fd, int band, const char *data, ssize_t sz, int packet_max)
{
const char *p = data;
while (sz) {
unsigned n;
char hdr[5];
n = sz;
if (packet_max - 5 < n)
n = packet_max - 5;
if (0 <= band) {
xsnprintf(hdr, sizeof(hdr), "%04x", n + 5);
hdr[4] = band;
write_or_die(fd, hdr, 5);
} else {
xsnprintf(hdr, sizeof(hdr), "%04x", n + 4);
write_or_die(fd, hdr, 4);
}
write_or_die(fd, p, n);
p += n;
sz -= n;
}
}
示例6: makesocketpath
char *
makesocketpath(const char *label)
{
char base[PATH_MAX], realbase[PATH_MAX], *path, *s;
struct stat sb;
u_int uid;
uid = getuid();
if ((s = getenv("TMUX_TMPDIR")) != NULL && *s != '\0')
xsnprintf(base, sizeof base, "%s/", s);
else if ((s = getenv("TMPDIR")) != NULL && *s != '\0')
xsnprintf(base, sizeof base, "%s/tmux-%u", s, uid);
else
xsnprintf(base, sizeof base, "%s/tmux-%u", _PATH_TMP, uid);
if (mkdir(base, S_IRWXU) != 0 && errno != EEXIST)
return (NULL);
if (lstat(base, &sb) != 0)
return (NULL);
if (!S_ISDIR(sb.st_mode)) {
errno = ENOTDIR;
return (NULL);
}
if (sb.st_uid != uid || (!S_ISDIR(sb.st_mode) &&
sb.st_mode & (S_IRWXG|S_IRWXO)) != 0) {
errno = EACCES;
return (NULL);
}
if (realpath(base, realbase) == NULL)
strlcpy(realbase, base, sizeof realbase);
xasprintf(&path, "%s/%s", realbase, label);
return (path);
}
示例7: set_variant_num_fprs
/* Indicate that the variant VAR has NUM_FPRS floating-point
registers, and fill in the names array appropriately. */
static void
set_variant_num_fprs (struct gdbarch_tdep *var, int num_fprs)
{
int r;
var->num_fprs = num_fprs;
for (r = 0; r < num_fprs; ++r)
{
char buf[20];
xsnprintf (buf, sizeof (buf), "fr%d", r);
var->register_names[first_fpr_regnum + r] = xstrdup (buf);
}
}
示例8: queue_directory
static void queue_directory(const unsigned char *sha1,
struct strbuf *base, const char *filename,
unsigned mode, int stage, struct archiver_context *c)
{
struct directory *d;
size_t len = st_add4(base->len, 1, strlen(filename), 1);
d = xmalloc(st_add(sizeof(*d), len));
d->up = c->bottom;
d->baselen = base->len;
d->mode = mode;
d->stage = stage;
c->bottom = d;
d->len = xsnprintf(d->path, len, "%.*s%s/", (int)base->len, base->buf, filename);
hashcpy(d->oid.hash, sha1);
}
示例9: cvs_server_static_directory
void
cvs_server_static_directory(char *data)
{
FILE *fp;
char fpath[MAXPATHLEN];
(void)xsnprintf(fpath, MAXPATHLEN, "%s/%s",
server_currentdir, CVS_PATH_STATICENTRIES);
if ((fp = fopen(fpath, "w+")) == NULL) {
cvs_log(LP_ERRNO, "%s", fpath);
return;
}
(void)fclose(fp);
}
示例10: colour_tostring
/* Convert colour to a string. */
const char *
colour_tostring(int c)
{
static char s[32];
if (c & 0x100) {
xsnprintf(s, sizeof s, "colour%u", c & ~0x100);
return (s);
}
switch (c) {
case 0:
return ("black");
case 1:
return ("red");
case 2:
return ("green");
case 3:
return ("yellow");
case 4:
return ("blue");
case 5:
return ("magenta");
case 6:
return ("cyan");
case 7:
return ("white");
case 8:
return ("default");
case 90:
return ("brightblack");
case 91:
return ("brightred");
case 92:
return ("brightgreen");
case 93:
return ("brightyellow");
case 94:
return ("brightblue");
case 95:
return ("brightmagenta");
case 96:
return ("brightcyan");
case 97:
return ("brightwhite");
}
return (NULL);
}
示例11: winansi_init
void winansi_init(void)
{
int con1, con2;
char name[32];
/* check if either stdout or stderr is a console output screen buffer */
con1 = is_console(1);
con2 = is_console(2);
/* Also compute console bit for fd 0 even though we don't need the result here. */
is_console(0);
if (!con1 && !con2) {
#ifdef DETECT_MSYS_TTY
/* check if stdin / stdout / stderr are MSYS2 pty pipes */
detect_msys_tty(0);
detect_msys_tty(1);
detect_msys_tty(2);
#endif
return;
}
/* create a named pipe to communicate with the console thread */
xsnprintf(name, sizeof(name), "\\\\.\\pipe\\winansi%lu", GetCurrentProcessId());
hwrite = CreateNamedPipe(name, PIPE_ACCESS_OUTBOUND,
PIPE_TYPE_BYTE | PIPE_WAIT, 1, BUFFER_SIZE, 0, 0, NULL);
if (hwrite == INVALID_HANDLE_VALUE)
die_lasterr("CreateNamedPipe failed");
hread = CreateFile(name, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
if (hread == INVALID_HANDLE_VALUE)
die_lasterr("CreateFile for named pipe failed");
/* start console spool thread on the pipe's read end */
hthread = CreateThread(NULL, 0, console_thread, NULL, 0, NULL);
if (hthread == INVALID_HANDLE_VALUE)
die_lasterr("CreateThread(console_thread) failed");
/* schedule cleanup routine */
if (atexit(winansi_exit))
die_errno("atexit(winansi_exit) failed");
/* redirect stdout / stderr to the pipe */
if (con1)
hconsole1 = swap_osfhnd(1, duplicate_handle(hwrite));
if (con2)
hconsole2 = swap_osfhnd(2, duplicate_handle(hwrite));
}
示例12: cmd_print
size_t
cmd_print(struct cmd *cmd, char *buf, size_t len)
{
size_t off, used;
off = xsnprintf(buf, len, "%s ", cmd->entry->name);
if (off + 1 < len) {
used = args_print(cmd->args, buf + off, len - off - 1);
if (used == 0)
off--;
else
off += used;
buf[off] = '\0';
}
return (off);
}
示例13: cli_field_int
static void
cli_field_int (struct ui_out *uiout, int fldno, int width,
enum ui_align alignment,
const char *fldname, int value)
{
char buffer[20]; /* FIXME: how many chars long a %d can become? */
cli_out_data *data = ui_out_data (uiout);
if (data->suppress_output)
return;
xsnprintf (buffer, sizeof (buffer), "%d", value);
/* Always go through the function pointer (virtual function call).
We may have been extended. */
uo_field_string (uiout, fldno, width, alignment, fldname, buffer);
}
示例14: report_message
static void report_message(const char *prefix, const char *err, va_list params)
{
int sz;
char msg[4096];
sz = xsnprintf(msg, sizeof(msg), "%s", prefix);
sz += vsnprintf(msg + sz, sizeof(msg) - sz, err, params);
if (sz > (sizeof(msg) - 1))
sz = sizeof(msg) - 1;
msg[sz++] = '\n';
if (use_sideband)
send_sideband(1, 2, msg, sz, use_sideband);
else
xwrite(2, msg, sz);
}
示例15: union_search
int
union_search(mnt_map *m, char *map, char *key, char **pval, time_t *tp)
{
char *mapd = xstrdup(map + UNION_PREFLEN);
char **v = strsplit(mapd, ':', '\"');
char **p;
size_t l;
for (p = v; p[1]; p++) ;
l = strlen(*p) + 5;
*pval = xmalloc(l);
xsnprintf(*pval, l, "fs:=%s", *p);
XFREE(mapd);
XFREE(v);
return 0;
}