本文整理汇总了C++中STREQ函数的典型用法代码示例。如果您正苦于以下问题:C++ STREQ函数的具体用法?C++ STREQ怎么用?C++ STREQ使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了STREQ函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: virPidFileReadPathIfAlive
/**
* virPidFileReadPathIfAlive:
* @path: path to pidfile
* @pid: variable to return pid in
* @binpath: path of executable associated with the pidfile
*
* This will attempt to read a pid from @path, and store it
* in @pid. The @pid will only be set, however, if the
* pid in @path is running, and its executable path
* resolves to @binpath. This adds protection against
* recycling of previously reaped pids.
*
* If @binpath is NULL the check for the executable path
* is skipped.
*
* Returns -errno upon error, or zero on successful
* reading of the pidfile. If the PID was not still
* alive, zero will be returned, but @pid will be
* set to -1.
*/
int virPidFileReadPathIfAlive(const char *path,
pid_t *pid,
const char *binPath)
{
int ret;
bool isLink;
char *procPath = NULL;
char *procLink = NULL;
size_t procLinkLen;
char *resolvedBinPath = NULL;
char *resolvedProcLink = NULL;
const char deletedText[] = " (deleted)";
size_t deletedTextLen = strlen(deletedText);
pid_t retPid;
/* only set this at the very end on success */
*pid = -1;
if ((ret = virPidFileReadPath(path, &retPid)) < 0)
goto cleanup;
#ifndef WIN32
/* Check that it's still alive. Safe to skip this sanity check on
* mingw, which lacks kill(). */
if (kill(retPid, 0) < 0) {
ret = 0;
retPid = -1;
goto cleanup;
}
#endif
if (!binPath) {
/* we only knew the pid, and that pid is alive, so we can
* return it.
*/
ret = 0;
goto cleanup;
}
if (virAsprintf(&procPath, "/proc/%lld/exe", (long long)retPid) < 0) {
ret = -ENOMEM;
goto cleanup;
}
if ((ret = virFileIsLink(procPath)) < 0)
goto cleanup;
isLink = ret;
if (isLink && virFileLinkPointsTo(procPath, binPath)) {
/* the link in /proc/$pid/exe is a symlink to a file
* that has the same inode as the file at binpath.
*/
ret = 0;
goto cleanup;
}
/* Even if virFileLinkPointsTo returns a mismatch, it could be
* that the binary was deleted/replaced after it was executed. In
* that case the link in /proc/$pid/exe will contain
* "$procpath (deleted)". Read that link, remove the " (deleted)"
* part, and see if it has the same canonicalized name as binpath.
*/
if (!(procLink = areadlink(procPath))) {
ret = -errno;
goto cleanup;
}
procLinkLen = strlen(procLink);
if (procLinkLen > deletedTextLen)
procLink[procLinkLen - deletedTextLen] = 0;
if ((ret = virFileResolveAllLinks(binPath, &resolvedBinPath)) < 0)
goto cleanup;
if ((ret = virFileResolveAllLinks(procLink, &resolvedProcLink)) < 0)
goto cleanup;
ret = STREQ(resolvedBinPath, resolvedProcLink) ? 0 : -1;
cleanup:
VIR_FREE(procPath);
VIR_FREE(procLink);
//.........这里部分代码省略.........
示例2: virCapabilitiesFormatXML
//.........这里部分代码省略.........
virBufferAdjustIndent(&buf, -2);
virBufferAddLit(&buf, "</host>\n\n");
for (i = 0; i < caps->nguests; i++) {
virBufferAddLit(&buf, "<guest>\n");
virBufferAdjustIndent(&buf, 2);
virBufferAsprintf(&buf, "<os_type>%s</os_type>\n",
virDomainOSTypeToString(caps->guests[i]->ostype));
if (caps->guests[i]->arch.id)
virBufferAsprintf(&buf, "<arch name='%s'>\n",
virArchToString(caps->guests[i]->arch.id));
virBufferAdjustIndent(&buf, 2);
virBufferAsprintf(&buf, "<wordsize>%d</wordsize>\n",
caps->guests[i]->arch.wordsize);
if (caps->guests[i]->arch.defaultInfo.emulator)
virBufferAsprintf(&buf, "<emulator>%s</emulator>\n",
caps->guests[i]->arch.defaultInfo.emulator);
if (caps->guests[i]->arch.defaultInfo.loader)
virBufferAsprintf(&buf, "<loader>%s</loader>\n",
caps->guests[i]->arch.defaultInfo.loader);
for (j = 0; j < caps->guests[i]->arch.defaultInfo.nmachines; j++) {
virCapsGuestMachinePtr machine = caps->guests[i]->arch.defaultInfo.machines[j];
virBufferAddLit(&buf, "<machine");
if (machine->canonical)
virBufferAsprintf(&buf, " canonical='%s'", machine->canonical);
if (machine->maxCpus > 0)
virBufferAsprintf(&buf, " maxCpus='%d'", machine->maxCpus);
virBufferAsprintf(&buf, ">%s</machine>\n", machine->name);
}
for (j = 0; j < caps->guests[i]->arch.ndomains; j++) {
virBufferAsprintf(&buf, "<domain type='%s'",
virDomainVirtTypeToString(caps->guests[i]->arch.domains[j]->type));
if (!caps->guests[i]->arch.domains[j]->info.emulator &&
!caps->guests[i]->arch.domains[j]->info.loader &&
!caps->guests[i]->arch.domains[j]->info.nmachines) {
virBufferAddLit(&buf, "/>\n");
continue;
}
virBufferAddLit(&buf, ">\n");
virBufferAdjustIndent(&buf, 2);
if (caps->guests[i]->arch.domains[j]->info.emulator)
virBufferAsprintf(&buf, "<emulator>%s</emulator>\n",
caps->guests[i]->arch.domains[j]->info.emulator);
if (caps->guests[i]->arch.domains[j]->info.loader)
virBufferAsprintf(&buf, "<loader>%s</loader>\n",
caps->guests[i]->arch.domains[j]->info.loader);
for (k = 0; k < caps->guests[i]->arch.domains[j]->info.nmachines; k++) {
virCapsGuestMachinePtr machine = caps->guests[i]->arch.domains[j]->info.machines[k];
virBufferAddLit(&buf, "<machine");
if (machine->canonical)
virBufferAsprintf(&buf, " canonical='%s'", machine->canonical);
if (machine->maxCpus > 0)
virBufferAsprintf(&buf, " maxCpus='%d'", machine->maxCpus);
virBufferAsprintf(&buf, ">%s</machine>\n", machine->name);
}
virBufferAdjustIndent(&buf, -2);
virBufferAddLit(&buf, "</domain>\n");
}
virBufferAdjustIndent(&buf, -2);
virBufferAddLit(&buf, "</arch>\n");
if (caps->guests[i]->nfeatures) {
virBufferAddLit(&buf, "<features>\n");
virBufferAdjustIndent(&buf, 2);
for (j = 0; j < caps->guests[i]->nfeatures; j++) {
if (STREQ(caps->guests[i]->features[j]->name, "pae") ||
STREQ(caps->guests[i]->features[j]->name, "nonpae") ||
STREQ(caps->guests[i]->features[j]->name, "ia64_be") ||
STREQ(caps->guests[i]->features[j]->name, "cpuselection") ||
STREQ(caps->guests[i]->features[j]->name, "deviceboot")) {
virBufferAsprintf(&buf, "<%s/>\n",
caps->guests[i]->features[j]->name);
} else {
virBufferAsprintf(&buf, "<%s default='%s' toggle='%s'/>\n",
caps->guests[i]->features[j]->name,
caps->guests[i]->features[j]->defaultOn ? "on" : "off",
caps->guests[i]->features[j]->toggle ? "yes" : "no");
}
}
virBufferAdjustIndent(&buf, -2);
virBufferAddLit(&buf, "</features>\n");
}
virBufferAdjustIndent(&buf, -2);
virBufferAddLit(&buf, "</guest>\n\n");
}
virBufferAdjustIndent(&buf, -2);
virBufferAddLit(&buf, "</capabilities>\n");
if (virBufferCheckError(&buf) < 0)
return NULL;
return virBufferContentAndReset(&buf);
}
示例3: prepare_input
/* Prepare the input source. If the input is a regular tar file, this
* just sets ifile = input. However normally the input will be either
* a directory or a compressed tarball. In that case we set up an
* external command to do the tar/uncompression to a temporary pipe,
* and set ifile to the name of the pipe. If there is a subprocess,
* the PID is returned so that callers can wait on it.
*/
static int
prepare_input (const char *input, const char *ifmt,
char **ifile_rtn, int *fd_rtn, pid_t *pid_rtn)
{
const char *argv[7];
*pid_rtn = 0;
*fd_rtn = -1;
if (STREQ (ifmt, "directory")) {
argv[0] = "tar";
argv[1] = "-C";
argv[2] = input;
argv[3] = "-cf";
argv[4] = "-";
argv[5] = ".";
argv[6] = NULL;
if (bg_command ((char **) argv, fd_rtn, pid_rtn) == -1)
return -1;
if (asprintf (ifile_rtn, "/dev/fd/%d", *fd_rtn) == -1) {
perror ("asprintf");
return -1;
}
}
else {
if (strstr (ifmt, "compress")) {
if (strstr (ifmt, "compress'd")) {
argv[0] = "uncompress";
argv[1] = "-c";
argv[2] = input;
argv[3] = NULL;
}
else if (strstr (ifmt, "gzip compressed")) {
argv[0] = "gzip";
argv[1] = "-cd";
argv[2] = input;
argv[3] = NULL;
}
else if (strstr (ifmt, "bzip2 compressed")) {
argv[0] = "bzip2";
argv[1] = "-cd";
argv[2] = input;
argv[3] = NULL;
}
else if (strstr (ifmt, "xz compressed")) {
argv[0] = "xz";
argv[1] = "-cd";
argv[2] = input;
argv[3] = NULL;
}
else
/* Shouldn't happen - see estimate_input above. */
abort ();
if (bg_command ((char **) argv, fd_rtn, pid_rtn) == -1)
return -1;
if (asprintf (ifile_rtn, "/dev/fd/%d", *fd_rtn) == -1) {
perror ("asprintf");
return -1;
}
}
else {
/* Plain tar file, read directly from the file. */
*ifile_rtn = strdup (input);
if (*ifile_rtn == NULL) {
perror ("strdup");
return -1;
}
}
}
return 0;
}
示例4: main
int
main (int argc, char *argv[])
{
/* Set global program name that is not polluted with libtool artifacts. */
set_program_name (argv[0]);
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEBASEDIR);
textdomain (PACKAGE);
enum { HELP_OPTION = CHAR_MAX + 1 };
static const char *options = "a:c:d:qvVx";
static const struct option long_options[] = {
{ "add", 1, 0, 'a' },
{ "filesystem", 1, 0, 0 },
{ "format", 2, 0, 0 },
{ "help", 0, 0, HELP_OPTION },
{ "lvm", 2, 0, 0 },
{ "partition", 2, 0, 0 },
{ "verbose", 0, 0, 'v' },
{ "version", 0, 0, 'V' },
{ "wipe", 0, 0, 0 },
{ 0, 0, 0, 0 }
};
struct drv *drvs = NULL;
struct drv *drv;
const char *format = NULL;
int c;
int option_index;
int retry, retries;
g = guestfs_create ();
if (g == NULL) {
fprintf (stderr, _("guestfs_create: failed to create handle\n"));
exit (EXIT_FAILURE);
}
argv[0] = bad_cast (program_name);
for (;;) {
c = getopt_long (argc, argv, options, long_options, &option_index);
if (c == -1) break;
switch (c) {
case 0: /* options which are long only */
if (STREQ (long_options[option_index].name, "format")) {
if (!optarg || STREQ (optarg, ""))
format = NULL;
else
format = optarg;
} else if (STREQ (long_options[option_index].name, "filesystem")) {
if (STREQ (optarg, "none"))
filesystem = NULL;
else if (optarg[0] == '-') { /* eg: --filesystem --lvm */
fprintf (stderr, _("%s: no filesystem was specified\n"),
program_name);
exit (EXIT_FAILURE);
} else
filesystem = optarg;
} else if (STREQ (long_options[option_index].name, "lvm")) {
if (vg || lv) {
fprintf (stderr,
_("%s: --lvm option cannot be given multiple times\n"),
program_name);
exit (EXIT_FAILURE);
}
if (optarg == NULL) {
vg = strdup ("VG");
lv = strdup ("LV");
if (!vg || !lv) { perror ("strdup"); exit (EXIT_FAILURE); }
}
else if (STREQ (optarg, "none"))
vg = lv = NULL;
else
parse_vg_lv (optarg);
} else if (STREQ (long_options[option_index].name, "partition")) {
if (optarg == NULL)
partition = "DEFAULT";
else if (STREQ (optarg, "none"))
partition = NULL;
else
partition = optarg;
} else if (STREQ (long_options[option_index].name, "wipe")) {
wipe = 1;
} else {
fprintf (stderr, _("%s: unknown long option: %s (%d)\n"),
program_name, long_options[option_index].name, option_index);
exit (EXIT_FAILURE);
}
break;
case 'a':
OPTION_a;
break;
case 'v':
OPTION_v;
break;
//.........这里部分代码省略.........
示例5: node_group_ungroup
//.........这里部分代码省略.........
for (link = wgroup->links.first; link; link = linkn) {
linkn = link->next;
BLI_remlink(&wgroup->links, link);
BLI_addtail(&ntree->links, link);
}
/* and copy across the animation,
* note that the animation data's action can be NULL here */
if (wgroup->adt) {
LinkData *ld, *ldn = NULL;
bAction *waction;
/* firstly, wgroup needs to temporary dummy action that can be destroyed, as it shares copies */
waction = wgroup->adt->action = BKE_action_copy(wgroup->adt->action);
/* now perform the moving */
BKE_animdata_separate_by_basepath(&wgroup->id, &ntree->id, &anim_basepaths);
/* paths + their wrappers need to be freed */
for (ld = anim_basepaths.first; ld; ld = ldn) {
ldn = ld->next;
MEM_freeN(ld->data);
BLI_freelinkN(&anim_basepaths, ld);
}
/* free temp action too */
if (waction) {
BKE_libblock_free(G.main, waction);
}
}
/* free the group tree (takes care of user count) */
BKE_libblock_free(G.main, wgroup);
/* restore external links to and from the gnode */
/* note: the nodes have been copied to intermediate wgroup first (so need to use new_node),
* then transferred to ntree (new_node pointers remain valid).
*/
/* input links */
for (link = ngroup->links.first; link; link = link->next) {
if (link->fromnode->type == NODE_GROUP_INPUT) {
const char *identifier = link->fromsock->identifier;
int num_external_links = 0;
/* find external links to this input */
for (tlink = ntree->links.first; tlink; tlink = tlink->next) {
if (tlink->tonode == gnode && STREQ(tlink->tosock->identifier, identifier)) {
nodeAddLink(ntree, tlink->fromnode, tlink->fromsock, link->tonode->new_node, link->tosock->new_sock);
++num_external_links;
}
}
/* if group output is not externally linked,
* convert the constant input value to ensure somewhat consistent behavior */
if (num_external_links == 0) {
/* XXX TODO bNodeSocket *sock = node_group_find_input_socket(gnode, identifier);
BLI_assert(sock);*/
/* XXX TODO nodeSocketCopy(ntree, link->tosock->new_sock, link->tonode->new_node, ntree, sock, gnode);*/
}
}
}
/* output links */
for (link = ntree->links.first; link; link = link->next) {
if (link->fromnode == gnode) {
const char *identifier = link->fromsock->identifier;
int num_internal_links = 0;
/* find internal links to this output */
for (tlink = ngroup->links.first; tlink; tlink = tlink->next) {
/* only use active output node */
if (tlink->tonode->type == NODE_GROUP_OUTPUT && (tlink->tonode->flag & NODE_DO_OUTPUT)) {
if (STREQ(tlink->tosock->identifier, identifier)) {
nodeAddLink(ntree, tlink->fromnode->new_node, tlink->fromsock->new_sock, link->tonode, link->tosock);
++num_internal_links;
}
}
}
/* if group output is not internally linked,
* convert the constant output value to ensure somewhat consistent behavior */
if (num_internal_links == 0) {
/* XXX TODO bNodeSocket *sock = node_group_find_output_socket(gnode, identifier);
BLI_assert(sock);*/
/* XXX TODO nodeSocketCopy(ntree, link->tosock, link->tonode, ntree, sock, gnode); */
}
}
}
/* delete the group instance */
nodeFreeNode(ntree, gnode);
ntree->update |= NTREE_UPDATE_NODES | NTREE_UPDATE_LINKS;
return 1;
}
示例6: parse_next_token
/* Extract the next token from raw characters. */
static bool parse_next_token(ExprParseState *state)
{
/* Skip whitespace. */
while (isspace(*state->cur)) {
state->cur++;
}
/* End of string. */
if (*state->cur == 0) {
state->token = 0;
return true;
}
/* Floating point numbers. */
if (isdigit(*state->cur) || (state->cur[0] == '.' && isdigit(state->cur[1]))) {
char *end, *out = state->tokenbuf;
bool is_float = false;
while (isdigit(*state->cur)) {
*out++ = *state->cur++;
}
if (*state->cur == '.') {
is_float = true;
*out++ = *state->cur++;
while (isdigit(*state->cur)) {
*out++ = *state->cur++;
}
}
if (ELEM(*state->cur, 'e', 'E')) {
is_float = true;
*out++ = *state->cur++;
if (ELEM(*state->cur, '+', '-')) {
*out++ = *state->cur++;
}
CHECK_ERROR(isdigit(*state->cur));
while (isdigit(*state->cur)) {
*out++ = *state->cur++;
}
}
*out = 0;
/* Forbid C-style octal constants. */
if (!is_float && state->tokenbuf[0] == '0') {
for (char *p = state->tokenbuf + 1; *p; p++) {
if (*p != '0') {
return false;
}
}
}
state->token = TOKEN_NUMBER;
state->tokenval = strtod(state->tokenbuf, &end);
return (end == out);
}
/* ?= tokens */
if (state->cur[1] == '=' && strchr(token_eq_characters, state->cur[0])) {
state->token = MAKE_CHAR2(state->cur[0], state->cur[1]);
state->cur += 2;
return true;
}
/* Special characters (single character tokens) */
if (strchr(token_characters, *state->cur)) {
state->token = *state->cur++;
return true;
}
/* Identifiers */
if (isalpha(*state->cur) || ELEM(*state->cur, '_')) {
char *out = state->tokenbuf;
while (isalnum(*state->cur) || ELEM(*state->cur, '_')) {
*out++ = *state->cur++;
}
*out = 0;
for (int i = 0; keyword_list[i].name; i++) {
if (STREQ(state->tokenbuf, keyword_list[i].name)) {
state->token = keyword_list[i].token;
return true;
}
}
state->token = TOKEN_ID;
return true;
}
return false;
}
示例7: parse_unary
static bool parse_unary(ExprParseState *state)
{
int i;
switch (state->token) {
case '+':
return parse_next_token(state) && parse_unary(state);
case '-':
CHECK_ERROR(parse_next_token(state) && parse_unary(state));
parse_add_func(state, OPCODE_FUNC1, 1, op_negate);
return true;
case '(':
return parse_next_token(state) && parse_expr(state) && state->token == ')' &&
parse_next_token(state);
case TOKEN_NUMBER:
parse_add_op(state, OPCODE_CONST, 1)->arg.dval = state->tokenval;
return parse_next_token(state);
case TOKEN_ID:
/* Parameters: search in reverse order in case of duplicate names -
* the last one should win. */
for (i = state->param_names_len - 1; i >= 0; i--) {
if (STREQ(state->tokenbuf, state->param_names[i])) {
parse_add_op(state, OPCODE_PARAMETER, 1)->arg.ival = i;
return parse_next_token(state);
}
}
/* Ordinary builtin constants. */
for (i = 0; builtin_consts[i].name; i++) {
if (STREQ(state->tokenbuf, builtin_consts[i].name)) {
parse_add_op(state, OPCODE_CONST, 1)->arg.dval = builtin_consts[i].value;
return parse_next_token(state);
}
}
/* Ordinary builtin functions. */
for (i = 0; builtin_ops[i].name; i++) {
if (STREQ(state->tokenbuf, builtin_ops[i].name)) {
int args = parse_function_args(state);
return parse_add_func(state, builtin_ops[i].op, args, builtin_ops[i].funcptr);
}
}
/* Specially supported functions. */
if (STREQ(state->tokenbuf, "min")) {
int cnt = parse_function_args(state);
CHECK_ERROR(cnt > 0);
parse_add_op(state, OPCODE_MIN, 1 - cnt)->arg.ival = cnt;
return true;
}
if (STREQ(state->tokenbuf, "max")) {
int cnt = parse_function_args(state);
CHECK_ERROR(cnt > 0);
parse_add_op(state, OPCODE_MAX, 1 - cnt)->arg.ival = cnt;
return true;
}
return false;
default:
return false;
}
}
示例8: BLO_version_defaults_userpref_blend
//.........这里部分代码省略.........
if (userdef->coba_weight.tot == 0) {
BKE_colorband_init(&userdef->coba_weight, true);
}
}
if (!USER_VERSION_ATLEAST(245, 3)) {
userdef->flag |= USER_ADD_VIEWALIGNED | USER_ADD_EDITMODE;
}
if (!USER_VERSION_ATLEAST(250, 0)) {
/* adjust grease-pencil distances */
userdef->gp_manhattendist = 1;
userdef->gp_euclideandist = 2;
/* adjust default interpolation for new IPO-curves */
userdef->ipo_new = BEZT_IPO_BEZ;
}
if (!USER_VERSION_ATLEAST(250, 3)) {
/* new audio system */
if (userdef->audiochannels == 0) {
userdef->audiochannels = 2;
}
if (userdef->audioformat == 0) {
userdef->audioformat = 0x24;
}
if (userdef->audiorate == 0) {
userdef->audiorate = 48000;
}
}
if (!USER_VERSION_ATLEAST(250, 8)) {
wmKeyMap *km;
for (km = userdef->user_keymaps.first; km; km = km->next) {
if (STREQ(km->idname, "Armature_Sketch")) {
strcpy(km->idname, "Armature Sketch");
}
else if (STREQ(km->idname, "View3D")) {
strcpy(km->idname, "3D View");
}
else if (STREQ(km->idname, "View3D Generic")) {
strcpy(km->idname, "3D View Generic");
}
else if (STREQ(km->idname, "EditMesh")) {
strcpy(km->idname, "Mesh");
}
else if (STREQ(km->idname, "UVEdit")) {
strcpy(km->idname, "UV Editor");
}
else if (STREQ(km->idname, "Animation_Channels")) {
strcpy(km->idname, "Animation Channels");
}
else if (STREQ(km->idname, "GraphEdit Keys")) {
strcpy(km->idname, "Graph Editor");
}
else if (STREQ(km->idname, "GraphEdit Generic")) {
strcpy(km->idname, "Graph Editor Generic");
}
else if (STREQ(km->idname, "Action_Keys")) {
strcpy(km->idname, "Dopesheet");
}
else if (STREQ(km->idname, "NLA Data")) {
strcpy(km->idname, "NLA Editor");
}
else if (STREQ(km->idname, "Node Generic")) {
strcpy(km->idname, "Node Editor");
}
示例9: ParseConfigurationFile
static void
ParseConfigurationFile( FILE *file )
{
char line[LINE_BUFFER_LEN];
char *token;
bool protocol_found = false;
bool server_found = false;
bool username_found = false;
bool password_found = false;
const char *err_string = NULL;
/* Default values for optional parameters. */
strcpy( wmnotify_infos.imap_folder, "INBOX"); /* Default IMAP folder. */
wmnotify_infos.port = 110;
wmnotify_infos.mail_check_interval = 60; /* 1 minute interval. */
wmnotify_infos.audible_notification = false; /* Disabled. */
wmnotify_infos.use_ssl = false; /* Disabled. */
wmnotify_infos.mail_client_argv[0] = NULL; /* No default command. */
wmnotify_infos.audiofile[0] = '\0'; /* No default audio file. */
wmnotify_infos.volume = 100; /* 100% volume. */
/* Reading one line of data from the configuration file. */
/* char *fgets(char *s, int size, FILE *stream);
Reading stops after an EOF or a newline. If a newline is read, it is
stored into the buffer. A '\0' is stored after the last character in
the buffer. */
while( fgets( line, LINE_BUFFER_LEN, file ) != NULL ) {
token = strtok( line, delimiter_single_arg );
if( ( token == NULL ) || ( token[0] == '#' ) ) {
continue; /* Next iteration of the while() loop (next line). */
}
if( STREQ( token, "protocol" ) ) {
token = GetArguments( "protocol", true );
if( STREQ( token, "POP3" ) == true ) {
wmnotify_infos.protocol = POP3_PROTOCOL;
}
else if( STREQ( token, "IMAP4" ) == true ) {
wmnotify_infos.protocol = IMAP4_PROTOCOL;
}
else {
fprintf( stderr, "%s: protocol must be POP3 or IMAP4.\n", PACKAGE );
exit( EXIT_FAILURE );
}
protocol_found = true;
}
else if( STREQ( token, "imap_folder" ) ) {
token = GetArguments( "imap_folder", true );
/* Should check size before using strcpy(), or use strncopy() instead. */
strcpy( wmnotify_infos.imap_folder, token );
}
else if( STREQ( token, "use_ssl" ) ) {
int number;
token = GetArguments( "use_ssl", true );
number = GetNumber( token, "use_ssl" );
if( number == 0 ) {
wmnotify_infos.use_ssl = false;
}
else if( number == 1 ) {
#if HAVE_SSL
wmnotify_infos.use_ssl = true;
#else
fprintf( stderr, "%s error: You must compile %s with SSL support to\n" \
"set parameter 'use_ssl' to true in configuration file\n", PACKAGE, PACKAGE );
exit( EXIT_FAILURE );
#endif
}
else {
fprintf( stderr, "%s: Invalid value for parameter 'use_ssl' in\n" \
"configuration file (must be 0 or 1): %d\n", PACKAGE, number );
exit( EXIT_FAILURE );
}
}
else if( STREQ( token, "server" ) ) {
token = GetArguments( "server", true );
strncpy( wmnotify_infos.server_name, token, MAX_STR_LEN );
server_found = true;
}
else if( STREQ( token, "port" ) ) {
token = GetArguments( "port", true );
wmnotify_infos.port = (u_int16_t) GetNumber( token, "port" );
}
else if( STREQ( token, "username" ) ) {
token = GetArguments( "username", true );
strncpy( wmnotify_infos.username, token, MAX_STR_LEN );
username_found = true;
}
else if( STREQ( token, "password" ) ) {
token = GetArguments( "password", true );
strncpy( wmnotify_infos.password, token, MAX_STR_LEN );
password_found = true;
}
else if( STREQ( token, "mailcheckdelay" ) ) {
int delay; /* delay in minutes. */
token = GetArguments( "mailcheckdelay", true );
//.........这里部分代码省略.........
示例10: hivex_open
hive_h *
hivex_open (const char *filename, int flags)
{
hive_h *h = NULL;
assert (sizeof (struct ntreg_header) == 0x1000);
assert (offsetof (struct ntreg_header, csum) == 0x1fc);
h = calloc (1, sizeof *h);
if (h == NULL)
goto error;
h->msglvl = flags & HIVEX_OPEN_MSGLVL_MASK;
const char *debug = getenv ("HIVEX_DEBUG");
if (debug && STREQ (debug, "1"))
h->msglvl = 2;
DEBUG (2, "created handle %p", h);
h->writable = !!(flags & HIVEX_OPEN_WRITE);
h->unsafe = !!(flags & HIVEX_OPEN_UNSAFE);
h->filename = strdup (filename);
if (h->filename == NULL)
goto error;
#ifdef O_CLOEXEC
h->fd = open (filename, O_RDONLY | O_CLOEXEC | O_BINARY);
#else
h->fd = open (filename, O_RDONLY | O_BINARY);
#endif
if (h->fd == -1)
goto error;
#ifndef O_CLOEXEC
fcntl (h->fd, F_SETFD, FD_CLOEXEC);
#endif
struct stat statbuf;
if (fstat (h->fd, &statbuf) == -1)
goto error;
h->size = statbuf.st_size;
if (h->size < 0x2000) {
SET_ERRNO (EINVAL,
"%s: file is too small to be a Windows NT Registry hive file",
filename);
goto error;
}
if (!h->writable) {
h->addr = mmap (NULL, h->size, PROT_READ, MAP_SHARED, h->fd, 0);
if (h->addr == MAP_FAILED)
goto error;
DEBUG (2, "mapped file at %p", h->addr);
} else {
h->addr = malloc (h->size);
if (h->addr == NULL)
goto error;
if (full_read (h->fd, h->addr, h->size) < h->size)
goto error;
/* We don't need the file descriptor along this path, since we
* have read all the data.
*/
if (close (h->fd) == -1)
goto error;
h->fd = -1;
}
/* Check header. */
if (h->hdr->magic[0] != 'r' ||
h->hdr->magic[1] != 'e' ||
h->hdr->magic[2] != 'g' ||
h->hdr->magic[3] != 'f') {
SET_ERRNO (ENOTSUP,
"%s: not a Windows NT Registry hive file", filename);
goto error;
}
/* Check major version. */
uint32_t major_ver = le32toh (h->hdr->major_ver);
if (major_ver != 1) {
SET_ERRNO (ENOTSUP,
"%s: hive file major version %" PRIu32 " (expected 1)",
filename, major_ver);
goto error;
}
h->bitmap = calloc (1 + h->size / 32, 1);
if (h->bitmap == NULL)
goto error;
/* Header checksum. */
uint32_t sum = header_checksum (h);
if (sum != le32toh (h->hdr->csum)) {
SET_ERRNO (EINVAL, "%s: bad checksum in hive header", filename);
goto error;
//.........这里部分代码省略.........
示例11: kernel_configuration
//.........这里部分代码省略.........
p = get_cmdline_key (cmdline, "p2v.removable");
if (p) {
CLEANUP_FREE char *t;
t = strdup (p);
guestfs_int_free_string_list (config->removable);
config->removable = guestfs_int_split_string (',', t);
}
p = get_cmdline_key (cmdline, "p2v.interfaces");
if (p) {
CLEANUP_FREE char *t;
t = strdup (p);
guestfs_int_free_string_list (config->interfaces);
config->interfaces = guestfs_int_split_string (',', t);
}
p = get_cmdline_key (cmdline, "p2v.network");
if (p) {
CLEANUP_FREE char *t;
t = strdup (p);
guestfs_int_free_string_list (config->network_map);
config->network_map = guestfs_int_split_string (',', t);
}
p = get_cmdline_key (cmdline, "p2v.o");
if (p) {
free (config->output);
config->output = strdup (p);
}
p = get_cmdline_key (cmdline, "p2v.oa");
if (p) {
if (STREQ (p, "sparse"))
config->output_allocation = OUTPUT_ALLOCATION_SPARSE;
else if (STREQ (p, "preallocated"))
config->output_allocation = OUTPUT_ALLOCATION_PREALLOCATED;
else
fprintf (stderr, "%s: warning: don't know what p2v.oa=%s means\n",
guestfs_int_program_name, p);
}
p = get_cmdline_key (cmdline, "p2v.oc");
if (p) {
free (config->output_connection);
config->output_connection = strdup (p);
}
p = get_cmdline_key (cmdline, "p2v.of");
if (p) {
free (config->output_format);
config->output_format = strdup (p);
}
p = get_cmdline_key (cmdline, "p2v.os");
if (p) {
free (config->output_storage);
config->output_storage = strdup (p);
}
/* Undocumented command line tool used for testing command line parsing. */
p = get_cmdline_key (cmdline, "p2v.dump_config_and_exit");
if (p) {
print_config (config, stdout);
exit (EXIT_SUCCESS);
}
/* Some disks must have been specified for conversion. */
if (config->disks == NULL || guestfs_int_count_strings (config->disks) == 0) {
fprintf (stderr, "%s: error: no non-removable disks were discovered on this machine.\n",
guestfs_int_program_name);
fprintf (stderr, "virt-p2v looked in /sys/block and in p2v.disks on the kernel command line.\n");
fprintf (stderr, "This is a fatal error and virt-p2v cannot continue.\n");
exit (EXIT_FAILURE);
}
/* Perform the conversion in text mode. */
if (start_conversion (config, notify_ui_callback) == -1) {
const char *err = get_conversion_error ();
fprintf (stderr, "%s: error during conversion: %s\n",
guestfs_int_program_name, err);
p = get_cmdline_key (cmdline, "p2v.fail");
if (p)
run_command (config->verbose, "p2v.fail", p);
exit (EXIT_FAILURE);
}
p = get_cmdline_key (cmdline, "p2v.post");
if (!p) {
if (geteuid () == 0 && cmdline_source == CMDLINE_SOURCE_PROC_CMDLINE)
p = "poweroff";
}
if (p)
run_command (config->verbose, "p2v.post", p);
}
示例12: main
int
main (int argc, char *argv[])
{
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEBASEDIR);
textdomain (PACKAGE);
parse_config ();
enum { HELP_OPTION = CHAR_MAX + 1 };
/* The command line arguments are broadly compatible with (a subset
* of) guestfish. Thus we have to deal mainly with -a, -m and --ro.
*/
static const char *options = "a:c:d:im:no:rv?Vwx";
static const struct option long_options[] = {
{ "add", 1, 0, 'a' },
{ "connect", 1, 0, 'c' },
{ "dir-cache-timeout", 1, 0, 0 },
{ "domain", 1, 0, 'd' },
{ "echo-keys", 0, 0, 0 },
{ "format", 2, 0, 0 },
{ "fuse-help", 0, 0, 0 },
{ "help", 0, 0, HELP_OPTION },
{ "inspector", 0, 0, 'i' },
{ "keys-from-stdin", 0, 0, 0 },
{ "live", 0, 0, 0 },
{ "mount", 1, 0, 'm' },
{ "no-sync", 0, 0, 'n' },
{ "option", 1, 0, 'o' },
{ "ro", 0, 0, 'r' },
{ "rw", 0, 0, 'w' },
{ "selinux", 0, 0, 0 },
{ "trace", 0, 0, 'x' },
{ "verbose", 0, 0, 'v' },
{ "version", 0, 0, 'V' },
{ 0, 0, 0, 0 }
};
struct drv *drvs = NULL;
struct drv *drv;
struct mp *mps = NULL;
struct mp *mp;
char *p;
const char *format = NULL;
int c, r;
int option_index;
struct sigaction sa;
int fuse_argc = 0;
const char **fuse_argv = NULL;
#define ADD_FUSE_ARG(str) \
do { \
fuse_argc ++; \
fuse_argv = realloc (fuse_argv, (1+fuse_argc) * sizeof (char *)); \
if (!fuse_argv) { \
perror ("realloc"); \
exit (EXIT_FAILURE); \
} \
fuse_argv[fuse_argc-1] = (str); \
fuse_argv[fuse_argc] = NULL; \
} while (0)
/* LC_ALL=C is required so we can parse error messages. */
setenv ("LC_ALL", "C", 1);
/* Set global program name that is not polluted with libtool artifacts. */
set_program_name (argv[0]);
memset (&sa, 0, sizeof sa);
sa.sa_handler = SIG_IGN;
sa.sa_flags = SA_RESTART;
sigaction (SIGPIPE, &sa, NULL);
/* Various initialization. */
init_dir_caches ();
g = guestfs_create ();
if (g == NULL) {
fprintf (stderr, _("guestfs_create: failed to create handle\n"));
exit (EXIT_FAILURE);
}
guestfs_set_recovery_proc (g, 0);
ADD_FUSE_ARG (program_name);
/* MUST be single-threaded. You cannot have two threads accessing the
* same libguestfs handle, and opening more than one handle is likely
* to be very expensive.
*/
ADD_FUSE_ARG ("-s");
for (;;) {
c = getopt_long (argc, argv, options, long_options, &option_index);
if (c == -1) break;
switch (c) {
case 0: /* options which are long only */
if (STREQ (long_options[option_index].name, "dir-cache-timeout"))
//.........这里部分代码省略.........
示例13: read_packet
/*
* read a packet from the wire, and decrypt it. Increment the global
* seq_no return NULL on failure
*/
u_char *
read_packet(void)
{
HDR hdr;
u_char *pkt, *data;
int len;
char *tkey;
if (debug & DEBUG_PACKET_FLAG)
report(LOG_DEBUG, "Waiting for packet");
/* read a packet header */
len = sockread(session.sock, (u_char *)&hdr,
TAC_PLUS_HDR_SIZE, cfg_get_readtimeout());
if (len != TAC_PLUS_HDR_SIZE) {
report(LOG_DEBUG, "Read %d bytes from %s %s, expecting %d",
len, session.peer, session.port, TAC_PLUS_HDR_SIZE);
return(NULL);
}
session.peerflags = hdr.flags;
if ((hdr.version & TAC_PLUS_MAJOR_VER_MASK) != TAC_PLUS_MAJOR_VER) {
report(LOG_ERR, "%s: Illegal major version specified: found %d wanted "
"%d\n", session.peer, hdr.version, TAC_PLUS_MAJOR_VER);
return(NULL);
}
/* get memory for the packet */
len = TAC_PLUS_HDR_SIZE + ntohl(hdr.datalength);
if ((ntohl(hdr.datalength) & ~0xffffUL) ||
(len < TAC_PLUS_HDR_SIZE) || (len > 0x10000)) {
report(LOG_ERR, "%s: Illegal data size: %lu\n", session.peer,
ntohl(hdr.datalength));
return(NULL);
}
pkt = (u_char *)tac_malloc(len);
/* initialise the packet */
memcpy(pkt, &hdr, TAC_PLUS_HDR_SIZE);
/* the data start here */
data = pkt + TAC_PLUS_HDR_SIZE;
/* read the rest of the packet data */
if (sockread(session.sock, data, ntohl(hdr.datalength),
cfg_get_readtimeout()) != ntohl(hdr.datalength)) {
report(LOG_ERR, "%s: start_session: bad socket read", session.peer);
free(pkt);
return(NULL);
}
session.seq_no++; /* should now equal that of incoming packet */
session.last_exch = time(NULL);
if (session.seq_no != hdr.seq_no) {
report(LOG_ERR, "%s: Illegal session seq # %d != packet seq # %d",
session.peer, session.seq_no, hdr.seq_no);
free(pkt);
return(NULL);
}
/* decrypt the data portion */
tkey = cfg_get_host_key(session.peerip);
if (tkey == NULL && !STREQ(session.peer, session.peerip)) {
tkey = cfg_get_host_prompt(session.peer);
}
if (tkey == NULL)
tkey = session.key;
if (md5_xor((HDR *)pkt, data, tkey)) {
report(LOG_ERR, "%s: start_session error decrypting data",
session.peer);
free(pkt);
return(NULL);
}
if (debug & DEBUG_PACKET_FLAG)
report(LOG_DEBUG, "Read %s size=%d",
summarise_incoming_packet_type(pkt), len);
session.version = hdr.version;
return(pkt);
}
示例14: parse_args
void parse_args(int argc, char** argv, struct prefs* v) {
gboolean in_loop = TRUE;
struct option long_options[] = {
{ "font-size-modifier", 1, NULL, 'z' },
{ "black", 1, NULL, '1' },
{ "red", 1, NULL, '2' },
{ "green", 1, NULL, '3' },
{ "yellow", 1, NULL, '4' },
{ "blue", 1, NULL, '5' },
{ "magenta", 1, NULL, '6' },
{ "cyan", 1, NULL, '7' },
{ "white", 1, NULL, '8' },
{ "jump-resize", 2, NULL, 'j' },
{ "file-icons", 2, NULL, 'i' },
{ "version", 0, NULL, 'V' },
};
GdkColor color_temp;
optind = 0;
while (in_loop) {
switch (fgetopt_long(argc, argv, "j::z:i::vV", long_options, NULL)) {
case -1:
in_loop = FALSE;
break;
/* Font size modifier */
case 'z':
v->font_size_modifier = CLAMP(atoi(optarg), -10, 10);
break;
/* Enable or disable icons */
case 'i':
if (!optarg || STREQ(optarg, "on"))
v->show_icons = TRUE;
else if (STREQ(optarg, "off"))
v->show_icons = FALSE;
break;
/* Enable or disable jump-resize */
case 'j':
if (!optarg || STREQ(optarg, "on"))
v->jump_resize = TRUE;
else if (STREQ(optarg, "off"))
v->jump_resize = FALSE;
break;
/* Colours */
case '1':
if (gdk_color_parse(optarg, &color_temp))
set_color(TCC_BLACK, &color_temp);
break;
case '2':
if (gdk_color_parse(optarg, &color_temp))
set_color(TCC_RED, &color_temp);
break;
case '3':
if (gdk_color_parse(optarg, &color_temp))
set_color(TCC_GREEN, &color_temp);
break;
case '4':
if (gdk_color_parse(optarg, &color_temp))
set_color(TCC_YELLOW, &color_temp);
break;
case '5':
if (gdk_color_parse(optarg, &color_temp))
set_color(TCC_BLUE, &color_temp);
break;
case '6':
if (gdk_color_parse(optarg, &color_temp))
set_color(TCC_MAGENTA, &color_temp);
break;
case '7':
if (gdk_color_parse(optarg, &color_temp))
set_color(TCC_CYAN, &color_temp);
break;
case '8':
if (gdk_color_parse(optarg, &color_temp))
set_color(TCC_WHITE, &color_temp);
break;
case 'v':
case 'V':
report_version();
break;
case ':':
g_warning("Option missing argument");
/*exit(EXIT_FAILURE);*/
break;
case '?':
default:
g_warning("Unknown option provided");
/*exit(EXIT_FAILURE);*/
break;
}
}
//.........这里部分代码省略.........
示例15: ED_armature_bone_rename
//.........这里部分代码省略.........
BLI_ghash_insert(gh, pchan->name, pchan);
}
}
BLI_assert(BKE_pose_channels_is_valid(ob->pose) == true);
}
/* Update any object constraints to use the new bone name */
for (cob = G.main->object.first; cob; cob = cob->id.next) {
if (cob->constraints.first)
constraint_bone_name_fix(ob, &cob->constraints, oldname, newname);
if (cob->pose) {
bPoseChannel *pchan;
for (pchan = cob->pose->chanbase.first; pchan; pchan = pchan->next) {
constraint_bone_name_fix(ob, &pchan->constraints, oldname, newname);
}
}
}
}
/* See if an object is parented to this armature */
if (ob->parent && (ob->parent->data == arm)) {
if (ob->partype == PARBONE) {
/* bone name in object */
if (!strcmp(ob->parsubstr, oldname))
BLI_strncpy(ob->parsubstr, newname, MAXBONENAME);
}
}
if (modifiers_usesArmature(ob, arm)) {
bDeformGroup *dg = defgroup_find_name(ob, oldname);
if (dg) {
BLI_strncpy(dg->name, newname, MAXBONENAME);
}
}
/* fix modifiers that might be using this name */
for (md = ob->modifiers.first; md; md = md->next) {
switch (md->type) {
case eModifierType_Hook:
{
HookModifierData *hmd = (HookModifierData *)md;
if (hmd->object && (hmd->object->data == arm)) {
if (STREQ(hmd->subtarget, oldname))
BLI_strncpy(hmd->subtarget, newname, MAXBONENAME);
}
break;
}
case eModifierType_UVWarp:
{
UVWarpModifierData *umd = (UVWarpModifierData *)md;
if (umd->object_src && (umd->object_src->data == arm)) {
if (STREQ(umd->bone_src, oldname))
BLI_strncpy(umd->bone_src, newname, MAXBONENAME);
}
if (umd->object_dst && (umd->object_dst->data == arm)) {
if (STREQ(umd->bone_dst, oldname))
BLI_strncpy(umd->bone_dst, newname, MAXBONENAME);
}
break;
}
default:
break;
}
}
}
/* Fix all animdata that may refer to this bone - we can't just do the ones attached to objects, since
* other ID-blocks may have drivers referring to this bone [#29822]
*/
{
BKE_all_animdata_fix_paths_rename(&arm->id, "pose.bones", oldname, newname);
}
/* correct view locking */
{
bScreen *screen;
for (screen = G.main->screen.first; screen; screen = screen->id.next) {
ScrArea *sa;
/* add regions */
for (sa = screen->areabase.first; sa; sa = sa->next) {
SpaceLink *sl;
for (sl = sa->spacedata.first; sl; sl = sl->next) {
if (sl->spacetype == SPACE_VIEW3D) {
View3D *v3d = (View3D *)sl;
if (v3d->ob_centre && v3d->ob_centre->data == arm) {
if (!strcmp(v3d->ob_centre_bone, oldname)) {
BLI_strncpy(v3d->ob_centre_bone, newname, MAXBONENAME);
}
}
}
}
}
}
}
}
}