本文整理汇总了C++中optget函数的典型用法代码示例。如果您正苦于以下问题:C++ optget函数的具体用法?C++ optget怎么用?C++ optget使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了optget函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: b_command
/*
* command is called with argc==0 when checking for -V or -v option
* In this case return 0 when -v or -V or unknown option, otherwise
* the shift count to the command is returned
*/
int b_command(register int argc,char *argv[],Shbltin_t *context)
{
register int n, flags=0;
register Shell_t *shp = context->shp;
opt_info.index = opt_info.offset = 0;
while((n = optget(argv,sh_optcommand))) switch(n)
{
case 'p':
if(sh_isoption(SH_RESTRICTED))
errormsg(SH_DICT,ERROR_exit(1),e_restricted,"-p");
sh_onstate(SH_DEFPATH);
break;
case 'v':
flags |= X_FLAG;
break;
case 'V':
flags |= V_FLAG;
break;
case 'x':
shp->xargexit = 1;
break;
case ':':
if(argc==0)
return(0);
errormsg(SH_DICT,2, "%s", opt_info.arg);
break;
case '?':
if(argc==0)
return(0);
errormsg(SH_DICT,ERROR_usage(2), "%s", opt_info.arg);
break;
}
if(argc==0)
return(flags?0:opt_info.index);
argv += opt_info.index;
if(error_info.errors || !*argv)
errormsg(SH_DICT,ERROR_usage(2),"%s", optusage((char*)0));
return(whence(shp,argv, flags));
}
示例2: b_basename
int
b_basename(int argc,register char *argv[], void* context)
{
register int n;
cmdinit(argc, argv, context, ERROR_CATALOG, 0);
while (n = optget(argv, usage)) switch (n)
{
case ':':
error(2, "%s", opt_info.arg);
break;
case '?':
error(ERROR_usage(2), "%s", opt_info.arg);
break;
}
argv += opt_info.index;
argc -= opt_info.index;
if(error_info.errors || argc < 1 || argc > 2)
error(ERROR_usage(2), "%s", optusage(NiL));
namebase(sfstdout,argv[0],argv[1]);
return(0);
}
示例3: onas_fan_checkowner
int
onas_fan_checkowner (int pid, const struct optstruct *opts)
{
char path[32];
STATBUF sb;
const struct optstruct *opt;
if (!(opt = optget (opts, "OnAccessExcludeUID"))->enabled)
return 0;
snprintf (path, sizeof (path), "/proc/%u", pid);
if (CLAMSTAT (path, &sb) == 0)
{
while (opt)
{
if (opt->numarg == (long long) sb.st_uid)
return 1;
opt = opt->nextarg;
}
}
return 0;
}
示例4: b_basename
int
b_basename(int argc, register char** argv, Shbltin_t* context)
{
char* string;
char* suffix = 0;
int all = 0;
cmdinit(argc, argv, context, ERROR_CATALOG, 0);
for (;;)
{
switch (optget(argv, usage))
{
case 'a':
all = 1;
continue;
case 's':
all = 1;
suffix = opt_info.arg;
continue;
case ':':
error(2, "%s", opt_info.arg);
break;
case '?':
error(ERROR_usage(2), "%s", opt_info.arg);
break;
}
break;
}
argv += opt_info.index;
argc -= opt_info.index;
if (error_info.errors || argc < 1 || !all && argc > 2)
error(ERROR_usage(2), "%s", optusage(NiL));
if (!all)
namebase(sfstdout, argv[0], argv[1]);
else
while (string = *argv++)
namebase(sfstdout, string, suffix);
return 0;
}
示例5: b_exec
//
// Builtin `exec`.
//
int b_exec(int argc, char *argv[], Shbltin_t *context) {
UNUSED(argc);
struct login logdata;
int n;
logdata.clear = 0;
logdata.arg0 = NULL;
logdata.sh = context->shp;
logdata.sh->st.ioset = 0;
while ((n = optget(argv, sh_optexec))) {
switch (n) {
case 'a': {
logdata.arg0 = opt_info.arg;
break;
}
case 'c': {
logdata.clear = 1;
break;
}
case ':': {
errormsg(SH_DICT, 2, "%s", opt_info.arg);
break;
}
case '?': {
errormsg(SH_DICT, ERROR_usage(0), "%s", opt_info.arg);
return 2;
}
default: { break; }
}
}
argv += opt_info.index;
if (error_info.errors) {
errormsg(SH_DICT, ERROR_usage(2), "%s", optusage(NULL));
__builtin_unreachable();
}
if (*argv) B_login(0, argv, (Shbltin_t *)&logdata);
return 0;
}
示例6: milter_exit
static void milter_exit(int sig) {
const struct optstruct *opt;
logg("*clamav-milter: milter_exit, signal %d\n", sig);
#ifndef _WIN32
if((opt = optget(opts, "MilterSocket"))) {
if(unlink(opt->strarg) == -1)
logg("!Can't unlink the socket file %s\n", opt->strarg);
else
logg("Socket file removed.\n");
}
#endif
logg("clamav-milter: stopped\n");
optfree(opts);
logg_close();
cpool_free();
localnets_free();
whitelist_free();
}
示例7: b_whence
/*
* for the whence command
*/
int b_whence(int argc,char *argv[],Shbltin_t *context)
{
register int flags=0, n;
register Shell_t *shp = context->shp;
NOT_USED(argc);
if(*argv[0]=='t')
flags = V_FLAG;
while((n = optget(argv,sh_optwhence))) switch(n)
{
case 'a':
flags |= A_FLAG;
/* FALL THRU */
case 'v':
flags |= V_FLAG;
break;
case 'f':
flags |= F_FLAG;
break;
case 'p':
flags |= P_FLAG;
flags &= ~V_FLAG;
break;
case 'q':
flags |= Q_FLAG;
break;
case ':':
errormsg(SH_DICT,2, "%s", opt_info.arg);
break;
case '?':
errormsg(SH_DICT,ERROR_usage(2), "%s", opt_info.arg);
break;
}
argv += opt_info.index;
if(error_info.errors || !*argv)
errormsg(SH_DICT,ERROR_usage(2),optusage((char*)0));
return(whence(shp, argv, flags));
}
示例8: clamd_virus_found_cb
void clamd_virus_found_cb(int fd, const char *virname, void *ctx)
{
struct cb_context *c = ctx;
struct scan_cb_data *d = c->scandata;
const char *fname;
if (d == NULL)
return;
if (!(d->options & CL_SCAN_ALLMATCHES))
return;
if (virname == NULL)
return;
fname = (c && c->filename) ? c->filename : "(filename not set)";
if (virname) {
conn_reply_virus(d->conn, fname, virname);
if(c->virsize > 0 && optget(d->opts, "ExtendedDetectionInfo")->enabled)
logg("~%s: %s(%s:%llu) FOUND\n", fname, virname, c->virhash, c->virsize);
logg("~%s: %s FOUND\n", fname, virname);
}
return;
}
示例9: b_eval
int b_eval(int argc,char *argv[], void *extra)
{
register int r;
register Shell_t *shp = ((Shbltin_t*)extra)->shp;
NOT_USED(argc);
while (r = optget(argv,sh_opteval)) switch (r)
{
case ':':
errormsg(SH_DICT,2, "%s", opt_info.arg);
break;
case '?':
errormsg(SH_DICT,ERROR_usage(0), "%s",opt_info.arg);
return(2);
}
if(error_info.errors)
errormsg(SH_DICT,ERROR_usage(2),"%s",optusage((char*)0));
argv += opt_info.index;
if(*argv && **argv)
{
sh_offstate(SH_MONITOR);
sh_eval(sh_sfeval(argv),0);
}
return(shp->exitval);
}
示例10: localserver
int localserver(const struct optstruct *opts)
{
struct sockaddr_un server;
int sockfd, backlog;
STATBUF foo;
char *estr;
memset((char *) &server, 0, sizeof(server));
server.sun_family = AF_UNIX;
strncpy(server.sun_path, optget(opts, "LocalSocket")->strarg, sizeof(server.sun_path));
server.sun_path[sizeof(server.sun_path)-1]='\0';
if((sockfd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
estr = strerror(errno);
logg("!LOCAL: Socket allocation error: %s\n", estr);
return -1;
}
if(bind(sockfd, (struct sockaddr *) &server, sizeof(struct sockaddr_un)) == -1) {
if(errno == EADDRINUSE) {
if(connect(sockfd, (struct sockaddr *) &server, sizeof(struct sockaddr_un)) >= 0) {
logg("!LOCAL: Socket file %s is in use by another process.\n", server.sun_path);
close(sockfd);
return -1;
}
if(optget(opts, "FixStaleSocket")->enabled) {
logg("#LOCAL: Removing stale socket file %s\n", server.sun_path);
if(unlink(server.sun_path) == -1) {
estr = strerror(errno);
logg("!LOCAL: Socket file %s could not be removed: %s\n", server.sun_path, estr);
close(sockfd);
return -1;
}
if(bind(sockfd, (struct sockaddr *) &server, sizeof(struct sockaddr_un)) == -1) {
estr = strerror(errno);
logg("!LOCAL: Socket file %s could not be bound: %s (unlink tried)\n", server.sun_path, estr);
close(sockfd);
return -1;
}
} else if(CLAMSTAT(server.sun_path, &foo) != -1) {
logg("!LOCAL: Socket file %s exists. Either remove it, or configure a different one.\n", server.sun_path);
close(sockfd);
return -1;
}
} else {
estr = strerror(errno);
logg("!LOCAL: Socket file %s could not be bound: %s\n", server.sun_path, estr);
close(sockfd);
return -1;
}
}
logg("#LOCAL: Unix socket file %s\n", server.sun_path);
backlog = optget(opts, "MaxConnectionQueueLength")->numarg;
logg("#LOCAL: Setting connection queue length to %d\n", backlog);
if(listen(sockfd, backlog) == -1) {
estr = strerror(errno);
logg("!LOCAL: listen() error: %s\n", estr);
close(sockfd);
return -1;
}
return sockfd;
}
示例11: command
/* returns
* -1 on fatal error (shutdown)
* 0 on ok
* >0 errors encountered
*/
int command(client_conn_t *conn, int *virus)
{
int desc = conn->sd;
struct cl_engine *engine = conn->engine;
unsigned int options = conn->options;
const struct optstruct *opts = conn->opts;
int type = -1; /* TODO: make this enum */
int maxdirrec;
int ret = 0;
int flags = CLI_FTW_STD;
struct scan_cb_data scandata;
struct cli_ftw_cbdata data;
unsigned ok, error, total;
STATBUF sb;
jobgroup_t *group = NULL;
if (thrmgr_group_need_terminate(conn->group)) {
logg("$Client disconnected while command was active\n");
if (conn->scanfd != -1)
close(conn->scanfd);
return 1;
}
thrmgr_setactiveengine(engine);
data.data = &scandata;
memset(&scandata, 0, sizeof(scandata));
scandata.id = conn->id;
scandata.group = conn->group;
scandata.odesc = desc;
scandata.conn = conn;
scandata.options = options;
scandata.engine = engine;
scandata.opts = opts;
scandata.thr_pool = conn->thrpool;
scandata.toplevel_path = conn->filename;
switch (conn->cmdtype) {
case COMMAND_SCAN:
thrmgr_setactivetask(NULL, "SCAN");
type = TYPE_SCAN;
break;
case COMMAND_CONTSCAN:
thrmgr_setactivetask(NULL, "CONTSCAN");
type = TYPE_CONTSCAN;
break;
case COMMAND_MULTISCAN: {
int multiscan, max, alive;
/* use MULTISCAN only for directories (bb #1869) */
if (STAT(conn->filename, &sb) == 0 &&
!S_ISDIR(sb.st_mode)) {
thrmgr_setactivetask(NULL, "CONTSCAN");
type = TYPE_CONTSCAN;
break;
}
pthread_mutex_lock(&conn->thrpool->pool_mutex);
multiscan = conn->thrpool->thr_multiscan;
max = conn->thrpool->thr_max;
if (multiscan+1 < max)
conn->thrpool->thr_multiscan = multiscan+1;
else {
alive = conn->thrpool->thr_alive;
ret = -1;
}
pthread_mutex_unlock(&conn->thrpool->pool_mutex);
if (ret) {
/* multiscan has 1 control thread, so there needs to be at least
1 threads that is a non-multiscan controlthread to scan and
make progress. */
logg("^Not enough threads for multiscan. Max: %d, Alive: %d, Multiscan: %d+1\n",
max, alive, multiscan);
conn_reply(conn, conn->filename, "Not enough threads for multiscan. Increase MaxThreads.", "ERROR");
return 1;
}
flags &= ~CLI_FTW_NEED_STAT;
thrmgr_setactivetask(NULL, "MULTISCAN");
type = TYPE_MULTISCAN;
scandata.group = group = thrmgr_group_new();
if (!group) {
if(optget(opts, "ExitOnOOM")->enabled)
return -1;
else
return 1;
}
break;
}
case COMMAND_MULTISCANFILE:
thrmgr_setactivetask(NULL, "MULTISCANFILE");
scandata.group = NULL;
scandata.type = TYPE_SCAN;
scandata.thr_pool = NULL;
/* TODO: check ret value */
ret = scan_callback(NULL, conn->filename, conn->filename, visit_file, &data); /* callback freed it */
//.........这里部分代码省略.........
示例12: execute_or_dispatch_command
/* returns:
* <0 for error
* -1 out of memory
* -2 other
* 0 for async dispatched
* 1 for command completed (connection can be closed)
*/
int execute_or_dispatch_command(client_conn_t *conn, enum commands cmd, const char *argument)
{
int desc = conn->sd;
char term = conn->term;
const struct cl_engine *engine = conn->engine;
/* execute commands that can be executed quickly on the recvloop thread,
* these must:
* - not involve any operation that can block for a long time, such as disk
* I/O
* - send of atomic message is allowed.
* Dispatch other commands */
if (conn->group) {
switch (cmd) {
case COMMAND_FILDES:
case COMMAND_SCAN:
case COMMAND_END:
case COMMAND_INSTREAM:
case COMMAND_INSTREAMSCAN:
case COMMAND_VERSION:
case COMMAND_PING:
case COMMAND_STATS:
case COMMAND_COMMANDS:
/* These commands are accepted inside IDSESSION */
break;
default:
/* these commands are not recognized inside an IDSESSION */
conn_reply_error(conn, "Command invalid inside IDSESSION.");
logg("$SESSION: command is not valid inside IDSESSION: %d\n", cmd);
conn->group = NULL;
return 1;
}
}
switch (cmd) {
case COMMAND_SHUTDOWN:
pthread_mutex_lock(&exit_mutex);
progexit = 1;
pthread_mutex_unlock(&exit_mutex);
return 1;
case COMMAND_RELOAD:
pthread_mutex_lock(&reload_mutex);
reload = 1;
pthread_mutex_unlock(&reload_mutex);
mdprintf(desc, "RELOADING%c", term);
/* we set reload flag, and we'll reload before closing the
* connection */
return 1;
case COMMAND_PING:
if (conn->group)
mdprintf(desc, "%u: PONG%c", conn->id, term);
else
mdprintf(desc, "PONG%c", term);
return conn->group ? 0 : 1;
case COMMAND_VERSION:
{
if (conn->group)
mdprintf(desc, "%u: ", conn->id);
print_ver(desc, conn->term, engine);
return conn->group ? 0 : 1;
}
case COMMAND_COMMANDS:
{
if (conn->group)
mdprintf(desc, "%u: ", conn->id);
print_commands(desc, conn->term, engine);
return conn->group ? 0 : 1;
}
case COMMAND_DETSTATSCLEAR:
{
detstats_clear();
return 1;
}
case COMMAND_DETSTATS:
{
detstats_print(desc, conn->term);
return 1;
}
case COMMAND_INSTREAM:
{
int rc = cli_gentempfd(optget(conn->opts, "TemporaryDirectory")->strarg, &conn->filename, &conn->scanfd);
if (rc != CL_SUCCESS)
return rc;
conn->quota = optget(conn->opts, "StreamMaxLength")->numarg;
conn->mode = MODE_STREAM;
return 0;
}
case COMMAND_STREAM:
case COMMAND_MULTISCAN:
case COMMAND_CONTSCAN:
case COMMAND_STATS:
case COMMAND_FILDES:
case COMMAND_SCAN:
case COMMAND_INSTREAMSCAN:
//.........这里部分代码省略.........
示例13: b_cut
int
b_cut(int argc, char** argv, void* context)
{
register char* cp = 0;
register Sfio_t* fp;
char* s;
int n;
Cut_t* cut;
int mode = 0;
Delim_t wdelim;
Delim_t ldelim;
size_t reclen = 0;
cmdinit(argc, argv, context, ERROR_CATALOG, 0);
wdelim.chr = '\t';
ldelim.chr = '\n';
wdelim.len = ldelim.len = 1;
for (;;)
{
switch (n = optget(argv, usage))
{
case 0:
break;
case 'b':
case 'c':
if(mode&C_FIELDS)
{
error(2, "f option already specified");
continue;
}
cp = opt_info.arg;
if(n=='b')
mode |= C_BYTES;
else
mode |= C_CHARS;
continue;
case 'D':
ldelim.str = opt_info.arg;
if (mbwide())
{
s = opt_info.arg;
ldelim.chr = mbchar(s);
if ((n = s - opt_info.arg) > 1)
{
ldelim.len = n;
continue;
}
}
ldelim.chr = *(unsigned char*)opt_info.arg;
ldelim.len = 1;
continue;
case 'd':
wdelim.str = opt_info.arg;
if (mbwide())
{
s = opt_info.arg;
wdelim.chr = mbchar(s);
if ((n = s - opt_info.arg) > 1)
{
wdelim.len = n;
continue;
}
}
wdelim.chr = *(unsigned char*)opt_info.arg;
wdelim.len = 1;
continue;
case 'f':
if(mode&(C_CHARS|C_BYTES))
{
error(2, "c option already specified");
continue;
}
cp = opt_info.arg;
mode |= C_FIELDS;
continue;
case 'n':
mode |= C_NOSPLIT;
continue;
case 'N':
mode |= C_NONEWLINE;
continue;
case 'R':
case 'r':
if(opt_info.num>0)
reclen = opt_info.num;
continue;
case 's':
mode |= C_SUPRESS;
continue;
case ':':
error(2, "%s", opt_info.arg);
break;
case '?':
error(ERROR_usage(2), "%s", opt_info.arg);
break;
}
break;
}
argv += opt_info.index;
if (error_info.errors)
//.........这里部分代码省略.........
示例14: b_mktemp
int
b_mktemp(int argc, char** argv, Shbltin_t* context)
{
mode_t mode = 0;
mode_t mask;
int fd;
int i;
int quiet = 0;
int unsafe = 0;
int* fdp = &fd;
char* dir = "";
char* pfx;
char* t;
char path[PATH_MAX];
cmdinit(argc, argv, context, ERROR_CATALOG, ERROR_NOTIFY);
for (;;)
{
switch (optget(argv, usage))
{
case 'd':
fdp = 0;
continue;
case 'm':
mode = strperm(pfx = opt_info.arg, &opt_info.arg, S_IRWXU);
if (*opt_info.arg)
error(ERROR_exit(0), "%s: invalid mode", pfx);
continue;
case 'p':
if ((t = getenv("TMPDIR")) && *t)
dir = 0;
else
dir = opt_info.arg;
continue;
case 'q':
quiet = 1;
continue;
case 't':
dir = 0;
continue;
case 'u':
unsafe = 1;
fdp = 0;
continue;
case 'R':
if (!pathtemp(NiL, 0, opt_info.arg, "/seed", NiL))
error(2, "%s: regression test initializtion failed", opt_info.arg);
continue;
case ':':
error(2, "%s", opt_info.arg);
break;
case '?':
error(ERROR_usage(2), "%s", opt_info.arg);
break;
}
break;
}
argv += opt_info.index;
if (error_info.errors || (pfx = *argv++) && *argv)
error(ERROR_usage(2), "%s", optusage(NiL));
mask = umask(0);
if (!mode)
mode = (fdp ? (S_IRUSR|S_IWUSR) : S_IRWXU) & ~mask;
umask(~mode & (S_IRWXU|S_IRWXG|S_IRWXO));
if (!pfx)
{
pfx = "tmp_";
if (dir && !*dir)
dir = 0;
}
if (t = strrchr(pfx, '/'))
{
i = ++t - pfx;
dir = fmtbuf(i);
memcpy(dir, pfx, i);
dir[i] = 0;
pfx = t;
}
for (;;)
{
if (!pathtemp(path, sizeof(path), dir, pfx, fdp))
{
if (quiet)
error_info.errors++;
else
error(ERROR_SYSTEM|2, "cannot create temporary path");
break;
}
if (fdp || unsafe || !mkdir(path, mode))
{
if (fdp)
close(*fdp);
sfputr(sfstdout, path, '\n');
break;
}
if (sh_checksig(context))
{
error_info.errors++;
break;
}
//.........这里部分代码省略.........
示例15: client
int client(const struct optstruct *opts, int *infected, int *err)
{
int remote, scantype, session = 0, errors = 0, scandash = 0, maxrec, flags = 0;
const char *fname;
scandash = (opts->filename && opts->filename[0] && !strcmp(opts->filename[0], "-") && !optget(opts, "file-list")->enabled && !opts->filename[1]);
remote = isremote(opts) | optget(opts, "stream")->enabled;
#ifdef HAVE_FD_PASSING
if(!remote && optget(clamdopts, "LocalSocket")->enabled && (optget(opts, "fdpass")->enabled || scandash)) {
scantype = FILDES;
session = optget(opts, "multiscan")->enabled;
} else
#endif
if(remote || scandash) {
scantype = STREAM;
session = optget(opts, "multiscan")->enabled;
}
else if(optget(opts, "multiscan")->enabled) scantype = MULTI;
else if(optget(opts, "allmatch")->enabled) scantype = ALLMATCH;
else scantype = CONT;
maxrec = optget(clamdopts, "MaxDirectoryRecursion")->numarg;
maxstream = optget(clamdopts, "StreamMaxLength")->numarg;
if (optget(clamdopts, "FollowDirectorySymlinks")->enabled)
flags |= CLI_FTW_FOLLOW_DIR_SYMLINK;
if (optget(clamdopts, "FollowFileSymlinks")->enabled)
flags |= CLI_FTW_FOLLOW_FILE_SYMLINK;
flags |= CLI_FTW_TRIM_SLASHES;
*infected = 0;
if(scandash) {
int sockd, ret;
STATBUF sb;
if(FSTAT(0, &sb) < 0) {
logg("client.c: fstat failed for file name \"%s\", with %s\n.",
opts->filename[0], strerror(errno));
return 2;
}
if((sb.st_mode & S_IFMT) != S_IFREG) scantype = STREAM;
if((sockd = dconnect()) >= 0 && (ret = dsresult(sockd, scantype, NULL, &ret, NULL)) >= 0)
*infected = ret;
else
errors = 1;
if(sockd >= 0) closesocket(sockd);
} else if(opts->filename || optget(opts, "file-list")->enabled) {
if(opts->filename && optget(opts, "file-list")->enabled)
logg("^Only scanning files from --file-list (files passed at cmdline are ignored)\n");
while((fname = filelist(opts, NULL))) {
if(!strcmp(fname, "-")) {
logg("!Scanning from standard input requires \"-\" to be the only file argument\n");
continue;
}
errors += client_scan(fname, scantype, infected, err, maxrec, session, flags);
/* this may be too strict
if(errors >= 10) {
logg("!Too many errors\n");
break;
}
*/
}
} else {
errors = client_scan("", scantype, infected, err, maxrec, session, flags);
}
return *infected ? 1 : (errors ? 2 : 0);
}