本文整理汇总了C++中err函数的典型用法代码示例。如果您正苦于以下问题:C++ err函数的具体用法?C++ err怎么用?C++ err使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了err函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: parseline
void parseline(char *line, const ssize_t linenum)
{
char *past_date_p;
size_t ret;
static char *outbuf;
static size_t outbuf_len = OUTBUF_LEN_MIN;
if (!outbuf)
if ((outbuf = malloc(outbuf_len)) == NULL)
err(EX_OSERR, "malloc() failed to create output buffer");
while (*line != '\0') {
if (*line == '\n') {
putchar('\n');
break;
}
if ((past_date_p = strptime(line, Flag_Input_Format, &When)) != NULL) {
/* Uhh so yeah about that %s thing on Mac OS X. Guard for it.
* This was reported in Apple Bug 15753871 maaaaaany months ago but
* hey I guess there's more important things to deal with? */
if (past_date_p - line < 1)
errx(EX_SOFTWARE, "error: zero-width timestamp parse");
if (!Flag_Output_Format) {
printf("%ld", (long) mktime(&When));
} else {
while ((ret =
strftime(outbuf, outbuf_len, Flag_Output_Format, &When))
== 0) {
outbuf_len <<= 1;
if (outbuf_len > OUTBUF_LEN_MAX)
errx(EX_SOFTWARE,
"strftime() output too large for buffer %d at %s:%ld",
OUTBUF_LEN_MAX, File_Name, linenum);
if ((outbuf = realloc(outbuf, outbuf_len)) == NULL)
err(EX_OSERR,
"realloc() could not resize output buffer to %ld",
outbuf_len);
}
fwrite(outbuf, ret, (size_t) 1, stdout);
}
if (!Flag_Global) {
if (Flag_Suppress) {
putchar('\n');
} else {
printf("%s", past_date_p);
}
/* no global search means we're done with the line */
break;
} else {
/* spacer necessary between just the strftimes */
if (Flag_Suppress)
putchar(' ');
}
line = past_date_p;
} else {
/* charwise until strptime finds something, or not */
if (!Flag_Suppress) {
putchar(*line);
}
line++;
}
}
}
开发者ID:Studiogit,项目名称:sial.org-scripts,代码行数:69,代码来源:epochal.c
示例2: opcodeify
// Turns LLL tree into tree of code fragments
programData opcodeify(Node node,
programAux aux=Aux(),
programVerticalAux vaux=verticalAux()) {
std::string symb = "_"+mkUniqueToken();
Metadata m = node.metadata;
// Numbers
if (node.type == TOKEN) {
return pd(aux, nodeToNumeric(node), 1);
}
else if (node.val == "ref" || node.val == "get" || node.val == "set") {
std::string varname = node.args[0].val;
// Determine reference to variable
if (!aux.vars.count(node.args[0].val)) {
aux.vars[node.args[0].val] = utd(aux.nextVarMem);
aux.nextVarMem += 32;
}
Node varNode = tkn(aux.vars[varname], m);
//std::cerr << varname << " " << printSimple(varNode) << "\n";
// Set variable
if (node.val == "set") {
programData sub = opcodeify(node.args[1], aux, vaux);
if (!sub.outs)
err("Value to set variable must have nonzero arity!", m);
// What if we are setting a stack variable?
if (vaux.dupvars.count(node.args[0].val)) {
int h = vaux.height - vaux.dupvars[node.args[0].val];
if (h > 16) err("Too deep for stack variable (max 16)", m);
Node nodelist[] = {
sub.code,
token("SWAP"+unsignedToDecimal(h), m),
token("POP", m)
};
return pd(sub.aux, multiToken(nodelist, 3, m), 0);
}
// Setting a memory variable
else {
Node nodelist[] = {
sub.code,
varNode,
token("MSTORE", m),
};
return pd(sub.aux, multiToken(nodelist, 3, m), 0);
}
}
// Get variable
else if (node.val == "get") {
// Getting a stack variable
if (vaux.dupvars.count(node.args[0].val)) {
int h = vaux.height - vaux.dupvars[node.args[0].val];
if (h > 16) err("Too deep for stack variable (max 16)", m);
return pd(aux, token("DUP"+unsignedToDecimal(h)), 1);
}
// Getting a memory variable
else {
Node nodelist[] =
{ varNode, token("MLOAD", m) };
return pd(aux, multiToken(nodelist, 2, m), 1);
}
}
// Refer variable
else if (node.val == "ref") {
if (vaux.dupvars.count(node.args[0].val))
err("Cannot ref stack variable!", m);
return pd(aux, varNode, 1);
}
}
// Comments do nothing
else if (node.val == "comment") {
return pd(aux, astnode("_", m), 0);
}
// Custom operation sequence
// eg. (ops bytez id msize swap1 msize add 0 swap1 mstore) == alloc
if (node.val == "ops") {
std::vector<Node> subs2;
int depth = 0;
for (unsigned i = 0; i < node.args.size(); i++) {
std::string op = upperCase(node.args[i].val);
if (node.args[i].type == ASTNODE || opinputs(op) == -1) {
programVerticalAux vaux2 = vaux;
vaux2.height = vaux.height - i - 1 + node.args.size();
programData sub = opcodeify(node.args[i], aux, vaux2);
aux = sub.aux;
depth += sub.outs;
subs2.push_back(sub.code);
}
else {
subs2.push_back(token(op, m));
depth += opoutputs(op) - opinputs(op);
}
}
if (depth < 0 || depth > 1) err("Stack depth mismatch", m);
return pd(aux, astnode("_", subs2, m), 0);
}
// Code blocks
if (node.val == "lll" && node.args.size() == 2) {
if (node.args[1].val != "0") aux.allocUsed = true;
std::vector<Node> o;
o.push_back(finalize(opcodeify(node.args[0])));
programData sub = opcodeify(node.args[1], aux, vaux);
//.........这里部分代码省略.........
开发者ID:ethereum,项目名称:serpent,代码行数:101,代码来源:compiler.cpp
示例3: socks_connect
int
socks_connect(const char *host, const char *port,
struct addrinfo hints __attribute__ ((__unused__)),
const char *proxyhost, const char *proxyport, struct addrinfo proxyhints,
int socksv, const char *proxyuser)
{
int proxyfd, r, authretry = 0;
size_t hlen, wlen;
unsigned char buf[1024];
size_t cnt;
struct sockaddr_storage addr;
struct sockaddr_in *in4 = (struct sockaddr_in *)&addr;
struct sockaddr_in6 *in6 = (struct sockaddr_in6 *)&addr;
in_port_t serverport;
const char *proxypass = NULL;
if (proxyport == NULL)
proxyport = (socksv == -1) ? HTTP_PROXY_PORT : SOCKS_PORT;
/* Abuse API to lookup port */
if (decode_addrport("0.0.0.0", port, (struct sockaddr *)&addr,
sizeof(addr), 1, 1) == -1)
errx(1, "unknown port \"%.64s\"", port);
serverport = in4->sin_port;
again:
if (authretry++ > 3)
errx(1, "Too many authentication failures");
proxyfd = remote_connect(proxyhost, proxyport, proxyhints);
if (proxyfd < 0)
return (-1);
if (socksv == 5) {
if (decode_addrport(host, port, (struct sockaddr *)&addr,
sizeof(addr), 0, 1) == -1)
addr.ss_family = 0; /* used in switch below */
/* Version 5, one method: no authentication */
buf[0] = SOCKS_V5;
buf[1] = 1;
buf[2] = SOCKS_NOAUTH;
cnt = atomicio(vwrite, proxyfd, buf, 3);
if (cnt != 3)
err(1, "write failed (%zu/3)", cnt);
cnt = atomicio(read, proxyfd, buf, 2);
if (cnt != 2)
err(1, "read failed (%zu/3)", cnt);
if (buf[1] == SOCKS_NOMETHOD)
errx(1, "authentication method negotiation failed");
switch (addr.ss_family) {
case 0:
/* Version 5, connect: domain name */
/* Max domain name length is 255 bytes */
hlen = strlen(host);
if (hlen > 255)
errx(1, "host name too long for SOCKS5");
buf[0] = SOCKS_V5;
buf[1] = SOCKS_CONNECT;
buf[2] = 0;
buf[3] = SOCKS_DOMAIN;
buf[4] = hlen;
memcpy(buf + 5, host, hlen);
memcpy(buf + 5 + hlen, &serverport, sizeof serverport);
wlen = 7 + hlen;
break;
case AF_INET:
/* Version 5, connect: IPv4 address */
buf[0] = SOCKS_V5;
buf[1] = SOCKS_CONNECT;
buf[2] = 0;
buf[3] = SOCKS_IPV4;
memcpy(buf + 4, &in4->sin_addr, sizeof in4->sin_addr);
memcpy(buf + 8, &in4->sin_port, sizeof in4->sin_port);
wlen = 10;
break;
case AF_INET6:
/* Version 5, connect: IPv6 address */
buf[0] = SOCKS_V5;
buf[1] = SOCKS_CONNECT;
buf[2] = 0;
buf[3] = SOCKS_IPV6;
memcpy(buf + 4, &in6->sin6_addr, sizeof in6->sin6_addr);
memcpy(buf + 20, &in6->sin6_port,
sizeof in6->sin6_port);
wlen = 22;
break;
default:
errx(1, "internal error: silly AF");
}
cnt = atomicio(vwrite, proxyfd, buf, wlen);
if (cnt != wlen)
err(1, "write failed (%zu/%zu)", cnt, wlen);
//.........这里部分代码省略.........
开发者ID:ajinkya93,项目名称:OpenBSD,代码行数:101,代码来源:socks.c
示例4: main
int
main(int argc, char **argv)
{
struct iovec *iov;
int iovlen;
int ch, mntflags;
char *dev, *dir, *p, *val, mntpath[MAXPATHLEN];
int verbose;
int ssector; /* starting sector, 0 for 1st session */
char fstype[] = "cd9660";
iov = NULL;
iovlen = 0;
mntflags = verbose = 0;
ssector = -1;
while ((ch = getopt(argc, argv, "begjo:rs:vC:")) != -1)
switch (ch) {
case 'b':
build_iovec(&iov, &iovlen, "brokenjoliet", NULL, (size_t)-1);
break;
case 'e':
build_iovec(&iov, &iovlen, "extatt", NULL, (size_t)-1);
break;
case 'g':
build_iovec(&iov, &iovlen, "gens", NULL, (size_t)-1);
break;
case 'j':
build_iovec(&iov, &iovlen, "nojoliet", NULL, (size_t)-1);
break;
case 'o':
getmntopts(optarg, mopts, &mntflags, NULL);
p = strchr(optarg, '=');
val = NULL;
if (p != NULL) {
*p = '\0';
val = p + 1;
}
build_iovec(&iov, &iovlen, optarg, val, (size_t)-1);
break;
case 'r':
build_iovec(&iov, &iovlen, "norrip", NULL, (size_t)-1);
break;
case 's':
ssector = atoi(optarg);
break;
case 'v':
verbose++;
break;
case 'C':
if (set_charset(&iov, &iovlen, optarg) == -1)
err(EX_OSERR, "cd9660_iconv");
build_iovec(&iov, &iovlen, "kiconv", NULL, (size_t)-1);
break;
case '?':
default:
usage();
}
argc -= optind;
argv += optind;
if (argc != 2)
usage();
dev = argv[0];
dir = argv[1];
/*
* Resolve the mountpoint with realpath(3) and remove unnecessary
* slashes from the devicename if there are any.
*/
if (checkpath(dir, mntpath) != 0)
err(1, "%s", mntpath);
(void)rmslashes(dev, dev);
if (ssector == -1) {
/*
* The start of the session has not been specified on
* the command line. If we can successfully read the
* TOC of a CD-ROM, use the last data track we find.
* Otherwise, just use 0, in order to mount the very
* first session. This is compatible with the
* historic behaviour of mount_cd9660(8). If the user
* has specified -s <ssector> above, we don't get here
* and leave the user's will.
*/
if ((ssector = get_ssector(dev)) == -1) {
if (verbose)
printf("could not determine starting sector, "
"using very first session\n");
ssector = 0;
} else if (verbose)
printf("using starting sector %d\n", ssector);
}
mntflags |= MNT_RDONLY;
build_iovec(&iov, &iovlen, "fstype", fstype, (size_t)-1);
build_iovec(&iov, &iovlen, "fspath", mntpath, (size_t)-1);
build_iovec(&iov, &iovlen, "from", dev, (size_t)-1);
build_iovec_argf(&iov, &iovlen, "ssector", "%d", ssector);
//.........这里部分代码省略.........
开发者ID:2asoft,项目名称:freebsd,代码行数:101,代码来源:mount_cd9660.c
示例5: main
int
main(int argc, char **argv)
{
int i, len;
double eval, clk;
long long ncycles_ref, counter;
double eptime;
double add_delay;
struct cfg cf;
char buf[256];
struct recfilter loop_error;
struct PFD phase_detector;
useconds_t usleep_time;
struct sched_param sparam;
#if RTPP_DEBUG
double sleep_time, filter_lastval;
#endif
memset(&cf, 0, sizeof(cf));
cf.stable = malloc(sizeof(struct rtpp_cfg_stable));
if (cf.stable == NULL) {
err(1, "can't allocate memory for the struct rtpp_cfg_stable");
/* NOTREACHED */
}
memset(cf.stable, '\0', sizeof(struct rtpp_cfg_stable));
cf.stable->ctrl_socks = malloc(sizeof(struct rtpp_list));
if (cf.stable->ctrl_socks == NULL) {
err(1, "can't allocate memory for the struct rtpp_cfg_stable");
/* NOTREACHED */
}
memset(cf.stable->ctrl_socks, '\0', sizeof(struct rtpp_list));
RTPP_LIST_RESET(cf.stable->ctrl_socks);
init_config(&cf, argc, argv);
seedrandom();
cf.stable->sessions_ht = rtpp_hash_table_ctor();
if (cf.stable->sessions_ht == NULL) {
err(1, "can't allocate memory for the hash table");
/* NOTREACHED */
}
cf.stable->rtpp_stats = rtpp_stats_ctor();
if (cf.stable->rtpp_stats == NULL) {
err(1, "can't allocate memory for the stats data");
/* NOTREACHED */
}
init_port_table(&cf);
if (rtpp_controlfd_init(&cf) != 0) {
err(1, "can't inilialize control socket%s",
cf.stable->ctrl_socks->len > 1 ? "s" : "");
}
if (cf.stable->nodaemon == 0) {
if (rtpp_daemon(0, 0) == -1)
err(1, "can't switch into daemon mode");
/* NOTREACHED */
}
if (rtpp_notify_init() != 0)
errx(1, "can't start notification thread");
cf.stable->glog = rtpp_log_open(cf.stable, "rtpproxy", NULL, LF_REOPEN);
rtpp_log_setlevel(cf.stable->glog, cf.stable->log_level);
_sig_cf = &cf;
atexit(ehandler);
rtpp_log_write(RTPP_LOG_INFO, cf.stable->glog, "rtpproxy started, pid %d", getpid());
i = open(cf.stable->pid_file, O_WRONLY | O_CREAT | O_TRUNC, DEFFILEMODE);
if (i >= 0) {
len = sprintf(buf, "%u\n", (unsigned int)getpid());
write(i, buf, len);
close(i);
} else {
rtpp_log_ewrite(RTPP_LOG_ERR, cf.stable->glog, "can't open pidfile for writing");
}
signal(SIGHUP, sighup);
signal(SIGINT, fatsignal);
signal(SIGKILL, fatsignal);
signal(SIGPIPE, SIG_IGN);
signal(SIGTERM, fatsignal);
signal(SIGXCPU, fatsignal);
signal(SIGXFSZ, fatsignal);
signal(SIGVTALRM, fatsignal);
signal(SIGPROF, fatsignal);
signal(SIGUSR1, fatsignal);
signal(SIGUSR2, fatsignal);
if (cf.stable->sched_policy != SCHED_OTHER) {
sparam.sched_priority = sched_get_priority_max(cf.stable->sched_policy);
if (sched_setscheduler(0, cf.stable->sched_policy, &sparam) == -1) {
rtpp_log_ewrite(RTPP_LOG_ERR, cf.stable->glog, "sched_setscheduler(SCHED_%s, %d)",
(cf.stable->sched_policy == SCHED_FIFO) ? "FIFO" : "RR", sparam.sched_priority);
}
}
if (cf.stable->run_uname != NULL || cf.stable->run_gname != NULL) {
if (drop_privileges(&cf) != 0) {
//.........这里部分代码省略.........
开发者ID:yzy5768,项目名称:rtpproxy,代码行数:101,代码来源:main.c
示例6: xamdeflst
xamdeflst()
{
long mul;
int botptr, bret, value;
int xoff, yoff, mx, my;
int i, ret, cont;
int np, xam;
int k1, k2;
/* Allocate memory to hold defects */
if ((xampaddr = mymalloc(npndefs*(sizeof(PADDR)))) <= 0) {
return err(nomemory);
}
for (np = 0; np < npndefs; np++) {
xampaddr[np].exist = nppaddr[np].exist;
xampaddr[np].head = nppaddr[np].head;
xampaddr[np].cylndr = nppaddr[np].cylndr;
xampaddr[np].btoffst = nppaddr[np].btoffst;
}
r_items(); /* read items */
totcnt = npndefs;
if (npndefs > NM_ITEMS) /* bigger than one window */
botptr = npndefs - NM_ITEMS;
else
botptr = 0;
cont = TRUE; /* control flag */
while(cont) {
bret = form_do(xamform, -1);
graf_mkstate(&mx, &my, &k1, &k2); /* graf mkstate */
ret = bret & 0x7FFF; /* mask off double click */
LWSET(OB_STATE(xamform, ret), 0);
value = 1; /* scroll factor */
switch (ret) { /* Big Switch */
case FSVSLID:
objc_offset(xamform, FSVELEV, &xoff, &yoff);
value = NM_ITEMS; /* one full window size */
if (my <= yoff)
goto up;
goto down;
case FSVELEV:
value = graf_slidebox(xamform, FSVSLID, FSVELEV, TRUE);
mul = (npndefs - NM_ITEMS) * value;
mul /= 1000;
value = (int)mul;
value = (topptr - value);
if (value >= 0)
goto up; /* go up */
else
value = -value; /* go down */
down: case FDNAROW: /* scroll down */
if (topptr == botptr)
break;
if ((topptr + value) <= botptr)
topptr += value;
else
topptr = botptr;
goto sfiles;
up: case FUPAROW: /* scroll up */
if (!topptr)
break;
if ((topptr - value) >= 0)
topptr -= value;
else
topptr = 0;
sfiles: r_show(topptr); /* redisplay the file */
break;
case FCLSBOX:
cont = FALSE;
break;
default:
if (ret >= ENTRY0 && ret <= ENTRY7) {
erasemsg(); /* erase EXAMINING box */
want2edt(ret); /* let user edit entry */
dsplymsg(xamform); /* redraw EXAMINING box */
}
break;
} /* end of switch */
} /* while */
erasemsg();
/* New inputted list = Examined list */
for (xam = 0, np = 0; xam < npndefs; xam++) {
if (xampaddr[xam].exist) {
nppaddr[np].head = xampaddr[xam].head;
nppaddr[np].cylndr = xampaddr[xam].cylndr;
nppaddr[np].btoffst = xampaddr[xam].btoffst;
//.........这里部分代码省略.........
开发者ID:daemqn,项目名称:Atari_ST_Sources,代码行数:101,代码来源:DEFSCROL.C
示例7: main
int main(int argc, char **argv)
{
if (argc < 2) {
usage();
exit(1);
}
FILE *fin, *fh, *fc;
fname = argv[1];
create_names();
fin = fopen(fname, "rt");
if (fin == NULL)
err(1, "cannot open input file: %s", fname);
fc = fopen(c_fname, "wt");
if (fc == NULL)
err(1, "cannot open output C file %s", c_fname);
fh = fopen(h_fname, "wt");
if (fh == NULL)
err(1, "cannot open output H file %s", h_fname);
fprintf(fh,
"extern const char %s[];\n"
"extern const size_t %s_size;\n",
name, name);
fprintf(fc,
"#include <unistd.h>\n"
"\n"
"const char %s[] = \"\"\n\"",
name);
int c = 0;
size_t size = 0;
while ((c = fgetc(fin)) != EOF) {
size++;
switch (c) {
case '\\':
fputs("\\\\", fc);
break;
case '\"':
fputs("\\\"", fc);
break;
case '\n':
fputs("\\n\"\n\"", fc);
break;
default:
fputc(c, fc);
}
}
fprintf(fc,
"\";\n"
"\n"
"const size_t %s_size = %zu;\n",
name,
size);
fclose(fc);
fclose(fh);
fclose(fin);
return 0;
}
开发者ID:serge-v,项目名称:common,代码行数:67,代码来源:mkresource.c
示例8: main
int
main(int argc, char *argv[])
{
struct passwd *pwd;
int ch, newline;
char *file, *sender, *p;
#if MAXPATHLEN > BUFSIZ
char buf[MAXPATHLEN];
#else
char buf[BUFSIZ];
#endif
file = sender = NULL;
while ((ch = getopt(argc, argv, "f:s:")) != -1)
switch((char)ch) {
case 'f':
file = optarg;
break;
case 's':
sender = optarg;
for (p = sender; *p; ++p)
if (isupper(*p))
*p = tolower(*p);
break;
case '?':
default:
fprintf(stderr,
"usage: from [-f file] [-s sender] [user]\n");
exit(1);
}
argv += optind;
/*
* We find the mailbox by:
* 1 -f flag
* 2 user
* 2 MAIL environment variable
* 3 _PATH_MAILDIR/file
*/
if (!file) {
if (!(file = *argv)) {
if (!(file = getenv("MAIL"))) {
if (!(pwd = getpwuid(getuid())))
errx(1, "no password file entry for you");
if ((file = getenv("USER"))) {
(void)snprintf(buf, sizeof(buf),
"%s/%s", _PATH_MAILDIR, file);
file = buf;
} else
(void)snprintf(file = buf, sizeof(buf),
"%s/%s", _PATH_MAILDIR,
pwd->pw_name);
}
} else {
(void)snprintf(buf, sizeof(buf), "%s/%s",
_PATH_MAILDIR, file);
file = buf;
}
}
if (!freopen(file, "r", stdin))
err(1, "%s", file);
for (newline = 1; fgets(buf, sizeof(buf), stdin);) {
if (*buf == '\n') {
newline = 1;
continue;
}
if (newline && !strncmp(buf, "From ", 5) &&
(!sender || match(buf + 5, sender)))
printf("%s", buf);
newline = 0;
}
exit(0);
}
开发者ID:UNGLinux,项目名称:Obase,代码行数:73,代码来源:from.c
示例9: main
/*
* Periodically pat the watchdog, preventing it from firing.
*/
int
main(int argc, char *argv[])
{
struct rtprio rtp;
struct pidfh *pfh;
pid_t otherpid;
if (getuid() != 0)
errx(EX_SOFTWARE, "not super user");
parseargs(argc, argv);
if (do_syslog)
openlog("watchdogd", LOG_CONS|LOG_NDELAY|LOG_PERROR,
LOG_DAEMON);
rtp.type = RTP_PRIO_REALTIME;
rtp.prio = 0;
if (rtprio(RTP_SET, 0, &rtp) == -1)
err(EX_OSERR, "rtprio");
if (!is_dry_run && watchdog_init() == -1)
errx(EX_SOFTWARE, "unable to initialize watchdog");
if (is_daemon) {
if (watchdog_onoff(1) == -1)
err(EX_OSERR, "patting the dog");
pfh = pidfile_open(pidfile, 0600, &otherpid);
if (pfh == NULL) {
if (errno == EEXIST) {
watchdog_onoff(0);
errx(EX_SOFTWARE, "%s already running, pid: %d",
getprogname(), otherpid);
}
warn("Cannot open or create pidfile");
}
if (debugging == 0 && daemon(0, 0) == -1) {
watchdog_onoff(0);
pidfile_remove(pfh);
err(EX_OSERR, "daemon");
}
signal(SIGHUP, SIG_IGN);
signal(SIGINT, sighandler);
signal(SIGTERM, sighandler);
pidfile_write(pfh);
if (madvise(0, 0, MADV_PROTECT) != 0)
warn("madvise failed");
if (mlockall(MCL_CURRENT | MCL_FUTURE) != 0)
warn("mlockall failed");
watchdog_loop();
/* exiting */
pidfile_remove(pfh);
return (EX_OK);
} else {
if (passive)
timeout |= WD_PASSIVE;
else
timeout |= WD_ACTIVE;
if (watchdog_patpat(timeout) < 0)
err(EX_OSERR, "patting the dog");
return (EX_OK);
}
}
开发者ID:JabirTech,项目名称:Source,代码行数:72,代码来源:watchdogd.c
示例10: tvtohz
/*
* Convert a timeval to a number of ticks.
* Mostly copied from the kernel.
*/
int
tvtohz(struct timeval *tv)
{
register unsigned long ticks;
register long sec, usec;
int hz;
size_t hzsize;
int error;
int tick;
hzsize = sizeof(hz);
error = sysctlbyname("kern.hz", &hz, &hzsize, NULL, 0);
if (error)
err(1, "sysctlbyname kern.hz");
tick = 1000000 / hz;
/*
* If the number of usecs in the whole seconds part of the time
* difference fits in a long, then the total number of usecs will
* fit in an unsigned long. Compute the total and convert it to
* ticks, rounding up and adding 1 to allow for the current tick
* to expire. Rounding also depends on unsigned long arithmetic
* to avoid overflow.
*
* Otherwise, if the number of ticks in the whole seconds part of
* the time difference fits in a long, then convert the parts to
* ticks separately and add, using similar rounding methods and
* overflow avoidance. This method would work in the previous
* case but it is slightly slower and assumes that hz is integral.
*
* Otherwise, round the time difference down to the maximum
* representable value.
*
* If ints have 32 bits, then the maximum value for any timeout in
* 10ms ticks is 248 days.
*/
sec = tv->tv_sec;
usec = tv->tv_usec;
if (usec < 0) {
sec--;
usec += 1000000;
}
if (sec < 0) {
#ifdef DIAGNOSTIC
if (usec > 0) {
sec++;
usec -= 1000000;
}
printf("tvotohz: negative time difference %ld sec %ld usec\n",
sec, usec);
#endif
ticks = 1;
} else if (sec <= LONG_MAX / 1000000)
ticks = (sec * 1000000 + (unsigned long)usec + (tick - 1))
/ tick + 1;
else if (sec <= LONG_MAX / hz)
ticks = sec * hz
+ ((unsigned long)usec + (tick - 1)) / tick + 1;
else
ticks = LONG_MAX;
if (ticks > INT_MAX)
ticks = INT_MAX;
return ((int)ticks);
}
开发者ID:JabirTech,项目名称:Source,代码行数:70,代码来源:watchdogd.c
示例11: runServer
int runServer(void) {
int listenfd;
struct sockaddr_in listen_addr;
struct event ev_accept;
int reuseaddr_on;
event_init();
sigset_t sigset;
sigemptyset(&sigset);
struct sigaction siginfo = {
.sa_handler = sighandler,
.sa_mask = sigset,
.sa_flags = SA_RESTART,
};
sigaction(SIGINT, &siginfo, NULL);
sigaction(SIGTERM, &siginfo, NULL);
listenfd = socket(AF_INET, SOCK_STREAM, 0);
if (listenfd < 0) {
err(1, "listen failed");
}
memset(&listen_addr, 0, sizeof(listen_addr));
listen_addr.sin_family = AF_INET;
listen_addr.sin_addr.s_addr = INADDR_ANY;
listen_addr.sin_port = htons(SERVER_PORT);
if (bind(listenfd, (struct sockaddr *)&listen_addr, sizeof(listen_addr)) < 0) {
err(1, "bind failed");
}
if (listen(listenfd, CONNECTION_BACKLOG) < 0) {
err(1, "listen failed");
}
reuseaddr_on = 1;
setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &reuseaddr_on, sizeof(reuseaddr_on));
if (setnonblock(listenfd) < 0) {
err(1, "failed to set server socket to non-blocking");
}
if ((evbase_accept = event_base_new()) == NULL) {
perror("Unable to create socket accept event base");
close(listenfd);
return 1;
}
if (workqueue_init(&workqueue, NUM_THREADS)) {
perror("Failed to create work queue");
close(listenfd);
workqueue_shutdown(&workqueue);
return 1;
}
event_set(&ev_accept, listenfd, EV_READ|EV_PERSIST, on_accept, (void *)&workqueue);
event_base_set(evbase_accept, &ev_accept);
event_add(&ev_accept, NULL);
printf("Server running.\n");
event_base_dispatch(evbase_accept);
event_base_free(evbase_accept);
evbase_accept = NULL;
close(listenfd);
printf("Server shutdown.\n");
return 0;
}
开发者ID:nike-17,项目名称:c-tcp-server-threaded,代码行数:69,代码来源:tcp-echo-server.c
示例12: runtest
static void
runtest(struct alg *alg, int count, int size, u_long cmd, struct timeval *tv)
{
int i, fd = crget();
struct timeval start, stop, dt;
char *cleartext, *ciphertext, *originaltext;
struct session2_op sop;
struct crypt_op cop;
char iv[EALG_MAX_BLOCK_LEN];
bzero(&sop, sizeof(sop));
if (!alg->ishash) {
sop.keylen = (alg->minkeylen + alg->maxkeylen)/2;
sop.key = (char *) malloc(sop.keylen);
if (sop.key == NULL)
err(1, "malloc (key)");
for (i = 0; i < sop.keylen; i++)
sop.key[i] = rdigit();
sop.cipher = alg->code;
} else {
sop.mackeylen = (alg->minkeylen + alg->maxkeylen)/2;
sop.mackey = (char *) malloc(sop.mackeylen);
if (sop.mackey == NULL)
err(1, "malloc (mac)");
for (i = 0; i < sop.mackeylen; i++)
sop.mackey[i] = rdigit();
sop.mac = alg->code;
}
sop.crid = crid;
if (ioctl(fd, cmd, &sop) < 0) {
if (cmd == CIOCGSESSION || cmd == CIOCGSESSION2) {
close(fd);
if (verbose) {
printf("cipher %s", alg->name);
if (alg->ishash)
printf(" mackeylen %u\n", sop.mackeylen);
else
printf(" keylen %u\n", sop.keylen);
perror("CIOCGSESSION");
}
/* hardware doesn't support algorithm; skip it */
return;
}
printf("cipher %s keylen %u mackeylen %u\n",
alg->name, sop.keylen, sop.mackeylen);
err(1, "CIOCGSESSION");
}
originaltext = malloc(3*size);
if (originaltext == NULL)
err(1, "malloc (text)");
cleartext = originaltext+size;
ciphertext = cleartext+size;
for (i = 0; i < size; i++)
cleartext[i] = rdigit();
memcpy(originaltext, cleartext, size);
for (i = 0; i < N(iv); i++)
iv[i] = rdigit();
if (verbose) {
printf("session = 0x%x\n", sop.ses);
printf("device = %s\n", crfind(sop.crid));
printf("count = %d, size = %d\n", count, size);
if (!alg->ishash) {
printf("iv:");
hexdump(iv, sizeof iv);
}
printf("cleartext:");
hexdump(cleartext, MIN(size, CHUNK));
}
gettimeofday(&start, NULL);
if (!alg->ishash) {
for (i = 0; i < count; i++) {
cop.ses = sop.ses;
cop.op = COP_ENCRYPT;
cop.flags = opflags;
cop.len = size;
cop.src = cleartext;
cop.dst = ciphertext;
cop.mac = 0;
cop.iv = iv;
if (ioctl(fd, CIOCCRYPT, &cop) < 0)
err(1, "ioctl(CIOCCRYPT)");
if (verify && bcmp(ciphertext, cleartext, size) == 0) {
printf("cipher text unchanged:");
hexdump(ciphertext, size);
}
memset(cleartext, 'x', MIN(size, CHUNK));
cop.ses = sop.ses;
cop.op = COP_DECRYPT;
cop.flags = opflags;
cop.len = size;
cop.src = ciphertext;
cop.dst = cleartext;
cop.mac = 0;
cop.iv = iv;
//.........这里部分代码省略.........
开发者ID:edgar-pek,项目名称:PerspicuOS,代码行数:101,代码来源:cryptotest.c
示例13: main
int main(int argc, char *argv[])
{
FILE *fh;
char *line = NULL;
int ch;
size_t linesize = 0;
ssize_t linelen;
ssize_t linenum = 1;
time_t now;
if (!setlocale(LC_ALL, ""))
errx(EX_USAGE, "setlocale(3) failed: check the locale settings");
/* As otherwise the default of 0 could cause time formats that do not
* include the date to skip back to a date in the previous month. */
When.tm_mday = 1;
while ((ch = getopt(argc, argv, "f:gh?o:syY:")) != -1) {
switch (ch) {
case 'f':
Flag_Input_Format = optarg;
break;
case 'g':
Flag_Global = true;
break;
case 'o':
Flag_Output_Format = optarg;
break;
case 's':
Flag_Suppress = true;
break;
case 'y':
if (time(&now) == (time_t) - 1)
errx(EX_OSERR, "time(3) could not obtain current time??");
if (localtime_r(&now, &When) == NULL)
errx(EX_OSERR, "localtime_r(3) failed??");
Flag_Custom_Year = true;
break;
case 'Y':
if (!strptime(optarg, "%Y", &When))
errx(EX_USAGE, "strptime(3) could not parse year from -Y flag");
Flag_Custom_Year = true;
break;
case 'h':
case '?':
default:
emit_help();
/* NOTREACHED */
}
}
argc -= optind;
argv += optind;
if (!Flag_Input_Format)
emit_help();
/* Due to crazy behavior on Mac OS X (see also guard for it, below), and
* otherwise there are less expensive syscalls that can better deal with
* epoch values. */
if (strncmp(Flag_Input_Format, "%s", (size_t) 2) == 0)
errx(EX_DATAERR, "%%s is not supported as input format");
if (argc == 0 || strncmp(*argv, "-", (size_t) 2) == 0) {
fh = stdin;
} else {
if ((fh = fopen(*argv, "r")) == NULL)
err(EX_IOERR, "could not open '%s'", *argv);
File_Name = *argv;
}
while ((linelen = getline(&line, &linesize, fh)) != -1) {
parseline(line, linenum);
linenum++;
}
if (ferror(fh))
err(EX_IOERR, "error reading file");
exit(EXIT_SUCCESS);
}
开发者ID:Studiogit,项目名称:sial.org-scripts,代码行数:79,代码来源:epochal.c
示例14: DBG_RTF
void RTFDocVisitor::visit(DocVerbatim *s)
{
if (m_hide) return;
DBG_RTF("{\\comment RTFDocVisitor::visit(DocVerbatim)}\n");
QCString lang = m_langExt;
if (!s->language().isEmpty()) // explicit language setting
{
lang = s->language();
}
SrcLangExt langExt = getLanguageFromFileName(lang);
switch(s->type())
{
case DocVerbatim::Code: // fall though
m_t << "{" << endl;
m_t << "\\par" << endl;
m_t << rtf_Style_Reset << getStyle("CodeExample");
Doxygen::parserManager->getParser(lang)
->parseCode(m_ci,s->context(),s->text(),langExt,
s->isExample(),s->exampleFile());
//m_t << "\\par" << endl;
m_t << "}" << endl;
break;
case DocVerbatim::Verbatim:
m_t << "{" << endl;
m_t << "\\par" << endl;
m_t << rtf_Style_Reset << getStyle("CodeExample");
filter(s->text(),TRUE);
//m_t << "\\par" << endl;
m_t << "}" << endl;
break;
case DocVerbatim::RtfOnly:
m_t << s->text();
break;
case DocVerbatim::HtmlOnly:
case DocVerbatim::LatexOnly:
case DocVerbatim::XmlOnly:
case DocVerbatim::ManOnly:
case DocVerbatim::DocbookOnly:
/* nothing */
break;
case DocVerbatim::Dot:
{
static int dotindex = 1;
QCString fileName(4096);
fileName.sprintf("%s%d%s",
(Config_getString(RTF_OUTPUT)+"/inline_dotgraph_").data(),
dotindex++,
".dot"
);
QFile file(fileName);
if (!file.open(IO_WriteOnly))
{
err("Could not open file %s for writing\n",fileName.data());
}
file.writeBlock( s->text(), s->text().length() );
file.close();
writeDotFile(fileName, s->hasCaption());
visitCaption(this, s->children());
includePicturePostRTF(true, s->hasCaption());
if (Config_getBool(DOT_CLEANUP)) file.remove();
}
break;
case DocVerbatim::Msc:
{
static int mscindex = 1;
QCString baseName(4096);
baseName.sprintf("%s%d%s",
(Config_getString(RTF_OUTPUT)+"/inline_mscgraph_").data(),
mscindex++,
".msc"
);
QFile file(baseName);
if (!file.open(IO_WriteOnly))
{
err("Could not open file %s for writing\n",baseName.data());
}
QCString text = "msc {";
text+=s->text();
text+="}";
file.writeBlock( text, text.length() );
file.close();
writeMscFile(baseName, s->hasCaption());
visitCaption(this, s->children());
includePicturePostRTF(true, s->hasCaption());
if (Config_getBool(DOT_CLEANUP)) file.remove();
}
break;
case DocVerbatim::PlantUML:
{
static QCString rtfOutput = Config_getString(RTF_OUTPUT);
QCString baseName = writePlantUMLSource(rtfOutput,s->exampleFile(),s->text());
writePlantUMLFile(baseName, s->hasCaption());
visitCaption(this, s->children());
//.........这里部分代码省略.........
开发者ID:wufengyi,项目名称:doxygen,代码行数:101,代码来源:rtfdocvisitor.cpp
示例15: init_config
static void
init_config(struct cfg *cf, int argc, char **argv)
{
int ch, i, umode, stdio_mode;
char *bh[2], *bh6[2], *cp, *tp[2];
const char *errmsg;
struct passwd *pp;
struct group *gp;
double x, y;
struct rtpp_ctrl_sock *ctrl_sock;
bh[0] = bh[1] = bh6[0] = bh6[1] = NULL;
umode = stdio_mode = 0;
cf->stable->pid_file = PID_FILE;
cf->stable->port_min = PORT_MIN;
cf->stable->port_max = PORT_MAX;
cf->stable->port_ctl = 0;
cf->stable->advaddr[0] = NULL;
cf->stable->advaddr[1] = NULL;
cf->stable->max_ttl = SESSION_TIMEOUT;
cf->stable->tos = TOS;
cf->stable->rrtcp = 1;
cf->stable->ttl_mode = TTL_UNIFIED;
cf->stable->log_level = -1;
cf->stable->log_facility = -1;
cf->stable->sched_offset = 0.0;
cf->stable->sched_hz = rtpp_get_sched_hz();
cf->stable->sched_policy = SCHED_OTHER;
cf->stable->target_pfreq = MIN(POLL_RATE, cf->stable->sched_hz);
#if RTPP_DEBUG
printf("target_pfreq = %f\n", cf->stable->target_pfreq);
#endif
cf->stable->slowshutdown = 0;
cf->timeout_handler = rtpp_th_init();
if (cf->timeout_handler == NULL)
err(1, "rtpp_th_init");
pthread_mutex_init(&cf->glock, NULL);
pthread_mutex_init(&cf->sessinfo.lock, NULL);
pthread_mutex_init(&cf->bindaddr_lock, NULL);
cf->stable->nofile_limit = malloc(sizeof(*cf->stable->nofile_limit));
if (cf->stable->nofile_limit == NULL)
err(1, "malloc");
if (getrlimit(RLIMIT_NOFILE, cf->stable->nofile_limit) != 0)
err(1, "getrlimit");
while ((ch = getopt(argc, argv, "vf2Rl:6:s:S:t:r:p:T:L:m:M:u:Fin:Pad:VN:c:A:")) != -1) {
switch (ch) {
case 'c':
if (strcmp(optarg, "fifo") == 0) {
cf->stable->sched_policy = SCHED_FIFO;
break;
}
if (strcmp(optarg, "rr") == 0) {
cf->stable->sched_policy = SCHED_RR;
break;
}
errx(1, "%s: unknown scheduling policy", optarg);
break;
case 'N':
if (strcmp(optarg, "random") == 0) {
x = getdtime() * 1000000.0;
srand48((long)x);
cf->stable->sched_offset = drand48();
} else {
tp[0] = optarg;
tp[1] = strchr(tp[0], '/');
if (tp[1] == NULL) {
errx(1, "%s: -N should be in the format X/Y", optarg);
}
*tp[1] = '\0';
tp[1]++;
x = (double)strtol(tp[0], &tp[0], 10);
y = (double)strtol(tp[1], &tp[1], 10);
cf->stable->sched_offset = x / y;
}
x = (double)cf->stable->sched_hz / cf->stable->target_pfreq;
cf->stable->sched_offset = trunc(x * cf->stable->sched_offset) / x;
cf->stable->sched_offset /= cf->stable->target_pfreq;
warnx("sched_offset = %f", cf->stable->sched_offset);
break;
case 'f':
cf->stable->nodaemon = 1;
break;
case 'l':
bh[0] = optarg;
bh[1] = strchr(bh[0], '/');
if (bh[1] != NULL) {
*bh[1] = '\0';
bh[1]++;
//.........这里部分代码省略.........
开发者ID:yzy5768,项目名称:rtpproxy,代码行数:101,代码来源:main.c
示例16: slip_config_handle_arguments
//.........这里部分代码省略.........
break;
case 'r':
use_raw_ethernet = 1;
break;
case 'R':
use_raw_ethernet = 0;
break;
case 'f':
ethernet_has_fcs = 1;
break;
case 'U':
slip_config_ifup_script = optarg;
break;
case 'D':
slip_config_ifdown_script = optarg;
break;
case 'w':
slip_config_www_root = optarg;
break;
case 'v':
printf("Warning: -v option is deprecated, use -L and -S instead\n");
break;
case '?':
case 'h':
default:
fprintf(stderr, "usage: %s [options] ipaddress\n", prog);
fprintf(stderr, "example: %s -L -v2 -s ttyUSB1\n", prog);
fprintf(stderr, "Options are:\n");
#ifdef linux
fprintf(stderr,
" -B baudrate 9600,19200,38400,57600,115200,921600 (default 115200)\n");
#else
fprintf(stderr,
" -B baudrate 9600,19200,38400,57600,115200 (default 115200)\n");
#endif
fprintf(stderr,
" -H Hardware CTS/RTS flow control (default disabled)\n");
fprintf(stderr,
" -s siodev Serial device (default /dev/ttyUSB0)\n");
fprintf(stderr,
" -a host Connect via TCP to server at <host>\n");
fprintf(stderr,
" -p port Connect via TCP to server at <host>:<port>\n");
fprintf(stderr, " -t dev Name of interface (default eth0)\n");
fprintf(stderr, " -r Use Raw Ethernet interface\n");
fprintf(stderr, " -R Use Tap Ethernet interface\n");
fprintf(stderr, " -f Raw Ethernet frames contains FCS\n");
fprintf(stderr,
" -d[basedelay] Minimum delay between outgoing SLIP packets.\n");
fprintf(stderr,
" Actual delay is basedelay*(#6LowPAN fragments) milliseconds.\n");
fprintf(stderr, " -d is equivalent to -d10.\n");
fprintf(stderr, " -L[level] Log level\n");
fprintf(stderr, " -S[services] Log services\n");
fprintf(stderr, " -c conf Configuration file (nvm file)\n");
fprintf(stderr, " -U script Interface up configuration script\n");
fprintf(stderr,
" -D script Interface down configuration script\n");
开发者ID:TiagoLourenco,项目名称:6lbr,代码行数:67,代码来 |
请发表评论