这篇教程C++ warnx函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中warnx函数的典型用法代码示例。如果您正苦于以下问题:C++ warnx函数的具体用法?C++ warnx怎么用?C++ warnx使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了warnx函数的24个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: mainintmain(int argc, char *argv[]){ size_t len, lineno = 0; char *line, *eptr, *longopt, *ptr, *optstring = NULL, *result = NULL; char buf[1024]; char *args[128]; char arg[256]; int nargs = -1; int c; int nlongopts = 0; int maxnlongopts = 0; int *longopt_flags = NULL; struct option *longopts = NULL; while ((line = fparseln(stdin, &len, &lineno, NULL, 0)) != NULL) { if (strncmp(line, "optstring:", 10) == 0) { if (optstring) free(optstring); optstring = strtok(&line[11], WS); if (optstring == NULL) errx(1, "missing optstring at line %ld", (unsigned long)lineno); optstring = strdup(optstring); } else if (strncmp(line, "longopts:", 9) == 0) { if (longopts) { int i; for (i = 0; i < nlongopts; i++) if (longopts[i].name != NULL) free(__UNCONST(longopts[i].name)); free(longopts); } if (longopt_flags) free(longopt_flags); nlongopts = 0; ptr = strtok(&line[10], WS); if (ptr == NULL) errx(1, "missing longopts at line %ld", (unsigned long)lineno); maxnlongopts = strtoul(ptr, &eptr, 10); if (*eptr != '/0') warnx("garbage in longopts at line %ld", (unsigned long)lineno); maxnlongopts++; /* space for trailer */ longopts = (struct option *)calloc(sizeof(struct option), maxnlongopts); if (longopts == NULL) err(1, "calloc"); longopt_flags = (int *)calloc(sizeof(int), maxnlongopts); if (longopt_flags == NULL) err(1, "calloc"); } else if (strncmp(line, "longopt:", 8) == 0) { if (longopts == NULL) errx(1, "longopt: without longopts at line %ld", (unsigned long)lineno); if (nlongopts >= maxnlongopts) errx(1, "longopt: too many options at line %ld", (unsigned long)lineno); /* name */ ptr = &line[9]; SKIPWS(ptr); longopt = strsep(&ptr, ","); if (longopt == NULL) errx(1, "missing longopt at line %ld", (unsigned long)lineno); longopts[nlongopts].name = strdup(longopt); /* has_arg */ SKIPWS(ptr); longopt = strsep(&ptr, ","); if (*longopt != '/0') { if (strncmp(longopt, "0", 1) == 0 || strncmp(longopt, "no_argument", 2) == 0) longopts[nlongopts].has_arg = no_argument; else if (strncmp(longopt, "1", 1) == 0 || strncmp(longopt, "required_argument", 8) == 0) longopts[nlongopts].has_arg = required_argument; else if (strncmp(longopt, "2", 1) == 0 || strncmp(longopt, "optional_argument", 8) == 0) longopts[nlongopts].has_arg = optional_argument; else errx(1, "unknown has_arg %s at line %ld", longopt, (unsigned long)lineno); } /* flag */ SKIPWS(ptr); longopt = strsep(&ptr, ","); if (*longopt != '/0' && strncmp(longopt, "NULL", 4) != 0) longopts[nlongopts].flag = &longopt_flags[nlongopts]; /* val */ SKIPWS(ptr); longopt = strsep(&ptr, ","); if (*longopt == '/0') errx(1, "missing val at line %ld", (unsigned long)lineno); if (*longopt != '/'') { longopts[nlongopts].val = (int)strtoul(longopt, &eptr, 10); if (*eptr != '/0')//.........这里部分代码省略.........
开发者ID:2asoft,项目名称:freebsd,代码行数:101,
示例2: mainintmain(int argc __unused, char *argv[]){ long cols, i, inc, j, margin, nstops, stops[NSTOPS]; const char *cr, *ct, *st, *ML; char area[1024], *ap, *arg, *end; setlocale(LC_ALL, ""); inc = 8; margin = 0; nstops = -1; while ((arg = *++argv) != NULL && (*arg == '-' || *arg == '+')) { if (*arg == '+') { /* +m[n] or +[n] */ if (*++arg == 'm') arg++; if (*arg != '/0') { errno = 0; margin = strtol(arg, &end, 10); if (errno != 0 || *end != '/0' || margin < 0) errx(1, "%s: invalid margin width", arg); } else margin = 10; } else if (isdigit(arg[1])) { /* -n */ errno = 0; inc = strtol(arg + 1, &end, 10); if (errno != 0 || *end != '/0' || inc < 0) errx(1, "%s: invalid increment", arg + 1); } else if (arg[1] == 'T') { /* -Ttype or -T type */ if (arg[2] != '/0') setenv("TERM", arg + 2, 1); else { if ((arg = *++argv) == NULL) usage(); setenv("TERM", arg, 1); } } else if (arg[1] == '-') { arg = *++argv; break; } else { /* Predefined format */ for (i = 0; i < (int)NELEMS(formats); i++) if (strcmp(formats[i].name, arg + 1) == 0) break; if (i == NELEMS(formats)) usage(); for (j = nstops = 0; j < NSTOPS && formats[i].stops[j] != 0; j++) stops[nstops++] = formats[i].stops[j]; } } if (arg != NULL) { if (nstops != -1) usage(); gettabs(arg, stops, &nstops); } /* Initialise terminal, get the strings we need */ setupterm(NULL, 1, NULL); ap = area; if ((ct = tgetstr("ct", &ap)) == NULL) errx(1, "terminal cannot clear tabs"); if ((st = tgetstr("st", &ap)) == NULL) errx(1, "terminal cannot set tabs"); if ((cr = tgetstr("cr", &ap)) == NULL) cr = "/r"; ML = tgetstr("ML", &ap); cols = ttywidth(); /* Clear all tabs. */ putp(cr); putp(ct); /* * Set soft margin. * XXX Does this actually work? */ if (ML != NULL) { printf("%*s", (int)margin, ""); putp(ML); } else if (margin != 0) warnx("terminal cannot set left margin"); /* Optionally output new tab stops. */ if (nstops >= 0) { printf("%*s", (int)stops[0] - 1, ""); putp(st); for (i = 1; i < nstops; i++) { printf("%*s", (int)(stops[i] - stops[i - 1]), ""); putp(st); } } else if (inc > 0) { for (i = 0; i < cols / inc; i++) { putp(st); printf("%*s", (int)inc, "");//.........这里部分代码省略.........
开发者ID:2asoft,项目名称:freebsd,代码行数:101,
示例3: mainintmain(int argc, char **argv){ char *font, *type, *termmode; const char *opts; int dumpmod, dumpopt, opt; int reterr; vt4_mode = is_vt4(); init(); info.size = sizeof(info); if (ioctl(0, CONS_GETINFO, &info) == -1) err(1, "must be on a virtual console"); dumpmod = 0; dumpopt = DUMP_FBF; termmode = NULL; if (vt4_mode) opts = "b:Cc:fg:h:Hi:M:m:pPr:S:s:T:t:x"; else opts = "b:Cc:dfg:h:Hi:l:LM:m:pPr:S:s:T:t:x"; while ((opt = getopt(argc, argv, opts)) != -1) switch(opt) { case 'b': set_border_color(optarg); break; case 'C': clear_history(); break; case 'c': set_cursor_type(optarg); break; case 'd': if (vt4_mode) break; print_scrnmap(); break; case 'f': optarg = nextarg(argc, argv, &optind, 'f', 0); if (optarg != NULL) { font = nextarg(argc, argv, &optind, 'f', 0); if (font == NULL) { type = NULL; font = optarg; } else type = optarg; load_font(type, font); } else { if (!vt4_mode) usage(); /* Switch syscons to ROM? */ load_default_vt4font(); } break; case 'g': if (sscanf(optarg, "%dx%d", &vesa_cols, &vesa_rows) != 2) { revert(); warnx("incorrect geometry: %s", optarg); usage(); } break; case 'h': set_history(optarg); break; case 'H': dumpopt = DUMP_ALL; break; case 'i': show_info(optarg); break; case 'l': if (vt4_mode) break; load_scrnmap(optarg); break; case 'L': if (vt4_mode) break; load_default_scrnmap(); break; case 'M': set_mouse_char(optarg); break; case 'm': set_mouse(optarg); break; case 'p': dumpmod = DUMP_FMT_RAW; break; case 'P': dumpmod = DUMP_FMT_TXT; break; case 'r': get_reverse_colors(argc, argv, &optind);//.........这里部分代码省略.........
开发者ID:jamesbjackson,项目名称:src,代码行数:101,
示例4: board_spi_reset__EXPORT void board_spi_reset(int ms){ /* disable SPI bus */ px4_arch_configgpio(GPIO_SPI_CS_OFF_MPU9250); px4_arch_configgpio(GPIO_SPI_CS_OFF_HMC5983); px4_arch_configgpio(GPIO_SPI_CS_OFF_MS5611); px4_arch_configgpio(GPIO_SPI_CS_OFF_ICM_20608_G); px4_arch_gpiowrite(GPIO_SPI_CS_OFF_MPU9250, 0); px4_arch_gpiowrite(GPIO_SPI_CS_OFF_HMC5983, 0); px4_arch_gpiowrite(GPIO_SPI_CS_OFF_MS5611, 0); px4_arch_gpiowrite(GPIO_SPI_CS_OFF_ICM_20608_G, 0); px4_arch_configgpio(GPIO_SPI1_SCK_OFF); px4_arch_configgpio(GPIO_SPI1_MISO_OFF); px4_arch_configgpio(GPIO_SPI1_MOSI_OFF); px4_arch_gpiowrite(GPIO_SPI1_SCK_OFF, 0); px4_arch_gpiowrite(GPIO_SPI1_MISO_OFF, 0); px4_arch_gpiowrite(GPIO_SPI1_MOSI_OFF, 0); px4_arch_configgpio(GPIO_DRDY_OFF_MPU9250); px4_arch_configgpio(GPIO_DRDY_OFF_HMC5983); px4_arch_configgpio(GPIO_DRDY_OFF_ICM_20608_G); px4_arch_gpiowrite(GPIO_DRDY_OFF_MPU9250, 0); px4_arch_gpiowrite(GPIO_DRDY_OFF_HMC5983, 0); px4_arch_gpiowrite(GPIO_DRDY_OFF_ICM_20608_G, 0); /* set the sensor rail off */ px4_arch_configgpio(GPIO_VDD_3V3_SENSORS_EN); px4_arch_gpiowrite(GPIO_VDD_3V3_SENSORS_EN, 0); /* wait for the sensor rail to reach GND */ usleep(ms * 1000); warnx("reset done, %d ms", ms); /* re-enable power */ /* switch the sensor rail back on */ px4_arch_gpiowrite(GPIO_VDD_3V3_SENSORS_EN, 1); /* wait a bit before starting SPI, different times didn't influence results */ usleep(100); /* reconfigure the SPI pins */#ifdef CONFIG_STM32_SPI1 px4_arch_configgpio(GPIO_SPI_CS_MPU9250); px4_arch_configgpio(GPIO_SPI_CS_HMC5983); px4_arch_configgpio(GPIO_SPI_CS_MS5611); px4_arch_configgpio(GPIO_SPI_CS_ICM_20608_G); /* De-activate all peripherals, * required for some peripheral * state machines */ px4_arch_gpiowrite(GPIO_SPI_CS_MPU9250, 1); px4_arch_gpiowrite(GPIO_SPI_CS_HMC5983, 1); px4_arch_gpiowrite(GPIO_SPI_CS_MS5611, 1); px4_arch_gpiowrite(GPIO_SPI_CS_ICM_20608_G, 1); px4_arch_configgpio(GPIO_SPI1_SCK); px4_arch_configgpio(GPIO_SPI1_MISO); px4_arch_configgpio(GPIO_SPI1_MOSI); // // XXX bring up the EXTI pins again // px4_arch_configgpio(GPIO_GYRO_DRDY); // px4_arch_configgpio(GPIO_MAG_DRDY); // px4_arch_configgpio(GPIO_ACCEL_DRDY); // px4_arch_configgpio(GPIO_EXTI_MPU_DRDY);#endif}
开发者ID:2013-8-15,项目名称:Firmware,代码行数:74,
示例5: pw_copy/* * Copy password file from one descriptor to another, replacing, deleting * or adding a single record on the way. */intpw_copy(int ffd, int tfd, const struct passwd *pw, struct passwd *old_pw){ char buf[8192], *end, *line, *p, *q, *r, t; struct passwd *fpw; const struct passwd *spw; size_t len; int eof, readlen; if (old_pw == NULL && pw == NULL) return (-1); spw = old_pw; /* deleting a user */ if (pw == NULL) { line = NULL; } else { if ((line = pw_make(pw)) == NULL) return (-1); } /* adding a user */ if (spw == NULL) spw = pw; eof = 0; len = 0; p = q = end = buf; for (;;) { /* find the end of the current line */ for (p = q; q < end && *q != '/0'; ++q) if (*q == '/n') break; /* if we don't have a complete line, fill up the buffer */ if (q >= end) { if (eof) break; if ((size_t)(q - p) >= sizeof(buf)) { warnx("passwd line too long"); errno = EINVAL; /* hack */ goto err; } if (p < end) { q = memmove(buf, p, end - p); end -= p - buf; } else { p = q = end = buf; } readlen = read(ffd, end, sizeof(buf) - (end - buf)); if (readlen == -1) goto err; else len = (size_t)readlen; if (len == 0 && p == buf) break; end += len; len = end - buf; if (len < (ssize_t)sizeof(buf)) { eof = 1; if (len > 0 && buf[len - 1] != '/n') ++len, *end++ = '/n'; } continue; } /* is it a blank line or a comment? */ for (r = p; r < q && isspace(*r); ++r) /* nothing */ ; if (r == q || *r == '#') { /* yep */ if (write(tfd, p, q - p + 1) != q - p + 1) goto err; ++q; continue; } /* is it the one we're looking for? */ t = *q; *q = '/0'; fpw = pw_scan(r, PWSCAN_MASTER); /* * fpw is either the struct passwd for the current line, * or NULL if the line is malformed. */ *q = t; if (fpw == NULL || strcmp(fpw->pw_name, spw->pw_name) != 0) { /* nope */ if (fpw != NULL) free(fpw); if (write(tfd, p, q - p + 1) != q - p + 1) goto err;//.........这里部分代码省略.........
开发者ID:hmatyschok,项目名称:MeshBSD,代码行数:101,
示例6: pass1_dir/* * Check a directory. INO is the inode number; PATHSOFAR is the path * to this directory. This traverses the volume directory tree * recursively. */staticvoidpass1_dir(uint32_t ino, const char *pathsofar){ struct sfs_dinode sfi; struct sfs_dir *direntries; uint32_t ndirentries, i; int ichanged=0, dchanged=0; sfs_readinode(ino, &sfi); if (sfi.sfi_size % sizeof(struct sfs_dir) != 0) { setbadness(EXIT_RECOV); warnx("Directory %s has illegal size %lu (fixed)", pathsofar, (unsigned long) sfi.sfi_size); sfi.sfi_size = SFS_ROUNDUP(sfi.sfi_size, sizeof(struct sfs_dir)); ichanged = 1; } count_dirs++; if (pass1_inode(ino, &sfi, ichanged)) { /* been here before; crosslinked dir, sort it out in pass 2 */ return; } ndirentries = sfi.sfi_size/sizeof(struct sfs_dir); direntries = domalloc(sfi.sfi_size); sfs_readdir(&sfi, direntries, ndirentries); for (i=0; i<ndirentries; i++) { if (pass1_direntry(pathsofar, i, &direntries[i])) { dchanged = 1; } } for (i=0; i<ndirentries; i++) { if (direntries[i].sfd_ino == SFS_NOINO) { /* nothing */ } else if (!strcmp(direntries[i].sfd_name, ".")) { /* nothing */ } else if (!strcmp(direntries[i].sfd_name, "..")) { /* nothing */ } else { char path[strlen(pathsofar)+SFS_NAMELEN+1]; struct sfs_dinode subsfi; uint32_t subino; subino = direntries[i].sfd_ino; sfs_readinode(subino, &subsfi); snprintf(path, sizeof(path), "%s/%s", pathsofar, direntries[i].sfd_name); switch (subsfi.sfi_type) { case SFS_TYPE_FILE: if (pass1_inode(subino, &subsfi, 0)) { /* been here before */ break; } count_files++; break; case SFS_TYPE_DIR: pass1_dir(subino, path); break; default: setbadness(EXIT_RECOV); warnx("Object %s: Invalid inode type " "(removed)", path); direntries[i].sfd_ino = SFS_NOINO; direntries[i].sfd_name[0] = 0; dchanged = 1; break; } } } if (dchanged) { sfs_writedir(&sfi, direntries, ndirentries); } free(direntries);}
开发者ID:cse451,项目名称:os161,代码行数:91,
示例7: exec_upgradeintexec_upgrade(int argc, char **argv){ struct pkgdb *db = NULL; struct pkg_jobs *jobs = NULL; const char *reponame = NULL; int retcode; int updcode; int ch; bool yes; bool dry_run = false; bool auto_update; nbactions = nbdone = 0; pkg_flags f = PKG_FLAG_NONE | PKG_FLAG_PKG_VERSION_TEST; pkg_config_bool(PKG_CONFIG_ASSUME_ALWAYS_YES, &yes); pkg_config_bool(PKG_CONFIG_REPO_AUTOUPDATE, &auto_update); while ((ch = getopt(argc, argv, "fInqFr:Uy")) != -1) { switch (ch) { case 'f': f |= PKG_FLAG_FORCE; break; case 'I': f |= PKG_FLAG_NOSCRIPT; break; case 'U': auto_update = false; break; case 'n': f |= PKG_FLAG_DRY_RUN; dry_run = true; break; case 'F': f |= PKG_FLAG_SKIP_INSTALL; break; case 'q': quiet = true; break; case 'r': reponame = optarg; break; case 'y': yes = true; break; default: usage_upgrade(); return (EX_USAGE); /* NOTREACHED */ } } argc -= optind; argv += optind; if (argc != 0) { usage_upgrade(); return (EX_USAGE); } if (dry_run && !auto_update) retcode = pkgdb_access(PKGDB_MODE_READ, PKGDB_DB_LOCAL|PKGDB_DB_REPO); else retcode = pkgdb_access(PKGDB_MODE_READ | PKGDB_MODE_WRITE | PKGDB_MODE_CREATE, PKGDB_DB_LOCAL|PKGDB_DB_REPO); if (retcode == EPKG_ENOACCESS && dry_run) { auto_update = false; retcode = pkgdb_access(PKGDB_MODE_READ, PKGDB_DB_LOCAL|PKGDB_DB_REPO); } if (retcode == EPKG_ENOACCESS) { warnx("Insufficient privilege to upgrade packages"); return (EX_NOPERM); } else if (retcode != EPKG_OK) return (EX_IOERR); else retcode = EX_SOFTWARE; /* first update the remote repositories if needed */ if (auto_update && (updcode = pkgcli_update(false)) != EPKG_OK) return (updcode); if (pkgdb_open(&db, PKGDB_REMOTE) != EPKG_OK) return (EX_IOERR); if (pkg_jobs_new(&jobs, PKG_JOBS_UPGRADE, db) != EPKG_OK) goto cleanup; if (reponame != NULL && pkg_jobs_set_repository(jobs, reponame) != EPKG_OK) goto cleanup; pkg_jobs_set_flags(jobs, f); if (pkg_jobs_solve(jobs) != EPKG_OK) goto cleanup;//.........这里部分代码省略.........
开发者ID:yaneurabeya,项目名称:pkgng,代码行数:101,
示例8: sctp_process_tcbstatic voidsctp_process_tcb(struct xsctp_tcb *xstcb, char *buf, const size_t buflen, size_t *offset, int *indent){ int i, xl_total = 0, xr_total = 0, x_max; struct xsctp_raddr *xraddr; struct xsctp_laddr *xladdr; struct xladdr_entry *prev_xl = NULL, *xl = NULL, *xl_tmp; struct xraddr_entry *prev_xr = NULL, *xr = NULL, *xr_tmp; LIST_INIT(&xladdr_head); LIST_INIT(&xraddr_head); /* * Make `struct xladdr_list' list and `struct xraddr_list' list * to handle the address flexibly. */ while (*offset < buflen) { xladdr = (struct xsctp_laddr *)(buf + *offset); *offset += sizeof(struct xsctp_laddr); if (xladdr->last == 1) break; prev_xl = xl; xl = malloc(sizeof(struct xladdr_entry)); if (xl == NULL) { warnx("malloc %lu bytes", (u_long)sizeof(struct xladdr_entry)); goto out; } xl->xladdr = xladdr; if (prev_xl == NULL) LIST_INSERT_HEAD(&xladdr_head, xl, xladdr_entries); else LIST_INSERT_AFTER(prev_xl, xl, xladdr_entries); xl_total++; } while (*offset < buflen) { xraddr = (struct xsctp_raddr *)(buf + *offset); *offset += sizeof(struct xsctp_raddr); if (xraddr->last == 1) break; prev_xr = xr; xr = malloc(sizeof(struct xraddr_entry)); if (xr == NULL) { warnx("malloc %lu bytes", (u_long)sizeof(struct xraddr_entry)); goto out; } xr->xraddr = xraddr; if (prev_xr == NULL) LIST_INSERT_HEAD(&xraddr_head, xr, xraddr_entries); else LIST_INSERT_AFTER(prev_xr, xr, xraddr_entries); xr_total++; } /* * Let's print the address infos. */ xl = LIST_FIRST(&xladdr_head); xr = LIST_FIRST(&xraddr_head); x_max = (xl_total > xr_total) ? xl_total : xr_total; for (i = 0; i < x_max; i++) { if (((*indent == 0) && i > 0) || *indent > 0) printf("%-12s ", " "); if (xl != NULL) { sctp_print_address(&(xl->xladdr->address), htons(xstcb->local_port), numeric_port); } else { if (Wflag) { printf("%-45s ", " "); } else { printf("%-22s ", " "); } } if (xr != NULL && !Lflag) { sctp_print_address(&(xr->xraddr->address), htons(xstcb->remote_port), numeric_port); } if (xl != NULL) xl = LIST_NEXT(xl, xladdr_entries); if (xr != NULL) xr = LIST_NEXT(xr, xraddr_entries); if (i == 0 && !Lflag) sctp_statesprint(xstcb->state); if (i < x_max) putchar('/n'); }out: /* * Free the list which be used to handle the address.//.........这里部分代码省略.........
开发者ID:AhmadTux,项目名称:freebsd,代码行数:101,
示例9: mainintmain(int argc, char **argv){ struct archive *a1; struct archive *a2; struct archive_entry *e1; struct archive_entry *e2; const char *tc; char *buf1; char *buf2; char checkcont; char checklen; char checkname; char checksize; char checktime; char a1end; size_t size1; size_t size2; int opt, r; /* * Parse command line options. */ checkcont = 0; checklen = 0; checkname = 0; checksize = 0; checktime = 0; tc = NULL; while ((opt = getopt(argc, argv, "cilnst:")) != -1) { switch(opt) { case 'c': checkcont = 1; break; case 'i': checktime = 1; break; case 'l': checklen = 1; break; case 'n': checkname = 1; break; case 's': checksize = 1; case 't': tc = optarg; break; default: usage(); } } argc -= optind; argv += optind; if (argc != 2) usage(); /* Open file 1 */ a1 = archive_read_new(); archive_read_support_format_ar(a1); if (archive_read_open_filename(a1, argv[0], 1024*10)) { warnx("%s", archive_error_string(a1)); filediff(tc, "archive open failed", NULL); } /* Open file 2 */ a2 = archive_read_new(); archive_read_support_format_ar(a2); if (archive_read_open_filename(a2, argv[1], 1024*10)) { warnx("%s", archive_error_string(a2)); filediff(tc, "archive open failed", NULL); } /* Main loop */ a1end = 0; size1 = 0; size2 = 0; for (;;) { /* * Read header from each archive, compare length. */ r = archive_read_next_header(a1, &e1); if (r == ARCHIVE_EOF) a1end = 1; if (r == ARCHIVE_WARN || r == ARCHIVE_RETRY || r == ARCHIVE_FATAL) { warnx("%s", archive_error_string(a1)); filediff(tc, "archive data error", NULL); } r = archive_read_next_header(a2, &e2); if (r == ARCHIVE_EOF) { if (a1end > 0) break; else { if (checklen) filediff(tc, "length differ", NULL); break;//.........这里部分代码省略.........
开发者ID:emaste,项目名称:elftoolchain,代码行数:101,
示例10: get_pkcs_keychar *get_pkcs_key(char *arg, char *saltopt){ char passphrase[128]; char saltbuf[128], saltfilebuf[PATH_MAX]; char *key = NULL; char *saltfile; const char *errstr; int rounds; rounds = strtonum(arg, 1000, INT_MAX, &errstr); if (errstr) err(1, "rounds: %s", errstr); bzero(passphrase, sizeof(passphrase)); if (readpassphrase("Encryption key: ", passphrase, sizeof(passphrase), RPP_REQUIRE_TTY) == NULL) errx(1, "Unable to read passphrase"); if (saltopt) saltfile = saltopt; else { printf("Salt file: "); fflush(stdout); saltfile = fgets(saltfilebuf, sizeof(saltfilebuf), stdin); if (saltfile) saltfile[strcspn(saltfile, "/n")] = '/0'; } if (!saltfile || saltfile[0] == '/0') { warnx("Skipping salt file, insecure"); memset(saltbuf, 0, sizeof(saltbuf)); } else { int fd; fd = open(saltfile, O_RDONLY); if (fd == -1) { int *s; fprintf(stderr, "Salt file not found, attempting to " "create one/n"); fd = open(saltfile, O_RDWR|O_CREAT|O_EXCL, 0600); if (fd == -1) err(1, "Unable to create salt file: '%s'", saltfile); for (s = (int *)saltbuf; s < (int *)(saltbuf + sizeof(saltbuf)); s++) *s = arc4random(); if (write(fd, saltbuf, sizeof(saltbuf)) != sizeof(saltbuf)) err(1, "Unable to write salt file: '%s'", saltfile); fprintf(stderr, "Salt file created as '%s'/n", saltfile); } else { if (read(fd, saltbuf, sizeof(saltbuf)) != sizeof(saltbuf)) err(1, "Unable to read salt file: '%s'", saltfile); } close(fd); } if ((key = calloc(1, BLF_MAXUTILIZED)) == NULL) err(1, NULL); if (pkcs5_pbkdf2(passphrase, sizeof(passphrase), saltbuf, sizeof (saltbuf), key, BLF_MAXUTILIZED, rounds)) errx(1, "pkcs5_pbkdf2 failed"); memset(passphrase, 0, sizeof(passphrase)); return (key);}
开发者ID:toddfries,项目名称:OpenBSD-sbin-patches,代码行数:68,
示例11: set/* * Set an individual neighbor cache entry */static intset(int argc, char **argv){ register struct sockaddr_in6 *mysin = &sin_m; register struct sockaddr_dl *sdl; register struct rt_msghdr *rtm = &(m_rtmsg.m_rtm); struct addrinfo hints, *res; int gai_error; u_char *ea; char *host = argv[0], *eaddr = argv[1]; getsocket(); argc -= 2; argv += 2; sdl_m = blank_sdl; sin_m = blank_sin; (void)memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_INET6; gai_error = getaddrinfo(host, NULL, &hints, &res); if (gai_error) { warnx("%s: %s", host, gai_strerror(gai_error)); return 1; } makeaddr(mysin, res->ai_addr); ea = (u_char *)LLADDR(&sdl_m); if (ndp_ether_aton(eaddr, ea) == 0) sdl_m.sdl_alen = 6; flags = expire_time = 0; while (argc-- > 0) { if (strncmp(argv[0], "temp", 4) == 0) { struct timeval tim; (void)gettimeofday(&tim, 0); expire_time = tim.tv_sec + 20 * 60; } else if (strncmp(argv[0], "proxy", 5) == 0) flags |= RTF_ANNOUNCE; argv++; } if (rtmsg(RTM_GET) < 0) { errx(1, "RTM_GET(%s) failed", host); /* NOTREACHED */ } mysin = (struct sockaddr_in6 *)(void *)(rtm + 1); sdl = (struct sockaddr_dl *)(void *)(RT_ROUNDUP(mysin->sin6_len) + (char *)(void *)mysin); if (IN6_ARE_ADDR_EQUAL(&mysin->sin6_addr, &sin_m.sin6_addr)) { if (sdl->sdl_family == AF_LINK && !(rtm->rtm_flags & RTF_GATEWAY)) { switch (sdl->sdl_type) { case IFT_ETHER: case IFT_FDDI: case IFT_ISO88023: case IFT_ISO88024: case IFT_ISO88025: goto overwrite; } } /* * IPv4 arp command retries with sin_other = SIN_PROXY here. */ (void)fprintf(stderr, "set: cannot configure a new entry/n"); return 1; }overwrite: if (sdl->sdl_family != AF_LINK) { warnx("cannot intuit interface index and type for %s", host); return (1); } sdl_m.sdl_type = sdl->sdl_type; sdl_m.sdl_index = sdl->sdl_index; return (rtmsg(RTM_ADD));}
开发者ID:ryo,项目名称:netbsd-src,代码行数:73,
示例12: mainintmain(int argc, char *argv[]){ int errors; intmax_t numsig, pid; char *ep; setprogname(argv[0]); setlocale(LC_ALL, ""); if (argc < 2) usage(); numsig = SIGTERM; argc--, argv++; if (strcmp(*argv, "-l") == 0) { argc--, argv++; if (argc > 1) usage(); if (argc == 1) { if (isdigit((unsigned char)**argv) == 0) usage(); numsig = strtoimax(*argv, &ep, 10); /* check for correctly parsed number */ if (*ep != '/0' || numsig == INTMAX_MIN || numsig == INTMAX_MAX) { errx(EXIT_FAILURE, "illegal signal number: %s", *argv); /* NOTREACHED */ } if (numsig >= 128) numsig -= 128; /* and whether it fits into signals range */ if (numsig <= 0 || numsig >= NSIG) nosig(*argv); printf("%s/n", sys_signame[(int) numsig]); exit(0); } printsignals(stdout); exit(0); } if (!strcmp(*argv, "-s")) { argc--, argv++; if (argc < 1) { warnx("option requires an argument -- s"); usage(); } if (strcmp(*argv, "0")) { if ((numsig = signame_to_signum(*argv)) < 0) nosig(*argv); } else numsig = 0; argc--, argv++; } else if (**argv == '-') { char *sn = *argv + 1; if (isalpha((unsigned char)*sn)) { if ((numsig = signame_to_signum(sn)) < 0) nosig(sn); } else if (isdigit((unsigned char)*sn)) { numsig = strtoimax(sn, &ep, 10); /* check for correctly parsed number */ if (*ep || numsig == INTMAX_MIN || numsig == INTMAX_MAX ) { errx(EXIT_FAILURE, "illegal signal number: %s", sn); /* NOTREACHED */ } /* and whether it fits into signals range */ if (numsig < 0 || numsig >= NSIG) nosig(sn); } else nosig(sn); argc--, argv++; } if (argc == 0) usage(); for (errors = 0; argc; argc--, argv++) {#ifdef SHELL extern int getjobpgrp(const char *); if (*argv[0] == '%') { pid = getjobpgrp(*argv); if (pid == 0) { warnx("illegal job id: %s", *argv); errors = 1; continue; } } else #endif { pid = strtoimax(*argv, &ep, 10); /* make sure the pid is a number and fits into pid_t */ if (!**argv || *ep || pid == INTMAX_MIN || pid == INTMAX_MAX || pid != (pid_t) pid) { warnx("illegal process id: %s", *argv); errors = 1; continue; } }//.........这里部分代码省略.........
开发者ID:tombibsd,项目名称:netbsd-src,代码行数:101,
示例13: check_inode_blocks/* * Check the blocks belonging to inode INO, whose inode has already * been loaded into SFI. ISDIR is a shortcut telling us if the inode * is a directory. * * Returns nonzero if SFI has been modified and needs to be written * back. */staticintcheck_inode_blocks(uint32_t ino, struct sfs_dinode *sfi, int isdir){ struct ibstate ibs; uint32_t size, datablock; int changed; int i; size = SFS_ROUNDUP(sfi->sfi_size, SFS_BLOCKSIZE); ibs.ino = ino; /*ibs.curfileblock = 0;*/ ibs.fileblocks = size/SFS_BLOCKSIZE; ibs.volblocks = sb_totalblocks(); ibs.pasteofcount = 0; ibs.usagetype = isdir ? B_DIRDATA : B_DATA; changed = 0; for (ibs.curfileblock=0; ibs.curfileblock<NUM_D; ibs.curfileblock++) { datablock = GET_D(sfi, ibs.curfileblock); if (datablock >= ibs.volblocks) { warnx("Inode %lu: direct block pointer for " "block %lu outside of volume " "(cleared)/n", (unsigned long)ibs.ino, (unsigned long)ibs.curfileblock); SET_D(sfi, ibs.curfileblock) = 0; changed = 1; } else if (datablock > 0) { if (ibs.curfileblock < ibs.fileblocks) { bitmap_blockinuse(datablock, ibs.usagetype, ibs.ino); } else { ibs.pasteofcount++; changed = 1; bitmap_blockfree(datablock); SET_D(sfi, ibs.curfileblock) = 0; } } } for (i=0; i<NUM_I; i++) { check_indirect_block(&ibs, &SET_I(sfi, i), &changed, 1); } for (i=0; i<NUM_II; i++) { check_indirect_block(&ibs, &SET_II(sfi, i), &changed, 2); } for (i=0; i<NUM_III; i++) { check_indirect_block(&ibs, &SET_III(sfi, i), &changed, 3); } if (ibs.pasteofcount > 0) { warnx("Inode %lu: %u blocks after EOF (freed)", (unsigned long) ibs.ino, ibs.pasteofcount); setbadness(EXIT_RECOV); } return changed;}
开发者ID:cse451,项目名称:os161,代码行数:71,
示例14: main//.........这里部分代码省略......... inodes = kb / 2; if (kb >= 100000) inodes = kb / 4; if (kb >= 1000000) inodes = kb / 6; if (kb >= 10000000) inodes = kb / 8; if (kb >= 100000000) inodes = kb / 10; if (kb >= 1000000000) inodes = kb / 12;/* XXX check overflow: with very large number of blocks, this results in insanely large number of inodes *//* XXX check underflow (if/when ino_t is signed), else the message below will look strange */ /* round up to fill inode block */ inodes += inodes_per_block - 1; inodes = inodes / inodes_per_block * inodes_per_block; } if (blocks < 5) errx(1, "Block count too small"); if (inodes < 1) errx(1, "Inode count too small"); /* Make simple file system of the given size, using defaults. */ mode = 040777; usrid = BIN; grpid = BINGRP; simple = 1; } nrblocks = blocks; nrinodes = inodes; umap_array_elements = 1 + blocks/8; if(!(umap_array = malloc(umap_array_elements))) err(1, "can't allocate block bitmap (%u bytes).", (unsigned)umap_array_elements); /* Open special. */ special(argv[--optind]); if (!donttest) { uint16_t *testb; ssize_t w; testb = alloc_block(); /* Try writing the last block of partition or diskette. */ if(lseek64(fd, mul64u(blocks - 1, block_size), SEEK_SET, NULL) < 0) { err(1, "couldn't seek to last block to test size (1)"); } testb[0] = 0x3245; testb[1] = 0x11FF; testb[block_size/2-1] = 0x1F2F; if ((w=write(fd, testb, block_size)) != block_size) err(1, "File system is too big for minor device (write1 %d/%u)", w, block_size); sync(); /* flush write, so if error next read fails */ if(lseek64(fd, mul64u(blocks - 1, block_size), SEEK_SET, NULL) < 0) { err(1, "couldn't seek to last block to test size (2)"); } testb[0] = 0; testb[1] = 0; testb[block_size/2-1] = 0; nread = read(fd, testb, block_size); if (nread != block_size || testb[0] != 0x3245 || testb[1] != 0x11FF || testb[block_size/2-1] != 0x1F2F) { warn("nread = %d/n", nread); warnx("testb = 0x%x 0x%x 0x%x/n", testb[0], testb[1], testb[block_size-1]); errx(1, "File system is too big for minor device (read)"); } lseek64(fd, mul64u(blocks - 1, block_size), SEEK_SET, NULL); testb[0] = 0; testb[1] = 0; testb[block_size/2-1] = 0; if (write(fd, testb, block_size) != block_size) err(1, "File system is too big for minor device (write2)"); lseek(fd, 0L, SEEK_SET); free(testb); } /* Make the file-system */ put_block(BOOT_BLOCK, zero); /* Write a null boot block. */ put_block(BOOT_BLOCK+1, zero); /* Write another null block. */ super(nrblocks >> zone_shift, inodes); root_inum = alloc_inode(mode, usrid, grpid); rootdir(root_inum); if (simple == 0) eat_dir(root_inum); if (print) print_fs(); else if (verbose > 1) { if (zone_shift) fprintf(stderr, "%d inodes used. %u zones (%u blocks) used./n", (int)next_inode-1, next_zone, next_zone*zone_per_block); else fprintf(stderr, "%d inodes used. %u zones used./n", (int)next_inode-1, next_zone); } return(0); /* NOTREACHED */} /* end main */
开发者ID:ChaosJohn,项目名称:minix,代码行数:101,
示例15: check_indirect_block/* * Traverse an indirect block, recording blocks that are in use, * dropping any entries that are past EOF, and clearing any entries * that point outside the volume. * * XXX: this should be extended to be able to recover from crosslinked * blocks. Currently it just complains in bitmap.c and sets * EXIT_UNRECOV. * * The traversal is recursive; the state is maintained in IBS (as * described above). IENTRY is a pointer to the entry in the parent * indirect block (or the inode) that names the block we're currently * scanning. IECHANGEDP should be set to 1 if *IENTRY is changed. * INDIRECTION is the indirection level of this block (1, 2, or 3). */staticvoidcheck_indirect_block(struct ibstate *ibs, uint32_t *ientry, int *iechangedp, int indirection){ uint32_t entries[SFS_DBPERIDB]; uint32_t i, ct; uint32_t coveredblocks; int localchanged = 0; int j; if (*ientry > 0 && *ientry < ibs->volblocks) { sfs_readindirect(*ientry, entries); bitmap_blockinuse(*ientry, B_IBLOCK, ibs->ino); } else { if (*ientry >= ibs->volblocks) { warnx("Inode %lu: indirect block pointer (level %d) " "for block %lu outside of volume " "(cleared)/n", (unsigned long)ibs->ino, indirection, (unsigned long)ibs->curfileblock); *ientry = 0; *iechangedp = 1; } coveredblocks = 1; for (j=0; j<indirection; j++) { coveredblocks *= SFS_DBPERIDB; } ibs->curfileblock += coveredblocks; return; } if (indirection > 1) { for (i=0; i<SFS_DBPERIDB; i++) { check_indirect_block(ibs, &entries[i], &localchanged, indirection-1); } } else { assert(indirection==1); for (i=0; i<SFS_DBPERIDB; i++) { if (entries[i] >= ibs->volblocks) { warnx("Inode %lu: direct block pointer for " "block %lu outside of volume " "(cleared)/n", (unsigned long)ibs->ino, (unsigned long)ibs->curfileblock); entries[i] = 0; localchanged = 1; } else if (entries[i] != 0) { if (ibs->curfileblock < ibs->fileblocks) { bitmap_blockinuse(entries[i], ibs->usagetype, ibs->ino); } else { ibs->pasteofcount++; bitmap_blockfree(entries[i]); entries[i] = 0; localchanged = 1; } } ibs->curfileblock++; } } ct=0; for (i=ct=0; i<SFS_DBPERIDB; i++) { if (entries[i]!=0) ct++; } if (ct==0) { if (*ientry != 0) { /* this is not necessarily correct */ /*ibs->pasteofcount++;*/ *iechangedp = 1; bitmap_blockfree(*ientry); *ientry = 0; } } else { assert(*ientry != 0); if (localchanged) {//.........这里部分代码省略.........
开发者ID:cse451,项目名称:os161,代码行数:101,
示例16: mainintmain(int argc, char *argv[]){ int errors, numsig, pid; char *ep; if (argc < 2) usage(); numsig = SIGTERM; argc--, argv++; if (!strcmp(*argv, "-l")) { argc--, argv++; if (argc > 1) usage(); if (argc == 1) { if (!isdigit(**argv)) usage(); numsig = strtol(*argv, &ep, 10); if (!**argv || *ep) errx(1, "illegal signal number: %s", *argv); if (numsig >= 128) numsig -= 128; if (numsig <= 0 || numsig >= sys_nsig) nosig(*argv); printf("%s/n", sys_signame[numsig]); exit(0); } printsignals(stdout); exit(0); } if (!strcmp(*argv, "-s")) { argc--, argv++; if (argc < 1) { warnx("option requires an argument -- s"); usage(); } if (strcmp(*argv, "0")) { if ((numsig = signame_to_signum(*argv)) < 0) nosig(*argv); } else numsig = 0; argc--, argv++; } else if (**argv == '-' && *(*argv + 1) != '-') { ++*argv; if (isalpha(**argv)) { if ((numsig = signame_to_signum(*argv)) < 0) nosig(*argv); } else if (isdigit(**argv)) { numsig = strtol(*argv, &ep, 10); if (!**argv || *ep) errx(1, "illegal signal number: %s", *argv); if (numsig < 0) nosig(*argv); } else nosig(*argv); argc--, argv++; } if (argc > 0 && strncmp(*argv, "--", 2) == 0) argc--, argv++; if (argc == 0) usage(); for (errors = 0; argc; argc--, argv++) { pid = strtol(*argv, &ep, 10); if (!**argv || *ep) { warnx("illegal process id: %s", *argv); errors = 1; } else if (kill(pid, numsig) == -1) { warn("%s", *argv); errors = 1; } } exit(errors);}
开发者ID:grayshadow212,项目名称:usr.src,代码行数:80,
示例17: read_groupsstatic voidread_groups(perf_event_desc_t *fds, int num){ uint64_t *values = NULL; size_t new_sz, sz = 0; int i, evt, ret; /* * { u64 nr; * { u64 time_enabled; } && PERF_FORMAT_ENABLED * { u64 time_running; } && PERF_FORMAT_RUNNING * { u64 value; * { u64 id; } && PERF_FORMAT_ID * } cntr[nr]; * } && PERF_FORMAT_GROUP * * we do not use FORMAT_ID in this program */ for (evt = 0; evt < num; ) { int num_evts_to_read; if (options.format_group) { num_evts_to_read = perf_get_group_nevents(fds, num, evt); new_sz = sizeof(uint64_t) * (3 + num_evts_to_read); } else { num_evts_to_read = 1; new_sz = sizeof(uint64_t) * 3; } if (new_sz > sz) { sz = new_sz; values = realloc(values, sz); } if (!values) err(1, "cannot allocate memory for values/n"); ret = read(fds[evt].fd, values, new_sz); if (ret != new_sz) { /* unsigned */ if (ret == -1) err(1, "cannot read values event %s", fds[evt].name); /* likely pinned and could not be loaded */ warnx("could not read event %d, tried to read %zu bytes, but got %d", evt, new_sz, ret); } /* * propagate to save area */ for (i = evt; i < (evt + num_evts_to_read); i++) { if (options.format_group) values[0] = values[3 + (i - evt)]; /* * scaling because we may be sharing the PMU and * thus may be multiplexed */ fds[i].prev_value = fds[i].value; fds[i].value = perf_scale(values); fds[i].enabled = values[1]; fds[i].running = values[2]; } evt += num_evts_to_read; } if (values) free(values);}
开发者ID:chavli,项目名称:HetCMP-Codebase,代码行数:68,
示例18: bexpstatic voidbexp(void){ struct number *a, *p; struct number *r; bool neg; u_int scale; p = pop_number(); if (p == NULL) { return; } a = pop_number(); if (a == NULL) { push_number(p); return; } if (p->scale != 0) warnx("Runtime warning: non-zero scale in exponent"); normalize(p, 0); neg = false; if (BN_cmp(p->number, &zero) < 0) { neg = true; negate(p); scale = bmachine.scale; } else { /* Posix bc says min(a.scale * b, max(a.scale, scale) */ u_long b; u_int m; b = BN_get_word(p->number); m = max(a->scale, bmachine.scale); scale = a->scale * b; if (scale > m || b == BN_MASK2) scale = m; } if (BN_is_zero(p->number)) { r = new_number(); bn_check(BN_one(r->number)); normalize(r, scale); } else { while (!BN_is_bit_set(p->number, 0)) { bmul_number(a, a, a); bn_check(BN_rshift1(p->number, p->number)); } r = dup_number(a); normalize(r, scale); bn_check(BN_rshift1(p->number, p->number)); while (!BN_is_zero(p->number)) { bmul_number(a, a, a); if (BN_is_bit_set(p->number, 0)) bmul_number(r, r, a); bn_check(BN_rshift1(p->number, p->number)); } if (neg) { BN_CTX *ctx; BIGNUM *one; one = BN_new(); bn_checkp(one); BN_one(one); ctx = BN_CTX_new(); bn_checkp(ctx); scale_number(one, r->scale + scale); normalize(r, scale); bn_check(BN_div(r->number, NULL, one, r->number, ctx)); BN_free(one); BN_CTX_free(ctx); } else normalize(r, scale); } push_number(r); free_number(a); free_number(p);}
开发者ID:AhmadTux,项目名称:DragonFlyBSD,代码行数:81,
示例19: cmdloopintcmdloop(void){ char *line; const char *elline; int cmd_argc, rval = 0, known;#define scratch known char **cmd_argv; struct cmdtable *cmdp; History *hist; EditLine *elptr; HistEvent he; curinode = ginode(ROOTINO); curinum = ROOTINO; printactive(0); hist = history_init(); history(hist, &he, H_SETSIZE, 100); /* 100 elt history buffer */ elptr = el_init("fsdb", stdin, stdout, stderr); el_set(elptr, EL_EDITOR, "emacs"); el_set(elptr, EL_PROMPT, prompt); el_set(elptr, EL_HIST, history, hist); el_source(elptr, NULL); while ((elline = el_gets(elptr, &scratch)) != NULL && scratch != 0) { if (debug) printf("command `%s'/n", elline); history(hist, &he, H_ENTER, elline); line = strdup(elline); cmd_argv = crack(line, &cmd_argc); /* * el_parse returns -1 to signal that it's not been handled * internally. */ if (el_parse(elptr, cmd_argc, (const char **)cmd_argv) != -1) continue; if (cmd_argc) { known = 0; for (cmdp = cmds; cmdp->cmd; cmdp++) { if (!strcmp(cmdp->cmd, cmd_argv[0])) { if ((cmdp->flags & FL_WR) == FL_WR && nflag) warnx("`%s' requires write access", cmd_argv[0]), rval = 1; else if (cmd_argc >= cmdp->minargc && cmd_argc <= cmdp->maxargc) rval = (*cmdp->handler)(cmd_argc, cmd_argv); else if (cmd_argc >= cmdp->minargc && (cmdp->flags & FL_ST) == FL_ST) { strcpy(line, elline); cmd_argv = recrack(line, &cmd_argc, cmdp->maxargc); rval = (*cmdp->handler)(cmd_argc, cmd_argv); } else rval = argcount(cmdp, cmd_argc, cmd_argv); known = 1; break; } } if (!known) warnx("unknown command `%s'", cmd_argv[0]), rval = 1; } else rval = 0; free(line); if (rval < 0) /* user typed "quit" */ return 0; if (rval) warnx("rval was %d", rval); } el_end(elptr); history_end(hist); return rval;}
开发者ID:MattDooner,项目名称:freebsd-west,代码行数:76,
示例20: unknownstatic voidunknown(void){ int ch = bmachine.readstack[bmachine.readsp].lastchar; warnx("%c (0%o) is unimplemented", ch, ch);}
开发者ID:AhmadTux,项目名称:DragonFlyBSD,代码行数:6,
示例21: make_lfsintmake_lfs(int devfd, uint secsize, struct dkwedge_info *dkw, int minfree, int block_size, int frag_size, int seg_size, int minfreeseg, int resvseg, int version, daddr_t start, int ibsize, int interleave, u_int32_t roll_id){ struct ufs1_dinode *dip; /* Pointer to a disk inode */ CLEANERINFO *cip; /* Segment cleaner information table */ IFILE *ip; /* Pointer to array of ifile structures */ IFILE_V1 *ip_v1 = NULL; struct lfs *fs; /* Superblock */ SEGUSE *segp; /* Segment usage table */ daddr_t sb_addr; /* Address of superblocks */ daddr_t seg_addr; /* Address of current segment */ int bsize; /* Block size */ int fsize; /* Fragment size */ int db_per_blk; /* Disk blocks per file block */ int i, j; int sb_interval; /* number of segs between super blocks */ int ssize; /* Segment size */ double fssize; int warned_segtoobig=0; int label_fsb, sb_fsb; int curw, ww; char tbuf[BUFSIZ]; struct ubuf *bp; struct uvnode *vp, *save_devvp; int bb, ubb, dmeta, labelskew; u_int64_t tsepb, tnseg; /* * Initialize buffer cache. Use a ballpark guess of the length of * the segment table for the number of hash chains. */ tnseg = dkw->dkw_size / ((seg_size ? seg_size : DFL_LFSSEG) / secsize); tsepb = (block_size ? block_size : DFL_LFSBLOCK) / sizeof(SEGSUM); if (tnseg == 0) fatal("zero size partition"); bufinit(tnseg / tsepb); /* Initialize LFS subsystem with blank superblock and ifile. */ fs = lfs_init(devfd, start, (ufs_daddr_t)0, 1, 1/* XXX debug*/); save_devvp = fs->lfs_devvp; vp = fs->lfs_ivnode; *fs = lfs_default; fs->lfs_ivnode = vp; fs->lfs_devvp = save_devvp; /* Set version first of all since it is used to compute other fields */ fs->lfs_version = version; /* If partition is not an LFS partition, warn that that is the case */ if (strcmp(dkw->dkw_ptype, DKW_PTYPE_LFS) != 0) { fatal("partition label indicated fs type /"%s/", " "expected /"%s/"", dkw->dkw_ptype, DKW_PTYPE_LFS); } if (!(bsize = block_size)) bsize = DFL_LFSBLOCK; if (!(fsize = frag_size)) fsize = DFL_LFSFRAG; if (!(ssize = seg_size)) { ssize = DFL_LFSSEG; } if (version > 1) { if (ibsize == 0) ibsize = fsize; if (ibsize <= 0 || ibsize % fsize) fatal("illegal inode block size: %d/n", ibsize); } else if (ibsize && ibsize != bsize) fatal("cannot specify inode block size when version == 1/n"); /* Sanity check: fsize<=bsize<ssize */ if (fsize > bsize) { /* Only complain if fsize was explicitly set */ if(frag_size) fatal("fragment size must be <= block size %d", bsize); fsize = bsize; } if (bsize >= ssize) { /* Only fatal if ssize was explicitly set */ if(seg_size) fatal("block size must be < segment size"); warnx("%s: disklabel segment size (%d) too small, using default (%d)", progname, ssize, DFL_LFSSEG); ssize = DFL_LFSSEG; } if (start < 0 || start >= dkw->dkw_size) fatal("filesystem offset %ld out of range", (long)start); if (version == 1) { if (start) warnx("filesystem offset ignored for version 1 filesystem"); start = LFS_LABELPAD / secsize; } tryagain: /* Modify parts of superblock overridden by command line arguments */ if (bsize != DFL_LFSBLOCK || fsize != DFL_LFSFRAG) { fs->lfs_bshift = lfs_log2(bsize);//.........这里部分代码省略.........
开发者ID:lacombar,项目名称:netbsd-alc,代码行数:101,
示例22: mainintmain(int argc, char **argv){ int errors, numsig; pid_t pid; char *ep; if (argc < 2) usage(); numsig = SIGTERM; argc--, argv++; if (strcmp(*argv, "-l") == 0) { argc--, argv++; if (argc > 1) usage(); if (argc == 1) { if (!isdigit(**argv)) usage(); numsig = strtol(*argv, &ep, 10); if (**argv == '/0' || *ep != '/0') errx(2, "illegal signal number: %s", *argv); if (numsig >= 128) numsig -= 128; if (numsig <= 0 || numsig >= sys_nsig) nosig(*argv); printf("%s/n", sys_signame[numsig]); return (0); } printsignals(stdout); return (0); } if (strcmp(*argv, "-s") == 0) { argc--, argv++; if (argc < 1) { warnx("option requires an argument -- s"); usage(); } if (strcmp(*argv, "0") != 0) { if ((numsig = signame_to_signum(*argv)) < 0) nosig(*argv); } else numsig = 0; argc--, argv++; } else if (**argv == '-' && *(*argv + 1) != '-') { ++*argv; if (isalpha(**argv)) { if ((numsig = signame_to_signum(*argv)) < 0) nosig(*argv); } else if (isdigit(**argv)) { numsig = strtol(*argv, &ep, 10); if (**argv == '/0' || *ep != '/0') errx(2, "illegal signal number: %s", *argv); if (numsig < 0) nosig(*argv); } else nosig(*argv); argc--, argv++; } if (argc > 0 && strncmp(*argv, "--", 2) == 0) argc--, argv++; if (argc == 0) usage(); for (errors = 0; argc; argc--, argv++) {#ifdef SHELL if (**argv == '%') pid = getjobpgrp(*argv); else#endif { pid = (pid_t)strtol(*argv, &ep, 10); if (**argv == '/0' || *ep != '/0') errx(2, "illegal process id: %s", *argv); } if (kill(pid, numsig) == -1) { warn("%s", *argv); errors = 1; } } return (errors);}
开发者ID:jorisgio,项目名称:DragonFlyBSD,代码行数:87,
示例23: load_font//.........这里部分代码省略......... {0, 0, 0}}; if (vt4_mode) { size_sufx[0] = '/0'; } else { _info.size = sizeof(_info); if (ioctl(0, CONS_GETINFO, &_info) == -1) { revert(); warn("failed to obtain current video mode parameters"); return; } snprintf(size_sufx, sizeof(size_sufx), "-8x%d", _info.font_size); } fd = openguess((vt4_mode == 0) ? a : vt4a, b, c, d, &name); if (fd == NULL) { revert(); errx(1, "%s: can't load font file", filename); } if (vt4_mode) { if(load_vt4font(fd)) warn("failed to load font /"%s/"", filename); fclose(fd); return; } if (type != NULL) { size = 0; if (sscanf(type, "%dx%d", &w, &h) == 2) { for (i = 0; sizes[i].w != 0; i++) { if (sizes[i].w == w && sizes[i].h == h) { size = DATASIZE(sizes[i]); io = sizes[i].io; font_height = sizes[i].h; } } } if (size == 0) { fclose(fd); revert(); errx(1, "%s: bad font size specification", type); } } else { /* Apply heuristics */ int j; int dsize[2]; size = DATASIZE(sizes[0]); fontmap = (char*) malloc(size); dsize[0] = decode(fd, fontmap, size); dsize[1] = fsize(fd); free(fontmap); size = 0; for (j = 0; j < 2; j++) { for (i = 0; sizes[i].w != 0; i++) { if (DATASIZE(sizes[i]) == dsize[j]) { size = dsize[j]; io = sizes[i].io; font_height = sizes[i].h; j = 2; /* XXX */ break; } } } if (size == 0) { fclose(fd); revert(); errx(1, "%s: can't guess font size", filename); } rewind(fd); } fontmap = (char*) malloc(size); if (decode(fd, fontmap, size) != size) { rewind(fd); if (fsize(fd) != size || fread(fontmap, 1, size, fd) != (size_t)size) { warnx("%s: bad font file", filename); fclose(fd); free(fontmap); revert(); errx(1, "%s: bad font file", filename); } } if (ioctl(0, io, fontmap) == -1) { revert(); errc(1, errno, "loading font"); } fclose(fd); free(fontmap);}
开发者ID:jamesbjackson,项目名称:src,代码行数:101,
示例24: exec_auditintexec_audit(int argc, char **argv){ struct pkg_audit *audit; struct pkgdb *db = NULL; struct pkgdb_it *it = NULL; struct pkg *pkg = NULL; const char *db_dir; char *name; char *version; char audit_file_buf[MAXPATHLEN]; char *audit_file = audit_file_buf; unsigned int vuln = 0; bool fetch = false, recursive = false; int ch, i; int ret = EX_OK; const char *portaudit_site = NULL; struct sbuf *sb; kh_pkgs_t *check = NULL; db_dir = pkg_object_string(pkg_config_get("PKG_DBDIR")); snprintf(audit_file_buf, sizeof(audit_file_buf), "%s/vuln.xml", db_dir); struct option longopts[] = { { "fetch", no_argument, NULL, 'F' }, { "file", required_argument, NULL, 'f' }, { "recursive", no_argument, NULL, 'r' }, { "quiet", no_argument, NULL, 'q' }, { NULL, 0, NULL, 0 }, }; while ((ch = getopt_long(argc, argv, "+Ff:qr", longopts, NULL)) != -1) { switch (ch) { case 'F': fetch = true; break; case 'f': audit_file = optarg; break; case 'q': quiet = true; break; case 'r': recursive = true; break; default: usage_audit(); return(EX_USAGE); } } argc -= optind; argv += optind; audit = pkg_audit_new(); if (fetch == true) { portaudit_site = pkg_object_string(pkg_config_get("VULNXML_SITE")); if (pkg_audit_fetch(portaudit_site, audit_file) != EPKG_OK) { pkg_audit_free(audit); return (EX_IOERR); } } if (pkg_audit_load(audit, audit_file) != EPKG_OK) { if (errno == ENOENT) warnx("vulnxml file %s does not exist. " "Try running 'pkg audit -F' first", audit_file); else warn("unable to open vulnxml file %s", audit_file); pkg_audit_free(audit); return (EX_DATAERR); } check = kh_init_pkgs(); if (argc >= 1) { for (i = 0; i < argc; i ++) { name = argv[i]; version = strrchr(name, '-'); if (version != NULL) { version[0] = '/0'; version++; } if (pkg_new(&pkg, PKG_FILE) != EPKG_OK) err(EX_OSERR, "malloc"); if (version != NULL) pkg_set(pkg, PKG_NAME, name, PKG_VERSION, version); else pkg_set(pkg, PKG_NAME, name); /* Fake uniqueid */ pkg_set(pkg, PKG_UNIQUEID, name); add_to_check(check, pkg); pkg = NULL; } } else { /*//.........这里部分代码省略.........
开发者ID:grembo,项目名称:pkg,代码行数:101,
注:本文中的warnx函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ waserror函数代码示例 C++ warnp函数代码示例 |