本文整理汇总了C++中cvtnum函数的典型用法代码示例。如果您正苦于以下问题:C++ cvtnum函数的具体用法?C++ cvtnum怎么用?C++ cvtnum使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cvtnum函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: msync_f
int
msync_f(
int argc,
char **argv)
{
off64_t offset;
ssize_t length;
void *start;
int c, flags = 0;
size_t blocksize, sectsize;
while ((c = getopt(argc, argv, "ais")) != EOF) {
switch (c) {
case 'a':
flags |= MS_ASYNC;
break;
case 'i':
flags |= MS_INVALIDATE;
break;
case 's':
flags |= MS_SYNC;
break;
default:
return command_usage(&msync_cmd);
}
}
if (optind == argc) {
offset = mapping->offset;
length = mapping->length;
} else if (optind == argc - 2) {
init_cvtnum(&blocksize, §size);
offset = cvtnum(blocksize, sectsize, argv[optind]);
if (offset < 0) {
printf(_("non-numeric offset argument -- %s\n"),
argv[optind]);
return 0;
}
optind++;
length = cvtnum(blocksize, sectsize, argv[optind]);
if (length < 0) {
printf(_("non-numeric length argument -- %s\n"),
argv[optind]);
return 0;
}
} else {
return command_usage(&msync_cmd);
}
start = check_mapping_range(mapping, offset, length, 1);
if (!start)
return 0;
if (msync(start, length, flags) < 0)
perror("msync");
return 0;
}
开发者ID:tytso,项目名称:xfsprogs,代码行数:58,代码来源:mmap.c
示例2: discard_f
static int discard_f(int argc, char **argv)
{
struct timeval t1, t2;
int Cflag = 0, qflag = 0;
int c, ret;
int64_t offset;
int count;
while ((c = getopt(argc, argv, "Cq")) != EOF) {
switch (c) {
case 'C':
Cflag = 1;
break;
case 'q':
qflag = 1;
break;
default:
return command_usage(&discard_cmd);
}
}
if (optind != argc - 2) {
return command_usage(&discard_cmd);
}
offset = cvtnum(argv[optind]);
if (offset < 0) {
printf("non-numeric length argument -- %s\n", argv[optind]);
return 0;
}
optind++;
count = cvtnum(argv[optind]);
if (count < 0) {
printf("non-numeric length argument -- %s\n", argv[optind]);
return 0;
}
gettimeofday(&t1, NULL);
ret = bdrv_discard(bs, offset >> BDRV_SECTOR_BITS,
count >> BDRV_SECTOR_BITS);
gettimeofday(&t2, NULL);
if (ret < 0) {
printf("discard failed: %s\n", strerror(-ret));
goto out;
}
/* Finally, report back -- -C gives a parsable format */
if (!qflag) {
t2 = tsub(t2, t1);
print_report("discard", &t2, offset, count, count, 1, Cflag);
}
out:
return 0;
}
开发者ID:AjayMashi,项目名称:x-tier,代码行数:57,代码来源:qemu-io.c
示例3: alloc_f
static int alloc_f(int argc, char **argv)
{
int64_t offset, sector_num;
int nb_sectors, remaining;
char s1[64];
int num, sum_alloc;
int ret;
offset = cvtnum(argv[1]);
if (offset & 0x1ff) {
printf("offset %" PRId64 " is not sector aligned\n",
offset);
return 0;
}
if (argc == 3) {
nb_sectors = cvtnum(argv[2]);
} else {
nb_sectors = 1;
}
remaining = nb_sectors;
sum_alloc = 0;
sector_num = offset >> 9;
while (remaining) {
ret = bdrv_is_allocated(bs, sector_num, remaining, &num);
if (ret < 0) {
printf("is_allocated failed: %s\n", strerror(-ret));
return 0;
}
sector_num += num;
remaining -= num;
if (ret) {
sum_alloc += num;
}
if (num == 0) {
nb_sectors -= remaining;
remaining = 0;
}
}
cvtstr(offset, s1, sizeof(s1));
if (nb_sectors == 1)
printf("sector allocated at offset %s\n", s1);
else
printf("%d/%d sectors allocated at offset %s\n",
sum_alloc, nb_sectors, s1);
return 0;
}
开发者ID:mithleshvrts,项目名称:qemu-kvm-rhel6,代码行数:50,代码来源:qemu-io.c
示例4: aio_write_f
static int aio_write_f(int argc, char **argv)
{
int nr_iov, c;
int pattern = 0xcd;
struct aio_ctx *ctx = g_new0(struct aio_ctx, 1);
while ((c = getopt(argc, argv, "CqP:")) != EOF) {
switch (c) {
case 'C':
ctx->Cflag = 1;
break;
case 'q':
ctx->qflag = 1;
break;
case 'P':
pattern = parse_pattern(optarg);
if (pattern < 0) {
g_free(ctx);
return 0;
}
break;
default:
g_free(ctx);
return command_usage(&aio_write_cmd);
}
}
if (optind > argc - 2) {
g_free(ctx);
return command_usage(&aio_write_cmd);
}
ctx->offset = cvtnum(argv[optind]);
if (ctx->offset < 0) {
printf("non-numeric length argument -- %s\n", argv[optind]);
g_free(ctx);
return 0;
}
optind++;
if (ctx->offset & 0x1ff) {
printf("offset %" PRId64 " is not sector aligned\n",
ctx->offset);
g_free(ctx);
return 0;
}
nr_iov = argc - optind;
ctx->buf = create_iovec(&ctx->qiov, &argv[optind], nr_iov, pattern);
if (ctx->buf == NULL) {
g_free(ctx);
return 0;
}
gettimeofday(&ctx->t1, NULL);
bdrv_aio_writev(bs, ctx->offset >> 9, &ctx->qiov,
ctx->qiov.size >> 9, aio_write_done, ctx);
return 0;
}
开发者ID:AjayMashi,项目名称:x-tier,代码行数:59,代码来源:qemu-io.c
示例5: alloc_f
static int
alloc_f(int argc, char **argv)
{
int64_t offset;
int nb_sectors, remaining;
char s1[64];
int num, sum_alloc;
int ret;
offset = cvtnum(argv[1]);
if (offset & 0x1ff) {
printf("offset %lld is not sector aligned\n",
(long long)offset);
return 0;
}
if (argc == 3)
nb_sectors = cvtnum(argv[2]);
else
nb_sectors = 1;
remaining = nb_sectors;
sum_alloc = 0;
while (remaining) {
ret = bdrv_is_allocated(bs, offset >> 9, nb_sectors, &num);
remaining -= num;
if (ret) {
sum_alloc += num;
}
}
cvtstr(offset, s1, sizeof(s1));
if (nb_sectors == 1)
printf("sector allocated at offset %s\n", s1);
else
printf("%d/%d sectors allocated at offset %s\n",
sum_alloc, nb_sectors, s1);
return 0;
}
开发者ID:bulotus,项目名称:bulotus-qemu-at91sam9263ek,代码行数:40,代码来源:qemu-io.c
示例6: create_iovec
/*
* Parse multiple length statements for vectored I/O, and construct an I/O
* vector matching it.
*/
static void *
create_iovec(QEMUIOVector *qiov, char **argv, int nr_iov, int pattern)
{
size_t *sizes = g_new0(size_t, nr_iov);
size_t count = 0;
void *buf = NULL;
void *p;
int i;
for (i = 0; i < nr_iov; i++) {
char *arg = argv[i];
int64_t len;
len = cvtnum(arg);
if (len < 0) {
printf("non-numeric length argument -- %s\n", arg);
goto fail;
}
/* should be SIZE_T_MAX, but that doesn't exist */
if (len > INT_MAX) {
printf("too large length argument -- %s\n", arg);
goto fail;
}
if (len & 0x1ff) {
printf("length argument %" PRId64
" is not sector aligned\n", len);
goto fail;
}
sizes[i] = len;
count += len;
}
qemu_iovec_init(qiov, nr_iov);
buf = p = qemu_io_alloc(count, pattern);
for (i = 0; i < nr_iov; i++) {
qemu_iovec_add(qiov, p, sizes[i]);
p += sizes[i];
}
fail:
g_free(sizes);
return buf;
}
开发者ID:AjayMashi,项目名称:x-tier,代码行数:52,代码来源:qemu-io.c
示例7: extsize_f
static int
extsize_f(
int argc,
char **argv)
{
size_t blocksize, sectsize;
int c;
recurse_all = recurse_dir = 0;
init_cvtnum(&blocksize, §size);
while ((c = getopt(argc, argv, "DR")) != EOF) {
switch (c) {
case 'D':
recurse_all = 0;
recurse_dir = 1;
break;
case 'R':
recurse_all = 1;
recurse_dir = 0;
break;
default:
return command_usage(&extsize_cmd);
}
}
if (optind < argc) {
extsize = (long)cvtnum(blocksize, sectsize, argv[optind]);
if (extsize < 0) {
printf(_("non-numeric extsize argument -- %s\n"),
argv[optind]);
return 0;
}
} else {
extsize = -1;
}
if (recurse_all || recurse_dir)
nftw(file->name, (extsize >= 0) ?
set_extsize_callback : get_extsize_callback,
100, FTW_PHYS | FTW_MOUNT | FTW_DEPTH);
else if (extsize >= 0)
set_extsize(file->name, file->fd, extsize);
else
get_extsize(file->name, file->fd);
return 0;
}
开发者ID:chandanr,项目名称:xfsprogs-dev,代码行数:46,代码来源:open.c
示例8: truncate_f
static int truncate_f(int argc, char **argv)
{
int64_t offset;
int ret;
offset = cvtnum(argv[1]);
if (offset < 0) {
printf("non-numeric truncate argument -- %s\n", argv[1]);
return 0;
}
ret = bdrv_truncate(bs, offset);
if (ret < 0) {
printf("truncate: %s\n", strerror(-ret));
return 0;
}
return 0;
}
开发者ID:AjayMashi,项目名称:x-tier,代码行数:19,代码来源:qemu-io.c
示例9: mremap_f
int
mremap_f(
int argc,
char **argv)
{
ssize_t new_length;
void *new_addr;
int flags = 0;
int c;
size_t blocksize, sectsize;
while ((c = getopt(argc, argv, "fm")) != EOF) {
switch (c) {
case 'f':
flags = MREMAP_FIXED|MREMAP_MAYMOVE;
break;
case 'm':
flags = MREMAP_MAYMOVE;
break;
default:
return command_usage(&mremap_cmd);
}
}
init_cvtnum(&blocksize, §size);
new_length = cvtnum(blocksize, sectsize, argv[optind]);
if (new_length < 0) {
printf(_("non-numeric offset argument -- %s\n"),
argv[optind]);
return 0;
}
new_addr = mremap(mapping->addr, mapping->length, new_length, flags);
if (new_addr == MAP_FAILED)
perror("mremap");
else {
mapping->addr = new_addr;
mapping->length = new_length;
}
return 0;
}
开发者ID:tytso,项目名称:xfsprogs,代码行数:42,代码来源:mmap.c
示例10: truncate_f
static int
truncate_f(
int argc,
char **argv)
{
off64_t offset;
size_t blocksize, sectsize;
init_cvtnum(&blocksize, §size);
offset = cvtnum(blocksize, sectsize, argv[1]);
if (offset < 0) {
printf(_("non-numeric truncate argument -- %s\n"), argv[1]);
return 0;
}
if (ftruncate64(file->fd, offset) < 0) {
perror("ftruncate");
return 0;
}
return 0;
}
开发者ID:Claruarius,项目名称:stblinux-2.6.37,代码行数:21,代码来源:truncate.c
示例11: pread_f
static int
pread_f(
int argc,
char **argv)
{
size_t bsize;
off64_t offset;
unsigned int zeed = 0;
long long count, total, tmp;
size_t fsblocksize, fssectsize;
struct timeval t1, t2;
char s1[64], s2[64], ts[64];
char *sp;
int Cflag, qflag, uflag, vflag;
int eof = 0, direction = IO_FORWARD;
int c;
Cflag = qflag = uflag = vflag = 0;
init_cvtnum(&fsblocksize, &fssectsize);
bsize = fsblocksize;
while ((c = getopt(argc, argv, "b:BCFRquvV:Z:")) != EOF) {
switch (c) {
case 'b':
tmp = cvtnum(fsblocksize, fssectsize, optarg);
if (tmp < 0) {
printf(_("non-numeric bsize -- %s\n"), optarg);
return 0;
}
bsize = tmp;
break;
case 'C':
Cflag = 1;
break;
case 'F':
direction = IO_FORWARD;
break;
case 'B':
direction = IO_BACKWARD;
break;
case 'R':
direction = IO_RANDOM;
break;
case 'q':
qflag = 1;
break;
case 'u':
uflag = 1;
break;
case 'v':
vflag = 1;
break;
#ifdef HAVE_PREADV
case 'V':
vectors = strtoul(optarg, &sp, 0);
if (!sp || sp == optarg) {
printf(_("non-numeric vector count == %s\n"),
optarg);
return 0;
}
break;
#endif
case 'Z':
zeed = strtoul(optarg, &sp, 0);
if (!sp || sp == optarg) {
printf(_("non-numeric seed -- %s\n"), optarg);
return 0;
}
break;
default:
return command_usage(&pread_cmd);
}
}
if (optind != argc - 2)
return command_usage(&pread_cmd);
offset = cvtnum(fsblocksize, fssectsize, argv[optind]);
if (offset < 0 && (direction & (IO_RANDOM|IO_BACKWARD))) {
eof = -1; /* read from EOF */
} else if (offset < 0) {
printf(_("non-numeric length argument -- %s\n"), argv[optind]);
return 0;
}
optind++;
count = cvtnum(fsblocksize, fssectsize, argv[optind]);
if (count < 0 && (direction & (IO_RANDOM|IO_FORWARD))) {
eof = -1; /* read to EOF */
} else if (count < 0) {
printf(_("non-numeric length argument -- %s\n"), argv[optind]);
return 0;
}
if (alloc_buffer(bsize, uflag, 0xabababab) < 0)
return 0;
gettimeofday(&t1, NULL);
switch (direction) {
case IO_RANDOM:
if (!zeed) /* srandom seed */
zeed = time(NULL);
//.........这里部分代码省略.........
开发者ID:chandanr,项目名称:xfsprogs-dev,代码行数:101,代码来源:pread.c
示例12: evalvar
static char *
evalvar(char *p, int flag)
{
int subtype;
int varflags;
char *var;
const char *val;
int patloc;
int c;
int set;
int special;
int startloc;
int varlen;
int varlenb;
int easy;
int quotes = flag & (EXP_FULL | EXP_CASE);
int record = 0;
varflags = (unsigned char)*p++;
subtype = varflags & VSTYPE;
var = p;
special = 0;
if (! is_name(*p))
special = 1;
p = strchr(p, '=') + 1;
again: /* jump here after setting a variable with ${var=text} */
if (varflags & VSLINENO) {
set = 1;
special = 1;
val = NULL;
} else if (special) {
set = varisset(var, varflags & VSNUL);
val = NULL;
} else {
val = bltinlookup(var, 1);
if (val == NULL || ((varflags & VSNUL) && val[0] == '\0')) {
val = NULL;
set = 0;
} else
set = 1;
}
varlen = 0;
startloc = expdest - stackblock();
if (!set && uflag && *var != '@' && *var != '*') {
switch (subtype) {
case VSNORMAL:
case VSTRIMLEFT:
case VSTRIMLEFTMAX:
case VSTRIMRIGHT:
case VSTRIMRIGHTMAX:
case VSLENGTH:
error("%.*s: parameter not set", (int)(p - var - 1),
var);
}
}
if (set && subtype != VSPLUS) {
/* insert the value of the variable */
if (special) {
if (varflags & VSLINENO)
STPUTBIN(var, p - var - 1, expdest);
else
varvalue(var, varflags & VSQUOTE, subtype, flag);
if (subtype == VSLENGTH) {
varlenb = expdest - stackblock() - startloc;
varlen = varlenb;
if (localeisutf8) {
val = stackblock() + startloc;
for (;val != expdest; val++)
if ((*val & 0xC0) == 0x80)
varlen--;
}
STADJUST(-varlenb, expdest);
}
} else {
if (subtype == VSLENGTH) {
for (;*val; val++)
if (!localeisutf8 ||
(*val & 0xC0) != 0x80)
varlen++;
}
else
strtodest(val, flag, subtype,
varflags & VSQUOTE);
}
}
if (subtype == VSPLUS)
set = ! set;
easy = ((varflags & VSQUOTE) == 0 ||
(*var == '@' && shellparam.nparam != 1));
switch (subtype) {
case VSLENGTH:
expdest = cvtnum(varlen, expdest);
record = 1;
break;
case VSNORMAL:
//.........这里部分代码省略.........
开发者ID:DragonFlyBSD,项目名称:DragonFlyBSD,代码行数:101,代码来源:expand.c
示例13: varvalue
static void
varvalue(const char *name, int quoted, int subtype, int flag)
{
int num;
char *p;
int i;
char sep[2];
char **ap;
switch (*name) {
case '$':
num = rootpid;
break;
case '?':
num = oexitstatus;
break;
case '#':
num = shellparam.nparam;
break;
case '!':
num = backgndpidval();
break;
case '-':
for (i = 0 ; i < NOPTS ; i++) {
if (optlist[i].val)
STPUTC(optlist[i].letter, expdest);
}
return;
case '@':
if (flag & EXP_FULL && quoted) {
for (ap = shellparam.p ; (p = *ap++) != NULL ; ) {
strtodest(p, flag, subtype, quoted);
if (*ap)
STPUTC('\0', expdest);
}
return;
}
/* FALLTHROUGH */
case '*':
if (ifsset())
sep[0] = ifsval()[0];
else
sep[0] = ' ';
sep[1] = '\0';
for (ap = shellparam.p ; (p = *ap++) != NULL ; ) {
strtodest(p, flag, subtype, quoted);
if (!*ap)
break;
if (sep[0])
strtodest(sep, flag, subtype, quoted);
else if (flag & EXP_FULL && !quoted && **ap != '\0')
STPUTC('\0', expdest);
}
return;
default:
if (is_digit(*name)) {
num = atoi(name);
if (num == 0)
p = arg0;
else if (num > 0 && num <= shellparam.nparam)
p = shellparam.p[num - 1];
else
return;
strtodest(p, flag, subtype, quoted);
}
return;
}
expdest = cvtnum(num, expdest);
}
开发者ID:DragonFlyBSD,项目名称:DragonFlyBSD,代码行数:69,代码来源:expand.c
示例14: main
int main(int argc, char **argv)
{
int fd;
char *fname;
int opt;
loff_t length = -2LL;
loff_t offset = 0;
int falloc_mode = 0;
int error;
int tflag = 0;
while ((opt = getopt(argc, argv, "nl:ot")) != -1) {
switch(opt) {
case 'n':
/* do not change filesize */
falloc_mode = FALLOC_FL_KEEP_SIZE;
break;
case 'l':
length = cvtnum(optarg);
break;
case 'o':
offset = cvtnum(optarg);
break;
case 't':
tflag++;
break;
default:
usage();
}
}
if (length == -2LL) {
printf("Error: no length argument specified\n");
usage();
}
if (length <= 0) {
printf("Error: invalid length value specified\n");
usage();
}
if (offset < 0) {
printf("Error: invalid offset value specified\n");
usage();
}
if (tflag && (falloc_mode & FALLOC_FL_KEEP_SIZE)) {
printf("-n and -t options incompatible\n");
usage();
}
if (tflag && offset) {
printf("-n and -o options incompatible\n");
usage();
}
if (optind == argc) {
printf("Error: no filename specified\n");
usage();
}
fname = argv[optind++];
/* Should we create the file if it doesn't already exist? */
fd = open(fname, O_WRONLY|O_LARGEFILE);
if (fd < 0) {
perror("Error opening file");
exit(EXIT_FAILURE);
}
if (tflag)
error = ftruncate(fd, length);
else
error = syscall(SYS_fallocate, fd, falloc_mode, offset, length);
if (error < 0) {
perror("fallocate failed");
exit(EXIT_FAILURE);
}
close(fd);
return 0;
}
开发者ID:ESOS-Lab,项目名称:MOST,代码行数:83,代码来源:fallocate.c
示例15: main
int main(int argc, char **argv)
{
int c;
int fd;
int mode = 0;
int dig = 0;
loff_t length = -2LL;
loff_t offset = 0;
static const struct option longopts[] = {
{ "help", 0, 0, 'h' },
{ "version", 0, 0, 'V' },
{ "keep-size", 0, 0, 'n' },
{ "punch-hole", 0, 0, 'p' },
{ "collapse-range", 0, 0, 'c' },
{ "dig-holes", 0, 0, 'd' },
{ "insert-range", 0, 0, 'i' },
{ "zero-range", 0, 0, 'z' },
{ "offset", 1, 0, 'o' },
{ "length", 1, 0, 'l' },
{ "verbose", 0, 0, 'v' },
{ NULL, 0, 0, 0 }
};
static const ul_excl_t excl[] = { /* rows and cols in in ASCII order */
{ 'c', 'd', 'p', 'z' },
{ 'c', 'n' },
{ 0 }
};
int excl_st[ARRAY_SIZE(excl)] = UL_EXCL_STATUS_INIT;
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
atexit(close_stdout);
while ((c = getopt_long(argc, argv, "hvVncpdizl:o:", longopts, NULL))
!= -1) {
err_exclusive_options(c, longopts, excl, excl_st);
switch(c) {
case 'h':
usage(stdout);
break;
case 'c':
mode |= FALLOC_FL_COLLAPSE_RANGE;
break;
case 'd':
dig = 1;
break;
case 'i':
mode |= FALLOC_FL_INSERT_RANGE;
break;
case 'l':
length = cvtnum(optarg);
break;
case 'n':
mode |= FALLOC_FL_KEEP_SIZE;
break;
case 'o':
offset = cvtnum(optarg);
break;
case 'p':
mode |= FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE;
break;
case 'z':
mode |= FALLOC_FL_ZERO_RANGE;
break;
case 'v':
verbose++;
break;
case 'V':
printf(UTIL_LINUX_VERSION);
return EXIT_SUCCESS;
default:
usage(stderr);
break;
}
}
if (optind == argc)
errx(EXIT_FAILURE, _("no filename specified"));
filename = argv[optind++];
if (optind != argc)
errx(EXIT_FAILURE, _("unexpected number of arguments"));
if (dig) {
/* for --dig-holes the default is analyze all file */
if (length == -2LL)
length = 0;
if (length < 0)
errx(EXIT_FAILURE, _("invalid length value specified"));
} else {
/* it's safer to require the range specification (--length --offset) */
if (length == -2LL)
errx(EXIT_FAILURE, _("no length argument specified"));
if (length <= 0)
//.........这里部分代码省略.........
开发者ID:kerolasa,项目名称:lelux-utiliteetit,代码行数:101,代码来源:fallocate.c
示例16: multiwrite_f
static int
multiwrite_f(int argc, char **argv)
{
struct timeval t1, t2;
int Cflag = 0, qflag = 0;
int c, cnt;
char **buf;
int64_t offset, first_offset = 0;
int total = 0;
int nr_iov;
int nr_reqs;
int pattern = 0xcd;
QEMUIOVector *qiovs;
int i;
BlockRequest *reqs;
while ((c = getopt(argc, argv, "CqP:")) != EOF) {
switch (c) {
case 'C':
Cflag = 1;
break;
case 'q':
qflag = 1;
break;
case 'P':
pattern = parse_pattern(optarg);
if (pattern < 0)
return 0;
break;
default:
return command_usage(&writev_cmd);
}
}
if (optind > argc - 2)
return command_usage(&writev_cmd);
nr_reqs = 1;
for (i = optind; i < argc; i++) {
if (!strcmp(argv[i], ";")) {
nr_reqs++;
}
}
reqs = qemu_malloc(nr_reqs * sizeof(*reqs));
buf = qemu_malloc(nr_reqs * sizeof(*buf));
qiovs = qemu_malloc(nr_reqs * sizeof(*qiovs));
for (i = 0; i < nr_reqs; i++) {
int j;
offset = cvtnum(argv[optind]);
if (offset < 0) {
printf("non-numeric offset argument -- %s\n", argv[optind]);
return 0;
}
optind++;
if (offset & 0x1ff) {
printf("offset %lld is not sector aligned\n",
(long long)offset);
return 0;
}
if (i == 0) {
first_offset = offset;
}
for (j = optind; j < argc; j++) {
if (!strcmp(argv[j], ";")) {
break;
}
}
nr_iov = j - optind;
reqs[i].qiov = &qiovs[i];
buf[i] = create_iovec(reqs[i].qiov, &argv[optind], nr_iov, pattern);
reqs[i].sector = offset >> 9;
reqs[i].nb_sectors = reqs[i].qiov->size >> 9;
optind = j + 1;
offset += reqs[i].qiov->size;
pattern++;
}
gettimeofday(&t1, NULL);
cnt = do_aio_multiwrite(reqs, nr_reqs, &total);
gettimeofday(&t2, NULL);
if (cnt < 0) {
printf("aio_multiwrite failed: %s\n", strerror(-cnt));
goto out;
}
//.........这里部分代码省略.........
开发者ID:qtekfun,项目名称:htcDesire820Kernel,代码行数:101,代码来源:qemu-io.c
示例17: aio_read_f
static int
aio_read_f(int argc, char **argv)
{
int nr_iov, c;
struct aio_ctx *ctx = calloc(1, sizeof(struct aio_ctx));
BlockDriverAIOCB *acb;
while ((c = getopt(argc, argv, "CP:qv")) != EOF) {
switch (c) {
case 'C':
ctx->Cflag = 1;
break;
case 'P':
ctx->Pflag = 1;
ctx->pattern = parse_pattern(optarg);
if (ctx->pattern < 0)
return 0;
break;
case 'q':
ctx->qflag = 1;
break;
case 'v':
ctx->vflag = 1;
break;
default:
free(ctx);
return command_usage(&aio_read_cmd);
}
}
if (optind > argc - 2) {
free(ctx);
return command_usage(&aio_read_cmd);
}
ctx->offset = cvtnum(argv[optind]);
if (ctx->offset < 0) {
printf("non-numeric length argument -- %s\n", argv[optind]);
free(ctx);
return 0;
}
optind++;
if (ctx->offset & 0x1ff) {
printf("offset %" PRId64 " is not sector aligned\n",
ctx->offset);
free(ctx);
return 0;
}
nr_iov = argc - optind;
ctx->buf = create_iovec(&ctx->qiov, &argv[optind], nr_iov, 0xab);
gettimeofday(&ctx->t1, NULL);
acb = bdrv_aio_readv(bs, ctx->offset >> 9, &ctx->qiov,
ctx->qiov.size >> 9, aio_read_done, ctx);
if (!acb) {
free(ctx->buf);
free(ctx);
return -EIO;
}
return 0;
}
开发者ID:ChengyuSong,项目名称:ATrace,代码行数:64,代码来源:qemu-io.c
示例18: readv_f
static int readv_f(int argc, char **argv)
{
struct timeval t1, t2;
int Cflag = 0, qflag = 0, vflag = 0;
int c, cnt;
char *buf;
int64_t offset;
/* Some compilers get confused and warn if this is not initialized. */
int total = 0;
int nr_iov;
QEMUIOVector qiov;
int pattern = 0;
int Pflag = 0;
while ((c = getopt(argc, argv, "CP:qv")) != EOF) {
switch (c) {
case 'C':
Cflag = 1;
break;
case 'P':
Pflag = 1;
pattern = parse_pattern(optarg);
if (pattern < 0) {
return 0;
}
break;
case 'q':
qflag = 1;
break;
case 'v':
vflag = 1;
break;
default:
return command_usage(&readv_cmd);
}
}
if (optind > argc - 2) {
return command_usage(&readv_cmd);
}
offset = cvtnum(argv[optind]);
if (offset < 0) {
printf("non-numeric length argument -- %s\n", argv[optind]);
return 0;
}
optind++;
if (offset & 0x1ff) {
printf("offset %" PRId64 " is not sector aligned\n",
offset);
return 0;
}
nr_iov = argc - optind;
buf = create_iovec(&qiov, &argv[optind], nr_iov, 0xab);
if (buf == NULL) {
return 0;
}
gettimeofday(&t1, NULL);
cnt = do_aio_readv(&qiov, offset, &total);
gettimeofday(&t2, NULL);
if (cnt < 0) {
printf("readv failed: %s\n", strerror(-cnt));
goto out;
}
if (Pflag) {
void *cmp_buf = g_malloc(qiov.size);
memset(cmp_buf, pattern, qiov.size);
if (memcmp(buf, cmp_buf, qiov.size)) {
printf("Pattern verification failed at offset %"
PRId64 ", %zd bytes\n", offset, qiov.size);
}
g_free(cmp_buf);
}
if (qflag) {
goto out;
}
if (vflag) {
dump_buffer(buf, offset, qiov.size);
}
/* Finally, report back -- -C gives a parsable format */
t2 = tsub(t2, t1);
print_report("read", &t2, offset, qiov.size, total, cnt, Cflag);
out:
qemu_iovec_destroy(&qiov);
qemu_io_free(buf);
return 0;
}
开发者ID:AjayMashi,项目名称:x-tier,代码行数:97,代码来源:qemu-io.c
示例19: writev_f
static int writev_f(int argc, char **argv)
{
struct timeval t1, t2;
int Cflag = 0, qflag = 0;
int c, cnt;
char *buf;
int64_t offset;
/* Some compilers get confused and warn if this is not initialized. */
int total = 0;
int nr_iov;
int pattern = 0xcd;
QEMUIOVector qiov;
while ((c = getopt(argc, argv, "CqP:")) != EOF) {
switch (c) {
case 'C':
Cflag = 1;
break;
case 'q':
qflag = 1;
break;
case 'P':
pattern = parse_pattern(optarg);
if (pattern < 0) {
return 0;
}
break;
default:
return command_usage(&writev_cmd);
}
}
if (optind > argc - 2) {
return command_usage(&writev_cmd);
}
offset = cvtnum(argv[optind]);
if (offset < 0) {
printf("non-numeric length argument -- %s\n", argv[optind]);
return 0;
}
optind++;
if (offset & 0x1ff) {
printf("offset %" PRId64 " is not sector aligned\n",
offset);
return 0;
}
nr_iov = argc - optind;
buf = create_iovec(&qiov, &argv[optind], nr_iov, pattern);
if (buf == NULL) {
return 0;
}
gettimeofday(&t1, NULL);
cnt = do_aio_writev(&qiov, offset, &total);
gettimeofday(&t2, NULL);
if (cnt < 0) {
printf("writev failed: %s\n", strerror(-cnt));
goto out;
}
if (qflag) {
goto out;
}
/* Finally, report back -- -C gives a parsable format */
t2 = tsub(t2, t1);
print_report("wrote", &t2, offset, qiov.size, total, cnt, Cflag);
out:
qemu_iovec_destroy(&qiov);
qemu_io_free(buf);
return 0;
}
开发者ID:AjayMashi,项目名称:x-tier,代码行数:76,代码来源:qemu-io.c
示例20: evalvar
STATIC char *
evalvar(shinstance *psh, char *p, int flag)
{
int subtype;
int varflags;
char *var;
char *val;
int patloc;
int c;
int set;
int special;
int startloc;
int varlen;
int apply_ifs;
int quotes = flag & (EXP_FULL | EXP_CASE);
varflags = (unsigned char)*p++;
subtype = varflags & VSTYPE;
var = p;
special = !is_name(*p);
p = strchr(p, '=') + 1;
again: /* jump here after setting a variable with ${var=text} */
if (special) {
set = varisset(psh, var, varflags & VSNUL);
val = NULL;
} else {
val = lookupvar(psh, var);
if (val == NULL || ((varflags & VSNUL) && val[0] == '\0')) {
val = NULL;
set = 0;
} else
set = 1;
}
varlen = 0;
startloc = (int)(psh->expdest - stackblock(psh));
if (!set && uflag(psh)) {
switch (subtype) {
case VSNORMAL:
case VSTRIMLEFT:
case VSTRIMLEFTMAX:
case VSTRIMRIGHT:
case VSTRIMRIGHTMAX:
case VSLENGTH:
error(psh, "%.*s: parameter not set", p - var - 1, var);
/* NOTREACHED */
}
}
if (set && subtype != VSPLUS) {
/* insert the value of the variable */
if (special) {
varvalue(psh, var, varflags & VSQUOTE, subtype, flag);
if (subtype == VSLENGTH) {
varlen = (int)(psh->expdest - stackblock(psh) - startloc);
STADJUST(psh, -varlen, psh->expdest);
}
} else {
char const *syntax = (varflags & VSQUOTE) ? DQSYNTAX
: BASESYNTAX;
if (subtype == VSLENGTH) {
for (;*val; val++)
varlen++;
} else {
while (*val) {
if (quotes && syntax[(int)*val] == CCTL)
STPUTC(psh, CTLESC, psh->expdest);
STPUTC(psh, *val++, psh->expdest);
}
}
}
}
apply_ifs = ((varflags & VSQUOTE) == 0 ||
(*var == '@' && psh->shellparam.nparam != 1));
switch (subtype) {
case VSLENGTH:
psh->expdest = cvtnum(psh, varlen, psh->expdest);
break;
case VSNORMAL:
break;
case VSPLUS:
set = !set;
/* FALLTHROUGH */
case VSMINUS:
if (!set) {
argstr(psh, p, flag | (apply_ifs ? EXP_IFS_SPLIT : 0));
/*
* ${x-a b c} doesn't get split, but removing the
* 'apply_ifs = 0' apparantly breaks ${1+"[email protected]"}..
* ${x-'a b' c} should generate 2 args.
*/
//.........这里部分代码省略.........
开发者ID:egraba,项目名称:kbuild_openbsd,代码行数:101,代码来源:expand.c
注:本文中的cvtnum函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论