这篇教程C++ strspn函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中strspn函数的典型用法代码示例。如果您正苦于以下问题:C++ strspn函数的具体用法?C++ strspn怎么用?C++ strspn使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了strspn函数的27个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: ZLoadProcesstable/* Load processes using zone-aware ps * to obtain solaris list of global * process ids for root and non-root * users to lookup later */int ZLoadProcesstable(Seq *pidlist, Seq *rootpidlist){ char *names[CF_PROCCOLS]; int start[CF_PROCCOLS]; int end[CF_PROCCOLS]; int index = 0; const char *pscmd = "/usr/bin/ps -Aleo zone,user,pid"; FILE *psf = cf_popen(pscmd, "r", false); if (psf == NULL) { Log(LOG_LEVEL_ERR, "ZLoadProcesstable: Couldn't open the process list with command %s.", pscmd); return false; } size_t pbuff_size = CF_BUFSIZE; char *pbuff = xmalloc(pbuff_size); while (true) { ssize_t res = CfReadLine(&pbuff, &pbuff_size, psf); if (res == -1) { if (!feof(psf)) { Log(LOG_LEVEL_ERR, "IsGlobalProcess(char **, int): Unable to read process list with command '%s'. (fread: %s)", pscmd, GetErrorStr()); cf_pclose(psf); free(pbuff); return false; } else { break; } } Chop(pbuff, pbuff_size); if (strstr(pbuff, "PID")) /* This line is the header. */ { GetProcessColumnNames(pbuff, &names[0], start, end); } else { int pid = ExtractPid(pbuff, &names[0], end); size_t zone_offset = strspn(pbuff, " "); size_t zone_end_offset = strcspn(pbuff + zone_offset, " ") + zone_offset; size_t user_offset = strspn(pbuff + zone_end_offset, " ") + zone_end_offset; size_t user_end_offset = strcspn(pbuff + user_offset, " ") + user_offset; bool is_global = (zone_end_offset - zone_offset == 6 && strncmp(pbuff + zone_offset, "global", 6) == 0); bool is_root = (user_end_offset - user_offset == 4 && strncmp(pbuff + user_offset, "root", 4) == 0); if (is_global && is_root) { SeqAppend(rootpidlist, (void*)(intptr_t)pid); } else if (is_global && !is_root) { SeqAppend(pidlist, (void*)(intptr_t)pid); } } } cf_pclose(psf); free(pbuff); return true;}
开发者ID:amousset,项目名称:core,代码行数:73,
示例2: read_cfstatic void read_cf(void){ char tmp[0x100], lv[0x20], rv[0x20]; struct conf_item *ci = NULL; FILE *fd; size_t len; int lnum, found, v_int; char *lp, *conv_err; bool file_needs_update = false; char *cfname = get_confname(); if (access(cfname, F_OK) != 0) goto done; fd = fopen(cfname, "r"); if (fd == NULL) err_sys("can not read configuration file '%s'", cfname); for (lnum = 1; fgets(tmp, sizeof(tmp), fd); lnum++) { lp = tmp + strspn(tmp, " "); if (*lp == '#' || *lp == '/n') continue; len = strcspn(lp, " ="); if (len > sizeof(lv)) err_quit("parse error in %s, line %d: identifier too long", cfname, lnum); strncpy(lv, lp, len); lv[len] = '/0'; lp += len; ll_reset(conf_items); for (found = 0; !found && (ci = ll_getall(conf_items)); ) found = (ci->type != t_sep && ci->type != t_func && strcasecmp(ci->cfname, lv) == 0); if (!found) { err_msg("%s, line %d: ignoring unknown identifier '%s'", cfname, lnum, lv); file_needs_update = true; continue; } lp += strspn(lp, " "); if (*lp++ != '=') err_quit("parse error in %s, line %d: missing '=' operator in assignment", cfname, lnum); lp += strspn(lp, " "); len = strcspn(lp, " /n"); if (len > sizeof(rv)) err_quit("parse error in %s, line %d: argument too long", cfname, lnum); else if (*lp == '/n') err_quit("parse error in %s, line %d: argument expected", cfname, lnum); strncpy(rv, lp, len); rv[len] = '/0'; switch (ci->type) { case t_int: v_int = strtol(rv, &conv_err, 10); if (*conv_err != '/0') { err_quit("parse error in %s, line %d: integer value expected, '%s' found instead", cfname, lnum, rv); } else if (v_int > ci->max) { err_msg("%s, line %d: value exceeds maximum of %d - using maximum", cfname, lnum, (int)ci->max); *ci->v.i = ci->max; file_needs_update = true; } else if (v_int < ci->min) { err_msg("%s, line %d: value is below minimum of %d - using minimum", cfname, lnum, (int)ci->min); *ci->v.i = ci->min; file_needs_update = true; } else { *ci->v.i = v_int; } break; case t_list: assert(ci->list != NULL); if (!argv_count(ci->list)) err_quit("no usable %s candidates available for '%s'", ci->name, rv); v_int = argv_find(ci->list, rv); if (v_int < 0) { err_msg("%s, line %d: '%s = %s' is not valid - using defaults", cfname, lnum, lv, rv); file_needs_update = true; } else { *ci->v.i = v_int; } case t_sep: case t_func: break; } } fclose(fd);done: free(cfname); if (file_needs_update) { write_cf(); }//.........这里部分代码省略.........
开发者ID:uoaerg,项目名称:wavemon,代码行数:101,
示例3: dStrspnU32 dStrspn(const char *str, const char *set){ return(strspn(str, set));}
开发者ID:120pulsations,项目名称:Torque2D,代码行数:4,
示例4: drop_privileges/* drops privileges */int drop_privileges(char *user, char *group){ uid_t uid=-1; gid_t gid=-1; struct group *grp; struct passwd *pw; /* set effective group ID */ if(group!=NULL){ /* see if this is a group name */ if(strspn(group,"0123456789")<strlen(group)){ grp=(struct group *)getgrnam(group); if(grp!=NULL) gid=(gid_t)(grp->gr_gid); else syslog(LOG_ERR,"Warning: Could not get group entry for '%s'",group); endgrent(); } /* else we were passed the GID */ else gid=(gid_t)atoi(group); /* set effective group ID if other than current EGID */ if(gid!=getegid()){ if(setgid(gid)==-1) syslog(LOG_ERR,"Warning: Could not set effective GID=%d",(int)gid); } } /* set effective user ID */ if(user!=NULL){ /* see if this is a user name */ if(strspn(user,"0123456789")<strlen(user)){ pw=(struct passwd *)getpwnam(user); if(pw!=NULL) uid=(uid_t)(pw->pw_uid); else syslog(LOG_ERR,"Warning: Could not get passwd entry for '%s'",user); endpwent(); } /* else we were passed the UID */ else uid=(uid_t)atoi(user); /* set effective user ID if other than current EUID */ if(uid!=geteuid()){#ifdef HAVE_INITGROUPS /* initialize supplementary groups */ if(initgroups(user,gid)==-1){ if(errno==EPERM) syslog(LOG_ERR,"Warning: Unable to change supplementary groups using initgroups()"); else{ syslog(LOG_ERR,"Warning: Possibly root user failed dropping privileges with initgroups()"); return ERROR; } }#endif if(setuid(uid)==-1) syslog(LOG_ERR,"Warning: Could not set effective UID=%d",(int)uid); } } return OK; }
开发者ID:hjanuschka,项目名称:nrpe-svn,代码行数:72,
示例5: _ngx_process_memguard_trim_wschar* _ngx_process_memguard_trim_ws(char *line){ return line + strspn(line, " /t");}
开发者ID:peschuster,项目名称:nginx,代码行数:4,
示例6: versionParse/* ****************************************************************************** versionParse -*/bool versionParse(std::string version, int& mayor, int& minor, std::string& bugFix){ char* copy = strdup(version.c_str()); char* s = wsStrip(copy); char* dotP; // // mayor number // dotP = strchr(s, '.'); if (dotP == NULL) { free(copy); return false; } *dotP = 0; ++dotP; s = wsStrip(s); mayor = atoi(s); if (strspn(s, "0123456789") != strlen(s)) { free(copy); return false; } s = dotP; // // minor number // If no dot is found, no bugFix 'version' is present. // Just zero the 'bugFix' and keep the remaining string in minor. // bool bugFixEmpty = false; dotP = strchr(s, '.'); if (dotP != NULL) { *dotP = 0; ++dotP; } else { bugFix = ""; bugFixEmpty = true; } s = wsStrip(s); minor = atoi(s); if (strspn(s, "0123456789") != strlen(s)) { free(copy); return false; } if (bugFixEmpty == true) { free(copy); return true; } s = dotP; // // bugfix // s = wsStrip(s); bugFix = s; free(copy); return true;}
开发者ID:agallegoc,项目名称:fiware-orion,代码行数:80,
示例7: CustomizableCleanupPriorWALFilesstatic voidCustomizableCleanupPriorWALFiles(void){ /* * Work out name of prior file from current filename */ if (nextWALFileType == XLOG_DATA) { int rc; DIR *xldir; struct dirent *xlde; /* * Assume its OK to keep failing. The failure situation may change * over time, so we'd rather keep going on the main processing than * fail because we couldnt clean up yet. */ if ((xldir = opendir(archiveLocation)) != NULL) { while ((xlde = readdir(xldir)) != NULL) { /* * We ignore the timeline part of the XLOG segment identifiers * in deciding whether a segment is still needed. This * ensures that we won't prematurely remove a segment from a * parent timeline. We could probably be a little more * proactive about removing segments of non-parent timelines, * but that would be a whole lot more complicated. * * We use the alphanumeric sorting property of the filenames * to decide which ones are earlier than the * exclusiveCleanupFileName file. Note that this means files * are not removed in the order they were originally written, * in case this worries you. */ if (strlen(xlde->d_name) == XLOG_DATA_FNAME_LEN && strspn(xlde->d_name, "0123456789ABCDEF") == XLOG_DATA_FNAME_LEN && strcmp(xlde->d_name + 8, exclusiveCleanupFileName + 8) < 0) {#ifdef WIN32 snprintf(WALFilePath, MAXPGPATH, "%s//%s", archiveLocation, xlde->d_name);#else snprintf(WALFilePath, MAXPGPATH, "%s/%s", archiveLocation, xlde->d_name);#endif if (debug) fprintf(stderr, "/nremoving /"%s/"", WALFilePath); rc = unlink(WALFilePath); if (rc != 0) { fprintf(stderr, "/n%s: ERROR failed to remove /"%s/": %s", progname, WALFilePath, strerror(errno)); break; } } } if (debug) fprintf(stderr, "/n"); } else fprintf(stderr, "%s: archiveLocation /"%s/" open error/n", progname, archiveLocation); closedir(xldir); fflush(stderr); }}
开发者ID:kvap,项目名称:postgres-pq,代码行数:67,
示例8: main//.........这里部分代码省略......... { restartWALFileName = argv[optind]; optind++; } CustomizableInitialize(); need_cleanup = SetWALFileNameForCleanup(); if (debug) { fprintf(stderr, "Trigger file : %s/n", triggerPath ? triggerPath : "<not set>"); fprintf(stderr, "Waiting for WAL file : %s/n", nextWALFileName); fprintf(stderr, "WAL file path : %s/n", WALFilePath); fprintf(stderr, "Restoring to : %s/n", xlogFilePath); fprintf(stderr, "Sleep interval : %d second%s/n", sleeptime, (sleeptime > 1 ? "s" : " ")); fprintf(stderr, "Max wait interval : %d %s/n", maxwaittime, (maxwaittime > 0 ? "seconds" : "forever")); fprintf(stderr, "Command for restore : %s/n", restoreCommand); fprintf(stderr, "Keep archive history : "); if (need_cleanup) fprintf(stderr, "%s and later/n", exclusiveCleanupFileName); else fprintf(stderr, "No cleanup required/n"); fflush(stderr); } /* * Check for initial history file: always the first file to be requested * It's OK if the file isn't there - all other files need to wait */ if (strlen(nextWALFileName) > 8 && strspn(nextWALFileName, "0123456789ABCDEF") == 8 && strcmp(nextWALFileName + strlen(nextWALFileName) - strlen(".history"), ".history") == 0) { nextWALFileType = XLOG_HISTORY; if (RestoreWALFileForRecovery()) exit(0); else { if (debug) { fprintf(stderr, "history file not found/n"); fflush(stderr); } exit(1); } } /* * Main wait loop */ for (;;) { /* Check for trigger file or signal first */ CheckForExternalTrigger();#ifndef WIN32 if (signaled) { Failover = FastFailover; if (debug) { fprintf(stderr, "signaled to exit: fast failover/n"); fflush(stderr);
开发者ID:kvap,项目名称:postgres-pq,代码行数:67,
示例9: fopenbool CPatch::FindTarget(const char *strConfigFilename, const char *strCommandLine){ FILE *hFile = fopen(strConfigFilename, "rb"); if(hFile == 0) return false; while(true) { char buffer[PATCH_LINE_MAX]; fgets(buffer, PATCH_LINE_MAX, hFile); if(feof(hFile)) break; char *pToken = &buffer[strspn(buffer, " /t/n/r")]; if(*pToken++ != '!') continue; char strTarget[_MAX_PATH]; if(strncmp(pToken, "commandline", 11) == 0) { if(strCommandLine && (strlen(strCommandLine) > 0)) { strcpy(strTarget, (char *)(LPCTSTR)strCommandLine); } else continue; } else if(strncmp(pToken, "file", 4) == 0) { pToken += 4; pToken = &pToken[strspn(pToken, " /t/n/r")]; if(*pToken++ != '/"') continue; char *strFilename = pToken; if((pToken = strchr(pToken, '/"')) == 0) continue; *pToken++ = 0; strcpy(strTarget, strFilename); } else if(strncmp(pToken, "registry", 8) == 0) { pToken += 8; pToken = &pToken[strspn(pToken, " /t/n/r")]; if(*pToken++ != '/"') continue; char *strKey = pToken; if((pToken = strchr(pToken, '/"')) == 0) continue; *pToken++ = 0; HKEY tempKey; if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, strKey, NULL, KEY_READ, &tempKey) != ERROR_SUCCESS) continue; pToken = &pToken[strspn(pToken, " /t/n/r")]; if(*pToken++ != '/"') continue; char *strValue = pToken; if((pToken = strchr(pToken, '/"')) == 0) continue; *pToken++ = 0; DWORD pathLength = _MAX_PATH; if(RegQueryValueEx(tempKey, strValue, NULL, NULL, (LPBYTE)strTarget, &pathLength) != ERROR_SUCCESS) continue; RegCloseKey(tempKey); pToken = &pToken[strspn(pToken, " /t/n/r")]; if(*pToken++ != '/"') continue; char *strAdd = pToken; if((pToken = strchr(pToken, '/"')) == 0) continue; *pToken++ = 0; strcat(strTarget, strAdd); } FILE *hTargetFile = fopen(strTarget, "rb"); if(hTargetFile != 0) { fclose(hTargetFile); delete [] m_strTarget; m_strTarget = new char[strlen(strTarget) + 1]; strcpy(m_strTarget, strTarget); fclose(hFile); return true; } } fclose(hFile);//.........这里部分代码省略.........
开发者ID:Skinny1001,项目名称:Ignition,代码行数:101,
示例10: parse_argsstatic intparse_args(const char **cpp, int *pflag, int *lflag, int *iflag, unsigned long *n_arg, char **path1, char **path2){ const char *cmd, *cp = *cpp; char *cp2; int base = 0; long l; int i, cmdnum; /* Skip leading whitespace */ cp = cp + strspn(cp, WHITESPACE); /* Ignore blank lines and lines which begin with comment '#' char */ if (*cp == '/0' || *cp == '#') return (0); /* Check for leading '-' (disable error processing) */ *iflag = 0; if (*cp == '-') { *iflag = 1; cp++; } /* Figure out which command we have */ for (i = 0; cmds[i].c; i++) { int cmdlen = strlen(cmds[i].c); /* Check for command followed by whitespace */ if (!strncasecmp(cp, cmds[i].c, cmdlen) && strchr(WHITESPACE, cp[cmdlen])) { cp += cmdlen; cp = cp + strspn(cp, WHITESPACE); break; } } cmdnum = cmds[i].n; cmd = cmds[i].c; /* Special case */ if (*cp == '!') { cp++; cmdnum = I_SHELL; } else if (cmdnum == -1) { error("Invalid command."); return (-1); } /* Get arguments and parse flags */ *lflag = *pflag = *n_arg = 0; *path1 = *path2 = NULL; switch (cmdnum) { case I_GET: case I_PUT: if (parse_getput_flags(&cp, pflag)) return(-1); /* Get first pathname (mandatory) */ if (get_pathname(&cp, path1)) return(-1); if (*path1 == NULL) { error("You must specify at least one path after a " "%s command.", cmd); return(-1); } /* Try to get second pathname (optional) */ if (get_pathname(&cp, path2)) return(-1); break; case I_RENAME: case I_SYMLINK: if (get_pathname(&cp, path1)) return(-1); if (get_pathname(&cp, path2)) return(-1); if (!*path1 || !*path2) { error("You must specify two paths after a %s " "command.", cmd); return(-1); } break; case I_RM: case I_MKDIR: case I_RMDIR: case I_CHDIR: case I_LCHDIR: case I_LMKDIR: /* Get pathname (mandatory) */ if (get_pathname(&cp, path1)) return(-1); if (*path1 == NULL) { error("You must specify a path after a %s command.", cmd); return(-1); } break; case I_LS: if (parse_ls_flags(&cp, lflag)) return(-1); /* Path is optional */ if (get_pathname(&cp, path1))//.........这里部分代码省略.........
开发者ID:Hacker-One,项目名称:backdoor_rootkit,代码行数:101,
示例11: get_pathnamestatic intget_pathname(const char **cpp, char **path){ const char *cp = *cpp, *end; char quot; u_int i, j; cp += strspn(cp, WHITESPACE); if (!*cp) { *cpp = cp; *path = NULL; return (0); } *path = xmalloc(strlen(cp) + 1); /* Check for quoted filenames */ if (*cp == '/"' || *cp == '/'') { quot = *cp++; /* Search for terminating quote, unescape some chars */ for (i = j = 0; i <= strlen(cp); i++) { if (cp[i] == quot) { /* Found quote */ i++; (*path)[j] = '/0'; break; } if (cp[i] == '/0') { /* End of string */ error("Unterminated quote"); goto fail; } if (cp[i] == '//') { /* Escaped characters */ i++; if (cp[i] != '/'' && cp[i] != '/"' && cp[i] != '//') { error("Bad escaped character '//%c'", cp[i]); goto fail; } } (*path)[j++] = cp[i]; } if (j == 0) { error("Empty quotes"); goto fail; } *cpp = cp + i + strspn(cp + i, WHITESPACE); } else { /* Read to end of filename */ end = strpbrk(cp, WHITESPACE); if (end == NULL) end = strchr(cp, '/0'); *cpp = end + strspn(end, WHITESPACE); memcpy(*path, cp, end - cp); (*path)[end - cp] = '/0'; } return (0); fail: xfree(*path); *path = NULL; return (-1);}
开发者ID:Hacker-One,项目名称:backdoor_rootkit,代码行数:65,
示例12: finalize_joinstatic bool finalize_join(void) { char *name = xstrdup(get_value(data, "Name")); if(!name) { fprintf(stderr, "No Name found in invitation!/n"); return false; } if(!check_id(name)) { fprintf(stderr, "Invalid Name found in invitation: %s!/n", name); return false; } if(!netname) netname = grep(data, "NetName"); bool ask_netname = false; char temp_netname[32];make_names: if(!confbasegiven) { free(confbase); confbase = NULL; } make_names(false); free(tinc_conf); free(hosts_dir); xasprintf(&tinc_conf, "%s" SLASH "tinc.conf", confbase); xasprintf(&hosts_dir, "%s" SLASH "hosts", confbase); if(!access(tinc_conf, F_OK)) { fprintf(stderr, "Configuration file %s already exists!/n", tinc_conf); if(confbasegiven) return false; // Generate a random netname, ask for a better one later. ask_netname = true; snprintf(temp_netname, sizeof temp_netname, "join_%x", rand()); netname = temp_netname; goto make_names; } if(mkdir(confbase, 0777) && errno != EEXIST) { fprintf(stderr, "Could not create directory %s: %s/n", confbase, strerror(errno)); return false; } if(mkdir(hosts_dir, 0777) && errno != EEXIST) { fprintf(stderr, "Could not create directory %s: %s/n", hosts_dir, strerror(errno)); return false; } FILE *f = fopen(tinc_conf, "w"); if(!f) { fprintf(stderr, "Could not create file %s: %s/n", tinc_conf, strerror(errno)); return false; } fprintf(f, "Name = %s/n", name); char filename[PATH_MAX]; snprintf(filename, sizeof filename, "%s" SLASH "%s", hosts_dir, name); FILE *fh = fopen(filename, "w"); if(!fh) { fprintf(stderr, "Could not create file %s: %s/n", filename, strerror(errno)); fclose(f); return false; } // Filter first chunk on approved keywords, split between tinc.conf and hosts/Name // Other chunks go unfiltered to their respective host config files const char *p = data; char *l, *value; while((l = get_line(&p))) { // Ignore comments if(*l == '#') continue; // Split line into variable and value int len = strcspn(l, "/t ="); value = l + len; value += strspn(value, "/t "); if(*value == '=') { value++; value += strspn(value, "/t "); } l[len] = 0; // Is it a Name? if(!strcasecmp(l, "Name")) if(strcmp(value, name)) break; else continue; else if(!strcasecmp(l, "NetName")) continue;//.........这里部分代码省略.........
开发者ID:xentec,项目名称:tinc,代码行数:101,
示例13: main//.........这里部分代码省略......... if (verbose < 0) { fprintf(stderr, "%s: verbosity level %d out of range/n", progname, verbose); exit(1); } break; } } argc -= optind; argv += optind; if (argc > 1) { usage(); exit(1); } if (argc == 1 && *argv[0] != '-') { if ((in = fopen(argv[0], "rb")) == NULL) { fprintf(stderr, "%s: unable to open input file %s/n", progname, argv[0]); exit(1); } else strcpy(input_name, argv[0]); } if (!orig) { fprintf(stderr, "%s: original image file not specified, use -i file option/n", progname); exit(1); } if (sig) { char line[32]; fgets(line, sizeof(line), sig); if (strspn(line, "CVSG") >= 4) { fscanf(sig, "%d/n", &n); if (alpha == 0.0) fscanf(sig, "%lf/n", &alpha); else fscanf(sig, "%*f/n"); if (method < 0) fscanf(sig, "%d/n", &method); else fscanf(sig, "%*d/n"); if (filter == 0) fscanf(sig, "%d/n", &filter); else fscanf(sig, "%*d/n"); if (!strcmp(filter_name, "")) fscanf(sig, "%[^/n/r]/n", filter_name); else fscanf(sig, "%*[^/n/r]/n"); } else { fprintf(stderr, "%s: invalid signature file %s/n", progname, signature_name); exit(1); } fclose(sig); } else { fprintf(stderr, "%s: signature file not specified, use -s file option/n", progname); exit(1); } pgm_readpgminit(in, &in_cols, &in_rows, &in_maxval, &in_format); pgm_readpgminit(orig, &orig_cols, &orig_rows, &orig_maxval, &orig_format);
开发者ID:faywong,项目名称:watermarking,代码行数:66,
示例14: makeargv/* Tokenizes strings given argument s, using the given delimiters, * and stores the results in argvp. * If there is an error, -1 is returned, otherwise, the number of tokens * is returned. */int makeargv(const char *s, const char *delimiters, char ***argvp) { int error; int i; int numtokens; const char *snew; char *t; /* Ensure that s, delimiters, and argvp are not NULL */ if ((s == NULL) || (delimiters == NULL) || (argvp == NULL)) { /* If they are, set errno to indicate the error */ errno = EINVAL; /* and return -1 to report the error condition back to the * caller */ return -1; } /* Dereferencing the triple pointer argvp, we get the value * of the double pointer passed in, and set it to NULL. * I don't see why this is necessary, since we are allocating * it new memory with malloc() later. */ *argvp = NULL; /* Here we increment the pointer s, by the number of bytes needed to * reach the first character not in the delimiter set. */ snew = s + strspn(s, delimiters); /* snew is real start of string */ /* Then we allocate, in t, enough bytes to hold snew and a null character. */ if ((t = malloc(strlen(snew) + 1)) == NULL) { /* Problem allocating memory, so let the caller know */ return -1; } /* Once allocated, we can copy snew to t */ strcpy(t, snew); /* Initialize automatic variable numtokens */ numtokens = 0; /* Check if there is at least one token. */ if (strtok(t, delimiters) != NULL) { /* count the number of tokens in s */ /* Loop through until there are no more tokens, counting each one. */ for (numtokens = 1; strtok(NULL, delimiters) != NULL; numtokens++); } /* create argument array for ptrs to the tokens */ if ((*argvp = malloc((numtokens + 1) * sizeof(char *))) == NULL) { /* Save errno, in case it is set by free() */ error = errno; free(t); errno = error; return -1; } /* insert pointers to tokens into the argument array */ if (numtokens == 0) { /* There were no tokens, so free t. */ free(t); } else { /* Reset t to original snew value, since strtok() modified it. */ strcpy(t, snew); /* Put the first token in it's place in the array. */ **argvp = strtok(t, delimiters); for (i = 1; i < numtokens; i++) { /* Put a token into each char* in argvp* * incrementing the pointer each time to * point to the next location in memory with i. */ *((*argvp) + i) = strtok(NULL, delimiters); } } /* Put in final NULL pointer to mark the end of the array. */ *((*argvp) + numtokens) = NULL; return numtokens;}
开发者ID:JReyLBC,项目名称:csis4600,代码行数:74,
示例15: process_config_line//.........这里部分代码省略......... return 0; case oUserKnownHostsFile: cpptr = (char **)&options->user_hostfiles; uintptr = &options->num_user_hostfiles; max_entries = SSH_MAX_HOSTS_FILES; goto parse_char_array; case oHostName: charptr = &options->hostname; goto parse_string; case oHostKeyAlias: charptr = &options->host_key_alias; goto parse_string; case oPreferredAuthentications: charptr = &options->preferred_authentications; goto parse_string; case oBindAddress: charptr = &options->bind_address; goto parse_string; case oPKCS11Provider: charptr = &options->pkcs11_provider; goto parse_string; case oProxyCommand: charptr = &options->proxy_command;parse_command: if (s == NULL) fatal("%.200s line %d: Missing argument.", filename, linenum); len = strspn(s, WHITESPACE "="); if (*activep && *charptr == NULL) *charptr = xstrdup(s + len); return 0; case oPort: intptr = &options->port;parse_int: arg = strdelim(&s); if (!arg || *arg == '/0') fatal("%.200s line %d: Missing argument.", filename, linenum); if (arg[0] < '0' || arg[0] > '9') fatal("%.200s line %d: Bad number.", filename, linenum); /* Octal, decimal, or hex format? */ value = strtol(arg, &endofnumber, 0); if (arg == endofnumber) fatal("%.200s line %d: Bad number.", filename, linenum); if (*activep && *intptr == -1) *intptr = value; break; case oConnectionAttempts: intptr = &options->connection_attempts; goto parse_int; case oCipher: intptr = &options->cipher; arg = strdelim(&s); if (!arg || *arg == '/0') fatal("%.200s line %d: Missing argument.", filename, linenum); value = cipher_number(arg); if (value == -1)
开发者ID:UNGLinux,项目名称:Obase,代码行数:67,
示例16: switchsize_t sinsp_filter_value_parser::string_to_rawval(const char* str, uint32_t len, uint8_t *storage, string::size_type max_len, ppm_param_type ptype){ size_t parsed_len; switch(ptype) { case PT_INT8: *(int8_t*)storage = sinsp_numparser::parsed8(str); parsed_len = sizeof(int8_t); break; case PT_INT16: *(int16_t*)storage = sinsp_numparser::parsed16(str); parsed_len = sizeof(int16_t); break; case PT_INT32: *(int32_t*)storage = sinsp_numparser::parsed32(str); parsed_len = sizeof(int32_t); break; case PT_INT64: case PT_FD: case PT_ERRNO: *(int64_t*)storage = sinsp_numparser::parsed64(str); parsed_len = sizeof(int64_t); break; case PT_L4PROTO: // This can be resolved in the future case PT_FLAGS8: case PT_UINT8: *(uint8_t*)storage = sinsp_numparser::parseu8(str); parsed_len = sizeof(int8_t); break; case PT_PORT: { string in(str); if(in.empty()) { *(uint16_t*)storage = 0; } else { // if the string is made only of numbers if(strspn(in.c_str(), "0123456789") == in.size()) { *(uint16_t*)storage = stoi(in); } else { struct servent* se = getservbyname(in.c_str(), NULL); if(se == NULL) { throw sinsp_exception("unrecognized protocol " + in); } else { *(uint16_t*)storage = ntohs(getservbyname(in.c_str(), NULL)->s_port); } } } parsed_len = sizeof(int16_t); break; } case PT_FLAGS16: case PT_UINT16: *(uint16_t*)storage = sinsp_numparser::parseu16(str); parsed_len = sizeof(uint16_t); break; case PT_FLAGS32: case PT_UINT32: *(uint32_t*)storage = sinsp_numparser::parseu32(str); parsed_len = sizeof(uint32_t); break; case PT_UINT64: *(uint64_t*)storage = sinsp_numparser::parseu64(str); parsed_len = sizeof(uint64_t); break; case PT_RELTIME: case PT_ABSTIME: *(uint64_t*)storage = sinsp_numparser::parseu64(str); parsed_len = sizeof(uint64_t); break; case PT_CHARBUF: case PT_SOCKADDR: case PT_SOCKFAMILY: { len = (uint32_t)strlen(str); if(len >= max_len) { throw sinsp_exception("filter parameter too long:" + string(str)); } memcpy(storage, str, len); *(uint8_t*)(&storage[len]) = 0; parsed_len = len; } break; case PT_BOOL: parsed_len = sizeof(uint32_t); if(string(str) == "true")//.........这里部分代码省略.........
开发者ID:draios,项目名称:sysdig,代码行数:101,
示例17: strspnstatic const char *set_attr(const char *str){ const char *func; size_t len = strspn(str, "0123456789;"); func = str + len; switch (*func) { case 'm': do { long val = strtol(str, (char **)&str, 10); switch (val) { case 0: /* reset */ attr = plain_attr; negative = 0; break; case 1: /* bold */ attr |= FOREGROUND_INTENSITY; break; case 2: /* faint */ case 22: /* normal */ attr &= ~FOREGROUND_INTENSITY; break; case 3: /* italic */ /* Unsupported */ break; case 4: /* underline */ case 21: /* double underline */ /* Wikipedia says this flag does nothing */ /* Furthermore, mingw doesn't define this flag attr |= COMMON_LVB_UNDERSCORE; */ break; case 24: /* no underline */ /* attr &= ~COMMON_LVB_UNDERSCORE; */ break; case 5: /* slow blink */ case 6: /* fast blink */ /* We don't have blink, but we do have background intensity */ attr |= BACKGROUND_INTENSITY; break; case 25: /* no blink */ attr &= ~BACKGROUND_INTENSITY; break; case 7: /* negative */ negative = 1; break; case 27: /* positive */ negative = 0; break; case 8: /* conceal */ case 28: /* reveal */ /* Unsupported */ break; case 30: /* Black */ attr &= ~FOREGROUND_ALL; break; case 31: /* Red */ attr &= ~FOREGROUND_ALL; attr |= FOREGROUND_RED; break; case 32: /* Green */ attr &= ~FOREGROUND_ALL; attr |= FOREGROUND_GREEN; break; case 33: /* Yellow */ attr &= ~FOREGROUND_ALL; attr |= FOREGROUND_RED | FOREGROUND_GREEN; break; case 34: /* Blue */ attr &= ~FOREGROUND_ALL; attr |= FOREGROUND_BLUE; break; case 35: /* Magenta */ attr &= ~FOREGROUND_ALL; attr |= FOREGROUND_RED | FOREGROUND_BLUE; break; case 36: /* Cyan */ attr &= ~FOREGROUND_ALL; attr |= FOREGROUND_GREEN | FOREGROUND_BLUE; break; case 37: /* White */ attr |= FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; break; case 38: /* Unknown */ break; case 39: /* reset */ attr &= ~FOREGROUND_ALL; attr |= (plain_attr & FOREGROUND_ALL); break; case 40: /* Black */ attr &= ~BACKGROUND_ALL; break; case 41: /* Red */ attr &= ~BACKGROUND_ALL; attr |= BACKGROUND_RED; break; case 42: /* Green */ attr &= ~BACKGROUND_ALL;//.........这里部分代码省略.........
开发者ID:StasKoval,项目名称:cpuminer-opt,代码行数:101,
示例18: mainint main(int argc, char **argv){ char server[STRING_SIZE]; char port[STRING_SIZE]; char opt_port[STRING_SIZE]; char user[STRING_SIZE]; char opt_user[STRING_SIZE]; char password[STRING_SIZE]; char opt_password[STRING_SIZE]; char from[STRING_SIZE]; char to[STRING_SIZE]; char hostname[STRING_SIZE]; char domainname[STRING_SIZE]; char subject[STRING_SIZE]; char subject_prefix[STRING_SIZE]; char message[STRING_SIZE]; char attachment[STRING_SIZE]; char *opt_subject = NULL; char *opt_messagefile = NULL; char *opt_attachment = NULL; char date[STRING_SIZE]; NODEKV *kv = NULL; NODEKV *main_kv = NULL; int rc; time_t curtime; struct tm *loctime; static struct option long_options[] = { { "subject", required_argument, 0, 's'}, { "messagefile", required_argument, 0, 'm'}, { "delete", no_argument, 0, 'd'}, { "attachment", required_argument, 0, 'a'}, { "verbose", no_argument, 0, 'v'}, { "help", no_argument, 0, 'h'}, {0, 0, 0, 0} }; int c; int option_index = 0; if (!(initsetuid())) exit(1); while ((c = getopt_long(argc, argv, "s:m:da:vh", long_options, &option_index)) != -1) { switch (c) { case 0: break; case 's': verbose_printf(3, "Option s ... /n"); flag_subject = 1; /* check a valid subject */ int len = 0; len = strlen(optarg); if (len > STRING_SIZE - 1) { fprintf(stdout, "Subject too long: %s/n", optarg); exit(EMAIL_ERR_SUBJECT); } if (strspn(optarg, LETTERS_NUMBERS "-_:.+, ") != len) { fprintf(stdout, "Invalid character in subject (%s)/n", optarg); exit(EMAIL_ERR_SUBJECT); } opt_subject = strdup(optarg); break; case 'm': verbose_printf(3, "Option m ... /n"); flag_messagefile = 1; opt_messagefile = strdup(optarg); break; case 'd': verbose_printf(3, "Option d ... /n"); flag_delete_messagefile = 1; break; case 'a': verbose_printf(3, "Option a ... /n"); flag_attachment = 1; opt_attachment = strdup(optarg); break; case 'v': /* verbose */ flag_verbose++; break; case 'h': usage(argv[0], EMAIL_SUCCESS); default: fprintf(stdout, "unknown option/n"); usage(argv[0], EMAIL_ERR_ANY); } } verbose_printf(1, "Reading email settings ... /n"); if (read_kv_from_file(&kv, "/var/ipcop/email/settings") != SUCCESS) { fprintf(stdout, "Cannot read email settings/n"); exit(EMAIL_ERR_ANY); } strcpy(server, ""); verbose_printf(2, "Reading EMAIL_SERVER ... /n"); if (find_kv_default(kv, "EMAIL_SERVER", server) != SUCCESS) { fprintf(stdout, "Cannot read EMAIL_SERVER/n");//.........这里部分代码省略.........
开发者ID:ewon,项目名称:efive,代码行数:101,
示例19: parse_timestr/* * -- parse_timestr() * * This function parse the time string of a query. The string is made of * two parts representing the two extreme of the time window. They two * parts are separated by a colon (:). * Valid formats for the start and end times are as follows: * * . 0, to indicate the time the query is received; * . @[cc[yy[mm[dd[hhmmss]]]]], to indicate an exact time; * . [+|-][[^0-9]d][[^0-9]h][[^0-9]m][[^0-9]s], to indicate an offset * from the time the query is received. * */static uint32_tparse_timestr(char * str, timestamp_t * base) { struct tm timeinfo; time_t ts; char * wh; size_t len; int adding; assert(str != NULL); assert(base != NULL); ts = TS2SEC(*base); gmtime_r(&ts, &timeinfo); /* look if this is a start or end */ wh = index(str, ':'); len = (wh == NULL)? strlen(str) : (size_t) (wh - str); adding = 0; switch (str[0]) { case '@': /* absolute timestamp */ for (str++, len--; len > 0; str += 2, len -= 2) { char val[3] = {0}; /* get two digits */ bcopy(str, val, 2); if (len == 14) /* century */ timeinfo.tm_year = (atoi(val) * 100) - 1900; else if (len == 12) /* year */ timeinfo.tm_year = atoi(val) + 100*(timeinfo.tm_year/100); else if (len == 10) /* month */ timeinfo.tm_mon = atoi(val) - 1; else if (len == 8) /* day */ timeinfo.tm_mday = atoi(val); else if (len == 6) /* hour */ timeinfo.tm_hour = atoi(val); else if (len == 4) /* minute */ timeinfo.tm_min = atoi(val); else if (len == 2) /* second */ timeinfo.tm_sec = atoi(val); else /* error */ break; } if (len > 0) { logmsg(LOGWARN, "time %s incorrect, using current time/n", str); return TS2SEC(*base); } ts = timegm(&timeinfo); *base = TIME2TS(ts, 0); break; case '+': /* relative timestamp (after current time) */ adding = 2; /* pass thru */ case '-': /* relative timestamp (before current time) */ adding--; /* skip first character */ str++; len--; /* check for one letter (in [dhms]) at a time */ while (len > 0) { int x; int val; val = atoi(str); x = strspn(str, "1234567890"); str += x; len -= x; if (str[0] == 'd') /* day */ timeinfo.tm_mday += adding*val; else if (str[0] == 'h') /* hour */ timeinfo.tm_hour += adding*val; else if (str[0] == 'm') /* minute */ timeinfo.tm_min += adding*val; else if (str[0] == 's') /* seconds */ timeinfo.tm_sec += adding*val; else /* error */ break; //.........这里部分代码省略.........
开发者ID:JackieXie168,项目名称:como,代码行数:101,
示例20: cmd_dr_runstatic intcmd_dr_run( chain_t *chain, char *params[] ){ int dir = 1; tap_register *r; if (cmd_params( params ) < 1 || cmd_params( params ) > 2) return -1; if (!cmd_test_cable( chain )) return 1; if (!chain->parts) { printf( _("Run /"detect/" first./n") ); return 1; } if (chain->active_part >= chain->parts->len) { printf( _("%s: no active part/n"), "dr" ); return 1; } if (chain->parts->parts[chain->active_part]->active_instruction == NULL) { printf( _("%s: part without active instruction/n"), "dr" ); return 1; } if (chain->parts->parts[chain->active_part]->active_instruction->data_register == NULL) { printf( _("%s: part without active data register/n"), "dr" ); return 1; } if (params[1]) { if (strcasecmp( params[1], "in" ) == 0) dir = 0; else if (strcasecmp( params[1], "out" ) == 0) dir = 1; else { unsigned int bit; if (strspn(params[1], "01") != strlen(params[1])) { return -1; } r = chain->parts->parts[chain->active_part]->active_instruction->data_register->in; if (r->len != strlen(params[1])) { printf( _("%s: register length mismatch/n"), "dr" ); return 1; } for (bit = 0; params[1][bit]; bit++) { r->data[r->len - 1 - bit] = (params[1][bit] == '1'); } dir = 0; } } if (dir) r = chain->parts->parts[chain->active_part]->active_instruction->data_register->out; else r = chain->parts->parts[chain->active_part]->active_instruction->data_register->in; printf( _("%s/n"), register_get_string( r ) ); return 1;}
开发者ID:dihmuzikien,项目名称:ECE473,代码行数:63,
示例21: MAINint MAIN(int argc, char **argv) { int ret=1,i; const char **pp; int verbose=0, list_cap=0, test_avail=0, test_avail_noise = 0; ENGINE *e; STACK *engines = sk_new_null(); STACK *pre_cmds = sk_new_null(); STACK *post_cmds = sk_new_null(); int badops=1; BIO *bio_out=NULL; const char *indent = " "; apps_startup(); SSL_load_error_strings(); if (bio_err == NULL) bio_err=BIO_new_fp(stderr,BIO_NOCLOSE); if (!load_config(bio_err, NULL)) goto end; bio_out=BIO_new_fp(stdout,BIO_NOCLOSE);#ifdef OPENSSL_SYS_VMS { BIO *tmpbio = BIO_new(BIO_f_linebuffer()); bio_out = BIO_push(tmpbio, bio_out); }#endif argc--; argv++; while (argc >= 1) { if (strncmp(*argv,"-v",2) == 0) { if(strspn(*argv + 1, "v") < strlen(*argv + 1)) goto skip_arg_loop; if((verbose=strlen(*argv + 1)) > 4) goto skip_arg_loop; } else if (strcmp(*argv,"-c") == 0) list_cap=1; else if (strncmp(*argv,"-t",2) == 0) { test_avail=1; if(strspn(*argv + 1, "t") < strlen(*argv + 1)) goto skip_arg_loop; if((test_avail_noise = strlen(*argv + 1) - 1) > 1) goto skip_arg_loop; } else if (strcmp(*argv,"-pre") == 0) { argc--; argv++; if (argc == 0) goto skip_arg_loop; sk_push(pre_cmds,*argv); } else if (strcmp(*argv,"-post") == 0) { argc--; argv++; if (argc == 0) goto skip_arg_loop; sk_push(post_cmds,*argv); } else if ((strncmp(*argv,"-h",2) == 0) || (strcmp(*argv,"-?") == 0)) goto skip_arg_loop; else sk_push(engines,*argv); argc--; argv++; } /* Looks like everything went OK */ badops = 0;skip_arg_loop: if (badops) { for (pp=engine_usage; (*pp != NULL); pp++) BIO_printf(bio_err,"%s",*pp); goto end; } if (sk_num(engines) == 0) { for(e = ENGINE_get_first(); e != NULL; e = ENGINE_get_next(e)) { sk_push(engines,(char *)ENGINE_get_id(e)); } } for (i=0; i<sk_num(engines); i++) { const char *id = sk_value(engines,i); if ((e = ENGINE_by_id(id)) != NULL) { const char *name = ENGINE_get_name(e); /* Do "id" first, then "name". Easier to auto-parse. */ BIO_printf(bio_out, "(%s) %s/n", id, name); util_do_cmds(e, pre_cmds, bio_out, indent);//.........这里部分代码省略.........
开发者ID:RafaelRMachado,项目名称:MinnowBoard,代码行数:101,
示例22: write_cfstatic void write_cf(void){ char tmp[0x100], rv[0x40]; struct conf_item *ci = NULL; char *lp, *cp; int add, i; char *cfname = get_confname(); int cfld = ll_create(); FILE *fd = fopen(cfname, "w"); if (fd == NULL) err_sys("failed to open configuration file '%s'", cfname); for (ll_reset(conf_items); (ci = ll_getall(conf_items)); ) { if (ci->type != t_sep && ci->type != t_func && (!ci->dep || (ci->dep && *ci->dep))) { switch (ci->type) { case t_int: sprintf(rv, "%d", *ci->v.i); break; case t_list: if (!argv_count(ci->list)) continue; sprintf(rv, "%s", ci->list[*ci->v.i]); str_tolower(rv); break; case t_sep: case t_func: break; } add = 1; for (i = 0; i < ll_size(cfld); i++) { lp = ll_get(cfld, i); cp = lp += strspn(lp, " "); if (!strncasecmp(cp, ci->cfname, strcspn(cp, " =")) && strlen(ci->cfname) == strcspn(cp, " =")) { add = 0; cp += strcspn(cp, "=") + 1; cp += strspn(cp, " "); strncpy(tmp, cp, strcspn(cp, " #/n")); if (strcasecmp(tmp, rv)) { strncpy(tmp, lp, strcspn(lp, " =")); tmp[strcspn(lp, " =")] = '/0'; strcat(tmp, " = "); strcat(tmp, rv); strcat(tmp, "/n"); ll_replace(cfld, i, "s", tmp); } } } if (add) { strcpy(tmp, ci->cfname); strcat(tmp, " = "); strcat(tmp, rv); strcat(tmp, "/n"); ll_push(cfld, "s", tmp); } } } for (ll_reset(cfld); (lp = ll_getall(cfld)); ) fputs(lp, fd); fclose(fd); ll_destroy(cfld); free(cfname);}
开发者ID:uoaerg,项目名称:wavemon,代码行数:70,
示例23: add_linegfarm_error_tadd_line(char *line, int lineno){ gfarm_error_t e; long port, ncpu, flags; int len, nhostaliases; char *s, *hostname, *architecture; char *hostaliases[MAX_HOSTALIASES + 1]; /* parse architecture */ line += strspn(line, space); /* skip space */ len = strcspn(line, space); if (len == 0 || line[len] == '/0') return (invalid_input(lineno)); line[len] = '/0'; architecture = line; line += len + 1; s = validate_architecture(architecture); if (s != NULL) { fprintf(stderr, "line %d: invalid character '%c' in architecture /"%s/"/n", lineno, *s, architecture); return (GFARM_ERR_INVALID_ARGUMENT); } e = parse_string_long(&line, lineno, "ncpu", &ncpu); if (e != GFARM_ERR_NO_ERROR) return (e); /* parse hostname */ line += strspn(line, space); /* skip space */ len = strcspn(line, space); if (len == 0) return (invalid_input(lineno)); hostname = line; if (line[len] == '/0') { line += len; } else { line[len] = '/0'; line += len + 1; } s = validate_hostname(hostname); if (s != NULL) { fprintf(stderr, "line %d: invalid character '%c' in hostname /"%s/"/n", lineno, *s, hostname); return (GFARM_ERR_INVALID_ARGUMENT); } e = parse_string_long(&line, lineno, "port", &port); if (e != GFARM_ERR_NO_ERROR) return (e); e = parse_string_long(&line, lineno, "flags", &flags); if (e != GFARM_ERR_NO_ERROR) return (e); /* parse hostaliases */ for (nhostaliases = 0;; nhostaliases++) { line += strspn(line, space); /* skip space */ if (*line == '/0') break; len = strcspn(line, space); /* assert(len > 0); */ if (nhostaliases >= MAX_HOSTALIASES) { fprintf(stderr, "line %d: " "number of hostaliases exceeds %d/n", lineno, nhostaliases); return (GFARM_ERR_INVALID_ARGUMENT); } hostaliases[nhostaliases] = line; if (line[len] == '/0') { line += len; } else { line[len] = '/0'; line += len + 1; } s = validate_hostname(hostaliases[nhostaliases]); if (s != NULL) { fprintf(stderr, "line %d: " "invalid character '%c' in hostalias /"%s/"/n", lineno, *s, hostaliases[nhostaliases]); return (GFARM_ERR_INVALID_ARGUMENT); } } hostaliases[nhostaliases] = NULL; e = add_host(hostname, port, hostaliases, architecture, ncpu, flags); if (e != GFARM_ERR_NO_ERROR) fprintf(stderr, "line %d: %s/n", lineno, gfarm_error_string(e)); return (e);}
开发者ID:ddk50,项目名称:gfarm_v2,代码行数:93,
示例24: concat_openstatic av_cold int concat_open(URLContext *h, const char *uri, int flags){ char *node_uri = NULL; int err = 0; int64_t size; size_t len, i; URLContext *uc; struct concat_data *data = h->priv_data; struct concat_nodes *nodes; av_strstart(uri, "concat:", &uri); for (i = 0, len = 1; uri[i]; i++) { if (uri[i] == *AV_CAT_SEPARATOR) { /* integer overflow */ if (++len == UINT_MAX / sizeof(*nodes)) { av_freep(&h->priv_data); return AVERROR(ENAMETOOLONG); } } } if (!(nodes = av_realloc(NULL, sizeof(*nodes) * len))) return AVERROR(ENOMEM); else data->nodes = nodes; /* handle input */ if (!*uri) err = AVERROR(ENOENT); for (i = 0; *uri; i++) { /* parsing uri */ len = strcspn(uri, AV_CAT_SEPARATOR); if ((err = av_reallocp(&node_uri, len + 1)) < 0) break; av_strlcpy(node_uri, uri, len + 1); uri += len + strspn(uri + len, AV_CAT_SEPARATOR); /* creating URLContext */ if ((err = ffurl_open(&uc, node_uri, flags, &h->interrupt_callback, NULL)) < 0) break; /* creating size */ if ((size = ffurl_size(uc)) < 0) { ffurl_close(uc); err = AVERROR(ENOSYS); break; } /* assembling */ nodes[i].uc = uc; nodes[i].size = size; } av_free(node_uri); data->length = i; if (err < 0) concat_close(h); else if ((err = av_reallocp(&nodes, data->length * sizeof(*nodes))) < 0) concat_close(h); else data->nodes = nodes; return err;}
开发者ID:VFR-maniac,项目名称:libav,代码行数:65,
示例25: mainint main(int argc, char *argv[]) { FILE *in = stdin; FILE *out = stdout; FILE *sig = NULL; char signature_name[MAXPATHLEN]; char output_name[MAXPATHLEN] = "(stdout)"; char input_name[MAXPATHLEN] = "(stdin)"; int correlation_only = 0; int c, i; int corr1 = 0, match1 = 0; int corr2 = 0, match2 = 0; int verbose = 0; char line[1024]; progname = argv[0]; while ((c = getopt(argc, argv, "h?Co:s:v:")) != EOF) { switch (c) { case 'h': case '?': usage(); break; case 'C': correlation_only = 1; break; case 'o': if ((out = fopen(optarg, "w")) == NULL) { fprintf(stderr, "%s: unable to open output file %s/n", progname, optarg); exit(1); } strcpy(output_name, optarg); break; case 's': if ((sig = fopen(optarg, "r")) == NULL) { fprintf(stderr, "%s: unable to open signature file %s/n", progname, optarg); exit(1); } strcpy(signature_name, optarg); break; case 'v': verbose = atoi(optarg); if (verbose < 0) { fprintf(stderr, "%s: verbosity level %d out of range/n", progname, verbose); exit(1); } break; } } argc -= optind; argv += optind; if (argc > 1) { usage(); exit(1); } if (argc == 1 && *argv[0] != '-') { if ((in = fopen(argv[0], "r")) == NULL) { fprintf(stderr, "%s: unable to open input file %s/n", progname, argv[0]); exit(1); } else strcpy(input_name, argv[0]); } if (sig) { fgets(line, sizeof(line), sig); if (strspn(line, "FR2SG") >= 5) { fscanf(sig, "%d/n", &nbit_signature); fscanf(sig, "%*f/n"); fscanf(sig, "%*f/n"); fscanf(sig, "%*d/n"); n_signature = NBITSTOBYTES(nbit_signature); fread(signature, sizeof(char), n_signature, sig); fscanf(sig, "/n"); } else { fprintf(stderr, "%s: invalid signature file %s/n", progname, signature_name); exit(1); } fclose(sig); } else { fprintf(stderr, "%s: original signature file not specified, use -s file option/n", progname); exit(1); } fgets(line, sizeof(line), in); if (strspn(line, "FR2WM") >= 5) { fscanf(in, "%d/n", &nbit_signature1); n_signature1 = NBITSTOBYTES(nbit_signature1); fread(signature1, sizeof(char), n_signature1, in);// fscanf(in, "/n"); fscanf(in, "%d/n", &nbit_signature2);//.........这里部分代码省略.........
开发者ID:faywong,项目名称:watermarking,代码行数:101,
示例26: appendShellString/* * Append the given string to the shell command being built in the buffer, * with shell-style quoting as needed to create exactly one argument. * * Forbid LF or CR characters, which have scant practical use beyond designing * security breaches. The Windows command shell is unusable as a conduit for * arguments containing LF or CR characters. A future major release should * reject those characters in CREATE ROLE and CREATE DATABASE, because use * there eventually leads to errors here. */voidappendShellString(PQExpBuffer buf, const char *str){#ifdef WIN32 int backslash_run_length = 0;#endif const char *p; /* * Don't bother with adding quotes if the string is nonempty and clearly * contains only safe characters. */ if (*str != '/0' && strspn(str, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_./:") == strlen(str)) { appendPQExpBufferStr(buf, str); return; }#ifndef WIN32 appendPQExpBufferChar(buf, '/''); for (p = str; *p; p++) { if (*p == '/n' || *p == '/r') { fprintf(stderr, _("shell command argument contains a newline or carriage return: /"%s/"/n"), str); exit(EXIT_FAILURE); } if (*p == '/'') appendPQExpBufferStr(buf, "'/"'/"'"); else appendPQExpBufferChar(buf, *p); } appendPQExpBufferChar(buf, '/'');#else /* WIN32 */ /* * A Windows system() argument experiences two layers of interpretation. * First, cmd.exe interprets the string. Its behavior is undocumented, * but a caret escapes any byte except LF or CR that would otherwise have * special meaning. Handling of a caret before LF or CR differs between * "cmd.exe /c" and other modes, and it is unusable here. * * Second, the new process parses its command line to construct argv (see * https://msdn.microsoft.com/en-us/library/17w5ykft.aspx). This treats * backslash-double quote sequences specially. */ appendPQExpBufferStr(buf, "^/""); for (p = str; *p; p++) { if (*p == '/n' || *p == '/r') { fprintf(stderr, _("shell command argument contains a newline or carriage return: /"%s/"/n"), str); exit(EXIT_FAILURE); } /* Change N backslashes before a double quote to 2N+1 backslashes. */ if (*p == '"') { while (backslash_run_length) { appendPQExpBufferStr(buf, "^//"); backslash_run_length--; } appendPQExpBufferStr(buf, "^//"); } else if (*p == '//') backslash_run_length++; else backslash_run_length = 0; /* * Decline to caret-escape the most mundane characters, to ease * debugging and lest we approach the command length limit. */ if (!((*p >= 'a' && *p <= 'z') || (*p >= 'A' && *p <= 'Z') || (*p >= '0' && *p <= '9'))) appendPQExpBufferChar(buf, '^'); appendPQExpBufferChar(buf, *p); } /* * Change N backslashes at end of argument to 2N backslashes, because they * precede the double quote that terminates the argument.//.........这里部分代码省略.........
开发者ID:Tao-Ma,项目名称:postgres,代码行数:101,
示例27: PEM_get_EVP_CIPHER_INFO/* * This implements a very limited PEM header parser that does not support the * full grammar of rfc1421. In particular, folded headers are not supported, * nor is additional whitespace. * * A robust implementation would make use of a library that turns the headers * into a BIO from which one folded line is read at a time, and is then split * into a header label and content. We would then parse the content of the * headers we care about. This is overkill for just this limited use-case, but * presumably we also parse rfc822-style headers for S/MIME, so a common * abstraction might well be more generally useful. */int PEM_get_EVP_CIPHER_INFO(char *header, EVP_CIPHER_INFO *cipher){ static const char ProcType[] = "Proc-Type:"; static const char ENCRYPTED[] = "ENCRYPTED"; static const char DEKInfo[] = "DEK-Info:"; const EVP_CIPHER *enc = NULL; int ivlen; char *dekinfostart, c; cipher->cipher = NULL; if ((header == NULL) || (*header == '/0') || (*header == '/n')) return 1; if (strncmp(header, ProcType, sizeof(ProcType)-1) != 0) { PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO, PEM_R_NOT_PROC_TYPE); return 0; } header += sizeof(ProcType)-1; header += strspn(header, " /t"); if (*header++ != '4' || *header++ != ',') return 0; header += strspn(header, " /t"); /* We expect "ENCRYPTED" followed by optional white-space + line break */ if (strncmp(header, ENCRYPTED, sizeof(ENCRYPTED)-1) != 0 || strspn(header+sizeof(ENCRYPTED)-1, " /t/r/n") == 0) { PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO, PEM_R_NOT_ENCRYPTED); return 0; } header += sizeof(ENCRYPTED)-1; header += strspn(header, " /t/r"); if (*header++ != '/n') { PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO, PEM_R_SHORT_HEADER); return 0; } /*- * https://tools.ietf.org/html/rfc1421#section-4.6.1.3 * We expect "DEK-Info: algo[,hex-parameters]" */ if (strncmp(header, DEKInfo, sizeof(DEKInfo)-1) != 0) { PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO, PEM_R_NOT_DEK_INFO); return 0; } header += sizeof(DEKInfo)-1; header += strspn(header, " /t"); /* * DEK-INFO is a comma-separated combination of algorithm name and optional * parameters. */ dekinfostart = header; header += strcspn(header, " /t,"); c = *header; *header = '/0'; cipher->cipher = enc = EVP_get_cipherbyname(dekinfostart); *header = c; header += strspn(header, " /t"); if (enc == NULL) { PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO, PEM_R_UNSUPPORTED_ENCRYPTION); return 0; } ivlen = EVP_CIPHER_iv_length(enc); if (ivlen > 0 && *header++ != ',') { PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO, PEM_R_MISSING_DEK_IV); return 0; } else if (ivlen == 0 && *header == ',') { PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO, PEM_R_UNEXPECTED_DEK_IV); return 0; } if (!load_iv(&header, cipher->iv, EVP_CIPHER_iv_length(enc))) return 0; return 1;}
开发者ID:Frrank1,项目名称:node,代码行数:90,
注:本文中的strspn函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ strstart函数代码示例 C++ strsplit函数代码示例 |