本文整理汇总了C++中INT_BUFSIZE_BOUND函数的典型用法代码示例。如果您正苦于以下问题:C++ INT_BUFSIZE_BOUND函数的具体用法?C++ INT_BUFSIZE_BOUND怎么用?C++ INT_BUFSIZE_BOUND使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了INT_BUFSIZE_BOUND函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: human_time
static char * ATTRIBUTE_WARN_UNUSED_RESULT
human_time (struct timespec t)
{
/* STR must be at least this big, either because localtime_rz fails,
or because the time zone is truly outlandish so that %z expands
to a long string. */
enum { intmax_bufsize = INT_BUFSIZE_BOUND (intmax_t) };
static char str[intmax_bufsize
+ INT_STRLEN_BOUND (int) /* YYYY */
+ 1 /* because YYYY might equal INT_MAX + 1900 */
+ sizeof "-MM-DD HH:MM:SS.NNNNNNNNN +"];
static timezone_t tz;
if (!tz)
tz = tzalloc (getenv ("TZ"));
struct tm tm;
int ns = t.tv_nsec;
if (localtime_rz (tz, &t.tv_sec, &tm))
nstrftime (str, sizeof str, "%Y-%m-%d %H:%M:%S.%N %z", &tm, tz, ns);
else
{
char secbuf[INT_BUFSIZE_BOUND (intmax_t)];
sprintf (str, "%s.%09d", timetostr (t.tv_sec, secbuf), ns);
}
return str;
}
示例2: main
int
main (int argc, char **argv)
{
char limit[1 + MAX (INT_BUFSIZE_BOUND (intmax_t),
INT_BUFSIZE_BOUND (uintmax_t))];
initialize_main (&argc, &argv);
set_program_name (argv[0]);
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
initialize_exit_failure (EXIT_FAILURE);
atexit (close_stdout);
parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, VERSION,
usage, AUTHORS, (char const *) NULL);
#define print_int(TYPE) \
sprintf (limit + 1, "%"PRIuMAX, (uintmax_t) TYPE##_MAX); \
printf (#TYPE"_MAX=%s\n", limit + 1); \
printf (#TYPE"_OFLOW=%s\n", decimal_absval_add_one (limit)); \
if (TYPE##_MIN) \
{ \
sprintf (limit + 1, "%"PRIdMAX, (intmax_t) TYPE##_MIN); \
printf (#TYPE"_MIN=%s\n", limit + 1); \
printf (#TYPE"_UFLOW=%s\n", decimal_absval_add_one (limit)); \
}
#define print_float(TYPE) \
printf (#TYPE"_MIN=%Le\n", (long double)TYPE##_MIN); \
printf (#TYPE"_MAX=%Le\n", (long double)TYPE##_MAX);
/* Variable sized ints */
print_int (CHAR);
print_int (SCHAR);
print_int (UCHAR);
print_int (SHRT);
print_int (INT);
print_int (UINT);
print_int (LONG);
print_int (ULONG);
print_int (SIZE);
print_int (SSIZE);
print_int (TIME_T);
print_int (UID_T);
print_int (GID_T);
print_int (PID_T);
print_int (OFF_T);
print_int (INTMAX);
print_int (UINTMAX);
/* Variable sized floats */
print_float (FLT);
print_float (DBL);
print_float (LDBL);
}
示例3: mpz_get_str
static char *
mpz_get_str (char const *str, int base, mpz_t z)
{
char buf[INT_BUFSIZE_BOUND (intmax_t)];
(void) str; (void) base;
return xstrdup (imaxtostr (z[0], buf));
}
示例4: mpz_out_str
static int
mpz_out_str (FILE *stream, int base, mpz_t z)
{
char buf[INT_BUFSIZE_BOUND (intmax_t)];
(void) base;
return fputs (imaxtostr (z[0], buf), stream) != EOF;
}
示例5: check_sparse_region
static bool
check_sparse_region (struct tar_sparse_file *file, off_t beg, off_t end)
{
if (!lseek_or_error (file, beg))
return false;
while (beg < end)
{
size_t bytes_read;
size_t rdsize = BLOCKSIZE < end - beg ? BLOCKSIZE : end - beg;
char diff_buffer[BLOCKSIZE];
bytes_read = safe_read (file->fd, diff_buffer, rdsize);
if (bytes_read == SAFE_READ_ERROR)
{
read_diag_details (file->stat_info->orig_file_name,
beg,
rdsize);
return false;
}
if (!zero_block_p (diff_buffer, bytes_read))
{
char begbuf[INT_BUFSIZE_BOUND (off_t)];
report_difference (file->stat_info,
_("File fragment at %s is not a hole"),
offtostr (beg, begbuf));
return false;
}
beg += bytes_read;
}
return true;
}
示例6: virPidFileWritePath
int virPidFileWritePath(const char *pidfile,
pid_t pid)
{
int rc;
int fd;
char pidstr[INT_BUFSIZE_BOUND(pid)];
if ((fd = open(pidfile,
O_WRONLY | O_CREAT | O_TRUNC,
S_IRUSR | S_IWUSR)) < 0) {
rc = -errno;
goto cleanup;
}
snprintf(pidstr, sizeof(pidstr), "%lld", (long long) pid);
if (safewrite(fd, pidstr, strlen(pidstr)) < 0) {
rc = -errno;
VIR_FORCE_CLOSE(fd);
goto cleanup;
}
rc = 0;
cleanup:
if (VIR_CLOSE(fd) < 0)
rc = -errno;
return rc;
}
示例7: read_negative_num
static void
read_negative_num (FILE *fp, intmax_t min_val, intmax_t *pval)
{
int c;
size_t i;
char buf[INT_BUFSIZE_BOUND (intmax_t)];
char *ep;
buf[0] = '-';
for (i = 1; ISDIGIT (c = getc (fp)); i++)
{
if (i == sizeof buf - 1)
FATAL_ERROR ((0, 0, _("Field too long while reading snapshot file")));
buf[i] = c;
}
if (c < 0)
{
if (ferror (fp))
FATAL_ERROR ((0, errno, _("Read error in snapshot file")));
else
FATAL_ERROR ((0, 0, _("Unexpected EOF in snapshot file")));
}
buf[i] = 0;
errno = 0;
*pval = strtoimax (buf, &ep, 10);
if (c || errno || *pval < min_val)
FATAL_ERROR ((0, errno, _("Unexpected field value in snapshot file")));
}
示例8: read_incr_db_2
/* Read incremental snapshot format 2 */
static void
read_incr_db_2 (void)
{
struct obstack stk;
char offbuf[INT_BUFSIZE_BOUND (off_t)];
obstack_init (&stk);
read_timespec (listed_incremental_stream, &newer_mtime_option);
for (;;)
{
intmax_t i;
struct timespec mtime;
dev_t dev;
ino_t ino;
bool nfs;
char *name;
char *content;
size_t s;
if (! read_num (listed_incremental_stream, "nfs", 0, 1, &i))
return; /* Normal return */
nfs = i;
read_timespec (listed_incremental_stream, &mtime);
if (! read_num (listed_incremental_stream, "dev",
TYPE_MINIMUM (dev_t), TYPE_MAXIMUM (dev_t), &i))
break;
dev = i;
if (! read_num (listed_incremental_stream, "ino",
TYPE_MINIMUM (ino_t), TYPE_MAXIMUM (ino_t), &i))
break;
ino = i;
if (read_obstack (listed_incremental_stream, &stk, &s))
break;
name = obstack_finish (&stk);
while (read_obstack (listed_incremental_stream, &stk, &s) == 0 && s > 1)
;
if (getc (listed_incremental_stream) != 0)
FATAL_ERROR ((0, 0, _("%s: byte %s: %s"),
quotearg_colon (listed_incremental_option),
offtostr (ftello (listed_incremental_stream), offbuf),
_("Missing record terminator")));
content = obstack_finish (&stk);
note_directory (name, mtime, dev, ino, nfs, false, content);
obstack_free (&stk, content);
}
FATAL_ERROR ((0, 0, "%s: %s",
quotearg_colon (listed_incremental_option),
_("Unexpected EOF in snapshot file")));
}
示例9: uid_to_name
extern char *
uid_to_name (uid_t uid)
{
char buf[INT_BUFSIZE_BOUND (intmax_t)];
struct passwd *pwd = getpwuid (uid);
return xstrdup (pwd ? pwd->pw_name
: TYPE_SIGNED (uid_t) ? imaxtostr (uid, buf)
: umaxtostr (uid, buf));
}
示例10: gid_to_name
extern char *
gid_to_name (gid_t gid)
{
char buf[INT_BUFSIZE_BOUND (intmax_t)];
struct group *grp = getgrgid (gid);
return xstrdup (grp ? grp->gr_name
: TYPE_SIGNED (gid_t) ? imaxtostr (gid, buf)
: umaxtostr (gid, buf));
}
示例11: human_time
static char * ATTRIBUTE_WARN_UNUSED_RESULT
human_time (struct timespec t)
{
static char str[MAX (INT_BUFSIZE_BOUND (intmax_t),
(INT_STRLEN_BOUND (int) /* YYYY */
+ 1 /* because YYYY might equal INT_MAX + 1900 */
+ sizeof "-MM-DD HH:MM:SS.NNNNNNNNN +ZZZZ"))];
struct tm const *tm = localtime (&t.tv_sec);
if (tm == NULL)
return timetostr (t.tv_sec, str);
nstrftime (str, sizeof str, "%Y-%m-%d %H:%M:%S.%N %z", tm, 0, t.tv_nsec);
return str;
}
示例12: out_of_range_header
static void
out_of_range_header (char const *keyword, char const *value,
intmax_t minval, uintmax_t maxval)
{
char minval_buf[INT_BUFSIZE_BOUND (intmax_t)];
char maxval_buf[UINTMAX_STRSIZE_BOUND];
char *minval_string = imaxtostr (minval, minval_buf);
char *maxval_string = umaxtostr (maxval, maxval_buf);
/* TRANSLATORS: The first %s is the pax extended header keyword
(atime, gid, etc.). */
ERROR ((0, 0, _("Extended header %s=%s is out of range %s..%s"),
keyword, value, minval_string, maxval_string));
}
示例13: virNetDevBridgeSet
/*
* Bridge parameters can be set via sysfs on newish kernels,
* or by ioctl on older kernels. Perhaps we could just use
* ioctl for every kernel, but its not clear what the long
* term lifespan of the ioctl interface is...
*/
static int virNetDevBridgeSet(const char *brname,
const char *paramname, /* sysfs param name */
unsigned long value, /* new value */
int fd, /* control socket */
struct ifreq *ifr) /* pre-filled bridge name */
{
char *path = NULL;
int ret = -1;
if (virAsprintf(&path, "%s/%s/bridge/%s", SYSFS_NET_DIR, brname, paramname) < 0) {
virReportOOMError();
return -1;
}
if (virFileExists(path)) {
char valuestr[INT_BUFSIZE_BOUND(value)];
snprintf(valuestr, sizeof(valuestr), "%lu", value);
if (virFileWriteStr(path, valuestr, 0) < 0) {
virReportSystemError(errno,
_("Unable to set bridge %s %s"), brname, paramname);
goto cleanup;
}
} else {
unsigned long paramid;
if (STREQ(paramname, "stp_state")) {
paramid = BRCTL_SET_BRIDGE_STP_STATE;
} else if (STREQ(paramname, "forward_delay")) {
paramid = BRCTL_SET_BRIDGE_FORWARD_DELAY;
} else {
virReportSystemError(EINVAL,
_("Unable to set bridge %s %s"), brname, paramname);
goto cleanup;
}
unsigned long args[] = { paramid, value, 0, 0 };
ifr->ifr_data = (char*)&args;
if (ioctl(fd, SIOCDEVPRIVATE, ifr) < 0) {
virReportSystemError(errno,
_("Unable to set bridge %s %s"), brname, paramname);
goto cleanup;
}
}
ret = 0;
cleanup:
VIR_FREE(path);
return ret;
}
示例14: virNodeGetCpuValue
/* Return the positive decimal contents of the given
* DIR/cpu%u/FILE, or -1 on error. If MISSING_OK and the
* file could not be found, return 1 instead of an error; this is
* because some machines cannot hot-unplug cpu0, or because
* hot-unplugging is disabled. */
static int
virNodeGetCpuValue(const char *dir, unsigned int cpu, const char *file,
bool missing_ok)
{
char *path;
FILE *pathfp;
int value = -1;
char value_str[INT_BUFSIZE_BOUND(value)];
char *tmp;
if (virAsprintf(&path, "%s/cpu%u/%s", dir, cpu, file) < 0) {
virReportOOMError();
return -1;
}
pathfp = fopen(path, "r");
if (pathfp == NULL) {
if (missing_ok && errno == ENOENT)
value = 1;
else
virReportSystemError(errno, _("cannot open %s"), path);
goto cleanup;
}
if (fgets(value_str, sizeof(value_str), pathfp) == NULL) {
virReportSystemError(errno, _("cannot read from %s"), path);
goto cleanup;
}
if (virStrToLong_i(value_str, &tmp, 10, &value) < 0) {
nodeReportError(VIR_ERR_INTERNAL_ERROR,
_("could not convert '%s' to an integer"),
value_str);
goto cleanup;
}
cleanup:
VIR_FORCE_FCLOSE(pathfp);
VIR_FREE(path);
return value;
}
示例15: virPidFileReadPath
int virPidFileReadPath(const char *path,
pid_t *pid)
{
int fd;
int rc;
ssize_t bytes;
long long pid_value = 0;
char pidstr[INT_BUFSIZE_BOUND(pid_value)];
char *endptr = NULL;
*pid = 0;
if ((fd = open(path, O_RDONLY)) < 0) {
rc = -errno;
goto cleanup;
}
bytes = saferead(fd, pidstr, sizeof(pidstr));
if (bytes < 0) {
rc = -errno;
VIR_FORCE_CLOSE(fd);
goto cleanup;
}
pidstr[bytes] = '\0';
if (virStrToLong_ll(pidstr, &endptr, 10, &pid_value) < 0 ||
!(*endptr == '\0' || c_isspace(*endptr)) ||
(pid_t) pid_value != pid_value) {
rc = -1;
goto cleanup;
}
*pid = pid_value;
rc = 0;
cleanup:
if (VIR_CLOSE(fd) < 0)
rc = -errno;
return rc;
}