static void load_drivers(void) { struct ibv_driver_name *name, *next_name; const char *env; char *list, *env_name; /* * Only use drivers passed in through the calling user's * environment if we're not running setuid. */ if (getuid() == geteuid()) { if ((env = getenv("RDMAV_DRIVERS"))) { list = strdupa(env); while ((env_name = strsep(&list, ":;"))) load_driver(env_name); } else if ((env = getenv("IBV_DRIVERS"))) { list = strdupa(env); while ((env_name = strsep(&list, ":;"))) load_driver(env_name); } } for (name = driver_name_list, next_name = name ? name->next : NULL; name; name = next_name, next_name = name ? name->next : NULL) { load_driver(name->name); free(name->name); free(name); } }
void parseCommandLine(char* cmdLineTxt, char*** argv, int* argc){ int count = 1; char *cmdLineCopy = strdupa(cmdLineTxt); char* match = strtok(cmdLineCopy, " "); // First, count the number of arguments while(match != NULL){ count++; match = strtok(NULL, " "); } *argv = malloc(sizeof(char*) * (count+1)); (*argv)[count] = 0; **argv = strdup("test"); // the program name would normally go in here if (count > 1){ int i=1; cmdLineCopy = strdupa(cmdLineTxt); match = strtok(cmdLineCopy, " "); do{ (*argv)[i++] = strdup(match); match = strtok(NULL, " "); } while(match != NULL); } *argc = count; }
std::string find_executable(const char *name) { struct stat s; char *tmpPath = getenv("PATH"); char *p, *n, *path; if (tmpPath) path = strdupa(tmpPath); else path = strdupa("/bin:/var/bin:/sbin:/var/sbin"); if (name[0] == '/') { /* full path given */ if (!access(name, X_OK) && !stat(name, &s) && S_ISREG(s.st_mode)) return std::string(name); return ""; } p = path; while (p) { n = strchr(p, ':'); if (n) *n++ = '\0'; if (*p != '\0') { std::string tmp = std::string(p) + "/" + std::string(name); const char *f = tmp.c_str(); if (!access(f, X_OK) && !stat(f, &s) && S_ISREG(s.st_mode)) return tmp; } p = n; } return ""; }
static void test_string_erase(void) { char *x; x = strdupa(""); assert_se(streq(string_erase(x), "")); x = strdupa("1"); assert_se(streq(string_erase(x), "x")); x = strdupa("12"); assert_se(streq(string_erase(x), "xx")); x = strdupa("123"); assert_se(streq(string_erase(x), "xxx")); x = strdupa("1234"); assert_se(streq(string_erase(x), "xxxx")); x = strdupa("12345"); assert_se(streq(string_erase(x), "xxxxx")); x = strdupa("123456"); assert_se(streq(string_erase(x), "xxxxxx")); x = strdupa("1234567"); assert_se(streq(string_erase(x), "xxxxxxx")); x = strdupa("12345678"); assert_se(streq(string_erase(x), "xxxxxxxx")); x = strdupa("123456789"); assert_se(streq(string_erase(x), "xxxxxxxxx")); }
static int _rg_write_meta (DB_playItem_t *track) { const char *path = NULL; const char *decoder_id = NULL; deadbeef->pl_lock (); path = strdupa (deadbeef->pl_find_meta_raw (track, ":URI")); int is_subtrack = deadbeef->pl_get_item_flags (track) & DDB_IS_SUBTRACK; if (is_subtrack) { trace ("rg_scanner: Can't write to subtrack of file: %s\n", path); deadbeef->pl_unlock (); return -1; } decoder_id = deadbeef->pl_find_meta_raw (track, ":DECODER"); if (!decoder_id) { trace ("rg_scanner: Invalid decoder in track %s\n", path); deadbeef->pl_unlock (); return -1; } decoder_id = strdupa (decoder_id); int match = track && decoder_id; deadbeef->pl_unlock (); if (match) { int is_subtrack = deadbeef->pl_get_item_flags (track) & DDB_IS_SUBTRACK; if (is_subtrack) { return 0; // only write tags for actual tracks } // find decoder DB_decoder_t *dec = NULL; DB_decoder_t **decoders = deadbeef->plug_get_decoder_list (); for (int i = 0; decoders[i]; i++) { if (!strcmp (decoders[i]->plugin.id, decoder_id)) { dec = decoders[i]; if (dec->write_metadata) { if (dec->write_metadata (track)) { trace ("rg_scanner: Failed to write tag to %s\n", path); return -1; } } else { trace ("rg_scanner: Writing tags is not supported for the file %s\n", path); } break; } } } else { trace ("rg_scanner: Could not find matching decoder for %s\n", path); return -1; } return 0; }
void lwan_straitjacket_enforce(config_t *c, config_line_t *l) { char *user_name = NULL; char *chroot_path = NULL; uid_t uid; gid_t gid; if (geteuid() != 0) { config_error(c, "Straitjacket requires root privileges"); return; } while (config_read_line(c, l)) { switch (l->type) { case CONFIG_LINE_TYPE_LINE: /* TODO: limit_syscalls */ if (!strcmp(l->line.key, "user")) { user_name = strdupa(l->line.value); } else if (!strcmp(l->line.key, "chroot")) { chroot_path = strdupa(l->line.value); } else { config_error(c, "Invalid key: %s", l->line.key); return; } break; case CONFIG_LINE_TYPE_SECTION: config_error(c, "Straitjacket accepts no sections"); return; case CONFIG_LINE_TYPE_SECTION_END: if (!get_user_uid_gid(user_name, &uid, &gid)) { config_error(c, "Unknown user: %s", user_name); return; } if (chroot_path) { if (chroot(chroot_path) < 0) { lwan_status_critical_perror("Could not chroot() to %s", chroot_path); } lwan_status_debug("Jailed to %s", chroot_path); } if (!switch_to_user(uid, gid, user_name)) { lwan_status_critical("Could not drop privileges to %s, aborting", user_name); } return; } } config_error(c, "Expecting section end while parsing straitjacket"); }
/** * Format a QString with the MySQL host portion for a remote host. The * resulting string will use the local subnet and mask to generate something * like "192.168.1.0/255.255.255.0" . * * @param host string with the hostname to use for the subnet and mask. * @return QString with formated result. **/ QString format_remote_host(const char *hostname) { struct in_addr local_netmask; struct hostent *temp_hostent; struct in_addr local_ip; struct in_addr local_subnet; temp_hostent=gethostbyname(hostname); local_ip=*(struct in_addr *)temp_hostent->h_addr; // FIXME: ideally do something smarter than just testing eth0 (see above in check_remote_server() also) get_netmask("eth0", &local_netmask); local_subnet.s_addr=(local_ip.s_addr & local_netmask.s_addr); return QString().sprintf("%s/%s", strdupa(inet_ntoa(local_subnet)), strdupa(inet_ntoa(local_netmask)) ); }
int btrfs_volume_create(const char* _target) { char* prefix; char* target; int handle; int result = -1; struct btrfs_ioctl_vol_args detail = {}; prefix = strdupa(_target); if((target = strrchr(prefix, '/'))) { *target++ = '\0'; } else { prefix = "."; } if((handle = open(prefix, O_DIRECTORY|O_RDONLY)) < 0) { fprintf(stderr, "%s: open %s: %m\n", __func__, prefix); return -1; } strncpy(detail.name, target, BTRFS_SUBVOL_NAME_MAX); if(ioctl(handle, BTRFS_IOC_SUBVOL_CREATE, &detail) < 0) { fprintf(stderr, "%s: ioctl BTRFS_IOC_SUBVOL_CREATE: %m\n", __func__); goto done; } result = 0; done: close(handle); return result; }
static int reflink_snapshot(int fd, const char *path) { char *p, *d; int new_fd, r; p = strdupa(path); d = dirname(p); new_fd = open(d, O_TMPFILE|O_CLOEXEC|O_NOCTTY|O_RDWR, 0600); if (new_fd < 0) { _cleanup_free_ char *t = NULL; r = tempfn_random(path, NULL, &t); if (r < 0) return r; new_fd = open(t, O_CLOEXEC|O_CREAT|O_NOCTTY|O_RDWR, 0600); if (new_fd < 0) return -errno; (void) unlink(t); } r = btrfs_reflink(fd, new_fd); if (r < 0) { safe_close(new_fd); return r; } return new_fd; }
static OpusTags * tags_list(DB_playItem_t *it, OggOpusFile *opusfile, int link) { const OpusTags *orig = op_tags (opusfile, link); OpusTags *tags = calloc (1, sizeof (OpusTags)); if (!tags) return NULL; deadbeef->pl_lock (); for (DB_metaInfo_t *m = deadbeef->pl_get_metadata_head (it); m; m = m->next) { if (strchr (":!_", m->key[0])) { break; } char *key = strdupa (m->key); if (!strcasecmp(key, "R128_TRACK_GAIN")) { continue; } split_tag (tags, oggedit_map_tag (key, "meta2tag"), m->value, m->valuesize); } deadbeef->pl_unlock (); // preserve album art int i = 0; const char *tag; while ((tag = opus_tags_query(orig, ALBUM_ART_KEY, i++))) { split_tag (tags, ALBUM_ART_KEY, tag, (int)strlen (tag) + 1); } return tags; }
/* * Given a request URI and the URI we are checking for. * Return: * true for a match and * false for no match. */ static bool match_uri(const char *request_uri, const char *match) { size_t rlen; size_t mlen = strlen(match); const char *request; char *req = strdupa(request_uri); /* * Handle URLs in the form /something/?key=value by stripping * everything from the ? onwards and matching on the initial part. */ if (strchr(request_uri, '?')) request = strtok(req, "?"); else request = request_uri; rlen = strlen(request); /* * The image URLs are a bit different, we only want to match on * the first /.../ part and they don't contain a ?. */ if (strstr(request, "/get_image/") && strstr(match, "/get_image/")) return true; else if (strncmp(request, match, mlen) == 0 && rlen == mlen) return true; else return false; }
static void build_extensions(void) { assert(GL_extensions_dict == NULL); /* create the dict */ GL_extensions_dict = strdict_create(128, STRDICT_FL_DUPKEY); assert(GL_extensions_dict != NULL); const char * __extensions = (const char *)gl(GetString, GL_EXTENSIONS); /* scan the string, identify each ' ' and replace it with '\0', then insert it * into GL_extensions_dict */ assert(__extensions != NULL); char * extensions = strdupa(__extensions); char * p = extensions; char * pp = p; dict_data_t data; data.bol = TRUE; while (*p != '\0') { if (*p == ' ') { *p = '\0'; dict_data_t dt; dt = strdict_insert(GL_extensions_dict, pp, data); assert(DICT_DATA_NULL(dt)); TRACE(OPENGL, "extension %s\n", pp); pp = p + 1; } p++; } }
int s_mkpath(char *dir, mode_t mode) { if (!dir) { return(-1); } if (strlength(dir, 2) == 1 && dir[0] == '/') { return(0); } if ( is_dir(dir) == 0 ) { // Directory already exists, stop... return(0); } if ( s_mkpath(dirname(strdupa(dir)), mode) < 0 ) { // Return if priors failed return(-1); } message(DEBUG, "Creating directory: %s\n", dir); if ( mkdir(dir, mode) < 0 ) { message(ERROR, "Could not create directory %s: %s\n", dir, strerror(errno)); return(-1); } return(0); }
void CDirUtils::create_directory_recursive(const char* dirpath, mode_t permissions) { char* slash; char* pathname = strdupa(dirpath); // _GNU_SOURCE char* pathname_p = pathname; // 过滤掉头部的斜杠 while ('/' == *pathname_p) ++pathname_p; for (;;) { slash = strchr(pathname_p, '/'); if (NULL == slash) // 叶子目录 { if (0 == mkdir(pathname, permissions)) break; if (EEXIST == errno) break; THROW_SYSCALL_EXCEPTION(NULL, errno, "mkdir"); } *slash = '\0'; if ((-1 == mkdir(pathname, permissions)) && (errno != EEXIST)) THROW_SYSCALL_EXCEPTION(NULL, errno, "mkdir"); *slash++ = '/'; while ('/' == *slash) ++slash; // 过滤掉相连的斜杠 pathname_p = slash; } }
/* container state */ static int container_start(lua_State *L) { struct lxc_container *c = lua_unboxpointer(L, 1, CONTAINER_TYPENAME); int argc = lua_gettop(L); char **argv = NULL; int i,j; int useinit = 0; if (argc > 1) { argv = alloca((argc+1) * sizeof(char *)); for (i = 0, j = 0; i < argc-1; i++) { const char *arg = luaL_checkstring(L, i+2); if (!strcmp(arg, "useinit")) useinit = 1; else argv[j++] = strdupa(arg); } argv[j] = NULL; } c->want_daemonize(c, true); lua_pushboolean(L, !!c->start(c, useinit, argv)); return 1; }
static int container_create(lua_State *L) { struct lxc_container *c = lua_unboxpointer(L, 1, CONTAINER_TYPENAME); char *template_name = strdupa(luaL_checkstring(L, 2)); int argc = lua_gettop(L); char **argv; int i; argv = alloca((argc+1) * sizeof(char *)); for (i = 0; i < argc-2; i++) argv[i] = strdupa(luaL_checkstring(L, i+3)); argv[i] = NULL; lua_pushboolean(L, !!c->create(c, template_name, NULL, NULL, 0, argv)); return 1; }
static int slice_verify(Slice *s) { assert(s); if (UNIT(s)->load_state != UNIT_LOADED) return 0; if (UNIT_DEREF(UNIT(s)->slice)) { char *a, *dash; a = strdupa(UNIT(s)->id); dash = strrchr(a, '-'); if (dash) strcpy(dash, ".slice"); else a = (char*) SPECIAL_ROOT_SLICE; if (!unit_has_name(UNIT_DEREF(UNIT(s)->slice), a)) { log_unit_error(UNIT(s)->id, "%s located outside its parent slice. Refusing.", UNIT(s)->id); return -EINVAL; } } return 0; }
int cmd_remove(const char* arg) { char* ptr, *argv; struct ncds_ds_list* ds; struct model_list* model; if (strlen(arg) < 7) { cmd_remove_help(); return 1; } argv = strdupa(arg + strlen("remove ")); ptr = strtok(argv, " "); ds = find_datastore(ptr); if (ds == NULL) { model = find_model(ptr); if (model == NULL) { nc_verb_error("No datastore or model \"%s\" found", ptr); return 1; } else { ncds_ds_model_free(model->model); } } else { ncds_free(ds->datastore); } remove_hint(ptr); return 0; }
static int slice_add_parent_slice(Slice *s) { char *a, *dash; Unit *parent; int r; assert(s); if (UNIT_ISSET(UNIT(s)->slice)) return 0; if (unit_has_name(UNIT(s), SPECIAL_ROOT_SLICE)) return 0; a = strdupa(UNIT(s)->id); dash = strrchr(a, '-'); if (dash) strcpy(dash, ".slice"); else a = (char*) SPECIAL_ROOT_SLICE; r = manager_load_unit(UNIT(s)->manager, a, NULL, NULL, &parent); if (r < 0) return r; unit_ref_set(&UNIT(s)->slice, parent); return 0; }
xlator_t * nfs_mntpath_to_xlator (xlator_list_t *cl, char *path) { char *volname = NULL; char *volptr = NULL; size_t pathlen; xlator_t *targetxl = NULL; if ((!cl) || (!path)) return NULL; volname = strdupa (path); pathlen = strlen (volname); gf_msg_trace (GF_NFS, 0, "Subvolume search: %s", path); if (volname[0] == '/') volptr = &volname[1]; else volptr = &volname[0]; if (pathlen && volname[pathlen - 1] == '/') volname[pathlen - 1] = '\0'; while (cl) { if (strcmp (volptr, cl->xlator->name) == 0) { targetxl = cl->xlator; break; } cl = cl->next; } return targetxl; }
/** * _exp_file_insert -- Insert the exports directory into the file structure * using the directory as a dict. Also hashes the dirname, * stores it in a uuid type, converts the uuid type to a * string and uses that as the key to the exports map. * The exports map maps an export "uuid" to an export * directory struct. * * @file : Exports file struct to insert into * @dir : Export directory to insert * * Not for external use. */ static void _exp_file_insert(struct exports_file *file, struct export_dir *dir) { data_t *dirdata = NULL; uint32_t hashedval = 0; uuid_t export_uuid = { 0, }; char export_uuid_str[512] = { 0, }; char *dirdup = NULL; GF_VALIDATE_OR_GOTO(GF_EXP, file, out); GF_VALIDATE_OR_GOTO(GF_EXP, dir, out); dirdata = bin_to_data(dir, sizeof(*dir)); dict_set(file->exports_dict, dir->dir_name, dirdata); dirdup = strdupa(dir->dir_name); while (strlen(dirdup) > 0 && dirdup[0] == '/') dirdup++; hashedval = SuperFastHash(dirdup, strlen(dirdup)); memset(export_uuid, 0, sizeof(export_uuid)); memcpy(export_uuid, &hashedval, sizeof(hashedval)); gf_uuid_unparse(export_uuid, export_uuid_str); dict_set(file->exports_map, export_uuid_str, dirdata); out: return; }
void ftpService(int sock) { char buf [BUF_SIZE]; char reply [BUF_SIZE]; bool terminate = false; int n, on, i; char *delimiters = " \n\r"; char *temp, *cmd, *arg; // don't wait for system buffer to be full on = 1; if (setsockopt(sock, SOL_SOCKET, SO_OOBINLINE, (char*)&on, sizeof(on)) == -1) { syslog(LOG_FTP | LOG_ERR, "ftpService: setsockopt: %m"); exit(1); } // let the peer know that you are ready snprintf(reply, BUF_SIZE, FTP_R220, "LightFTPServer v0.1"); sendReply(sock, reply); while (!terminate) { // read command memset(buf, 0, BUF_SIZE); // TODO: loop to read all data if ( (n = read(sock, buf, BUF_SIZE)) == -1) { syslog(LOG_FTP | LOG_ERR, "ftpService: read: %m"); exit(1); } // TODO: check if command too large for buffer = not ending in CRLF // parse cmd and arguments temp = strdupa(buf); cmd = strtok(temp, delimiters); arg = strtok(NULL, delimiters); // free(temp); // should ignore blank commands or send a reply? if (cmd != NULL) { // look for handler for (i = 0; i < _FTPCMDS_END; i++) if (strcasecmp(cmd, ftpcmds[i]) == 0) { ftphandlers[i](cmd, arg, (char*)&reply, BUF_SIZE, &terminate); // // say good bye and terminate // if (i == FTP_CQUIT) { // terminate = true; // snprintf(reply, BUF_SIZE, FTP_R221); // } // else // // handle command // snprintf(reply, BUF_SIZE, FTP_R200, cmd); break; } // unknown command if (i == _FTPCMDS_END) snprintf(reply, BUF_SIZE, FTP_R500, cmd); // send back reply sendReply(sock, reply); } } close(sock); }
/** * Return the wanted_field'th field of the feature of the given node. */ static std::string mecab_node_get_field( const MeCab::Node *node, int wanted_field ) { size_t field = 1; char *token = strdupa(node->feature); while (token != NULL) { char *next = NULL; if (*token == '"') { char *closing_quote = strchr(token + 1, '"'); if (closing_quote && closing_quote[1] == ',') { next = closing_quote + 1; token++; // skip opening quote *closing_quote = '\0'; // remove closing quote } } if (!next) next = strchr(token, ','); if (next) { *next = '\0'; next++; } if (field == wanted_field) { return std::string(token); } field++; token = next; } return ""; }
BOOL CDlgFileConv::OnInitDialog() { CDialog::OnInitDialog(); CWnd::DragAcceptFiles(); //所有支持的编码 char *p, *charsets; charsets = strdupa(supported_charsets); while (p = strsep(&charsets, " ")) { ((CComboBox*)GetDlgItem(IDC_CB_SRC_CHARSET))->AddString(stringToCString(p)); ((CComboBox*)GetDlgItem(IDC_CB_DST_CHARSET))->AddString(stringToCString(p)); } //默认选择文件 m_rdSrcFile.SetCheck(TRUE); SwitchSrcType(); m_bRecurDir = TRUE; m_bWriteBOM = TRUE; m_bConverting = FALSE; m_progTotal.SetRange(0, 100); UpdateData(FALSE); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE }
/** * @short Updates allowed commands acording to config file SHELL_WHITELIST and SHELL_BLACKLIST * * First removes all not at whitelist, then all from blacklist. * * A command with empty name (string length 0) is not valid. At end we really remove them. */ void update_allowed_commands(){ if (getenv("SHELL_WHITELIST")){ { // Blacklist all. subcommand_t *I=subcommand_list_begin(), *endI=subcommand_list_end(); for(;I!=endI;++I) I->type|=SC_BLACKLISTED; } // Allow some. char *whitelist=strdupa( getenv("SHELL_WHITELIST") ); char *I=whitelist, *endI=whitelist+strlen(whitelist); while (*whitelist){ while (*whitelist && !isspace(*whitelist)) whitelist++; *whitelist=0; subcommand_t *command=subcommand_find(I); if (command){ fprintf(stderr,"Whitelist %s\n", command->name); command->type&=~SC_BLACKLISTED; // Clear. } if (whitelist>=endI) break; whitelist++; while (isspace(*whitelist)) whitelist++; // Advance to next. I=whitelist; } } if (getenv("SHELL_BLACKLIST")){ char *blacklist=strdupa( getenv("SHELL_BLACKLIST") ); char *I=blacklist, *endI=blacklist+strlen(blacklist); while (*blacklist){ while (*blacklist && !isspace(*blacklist)) blacklist++; *blacklist=0; subcommand_t *command=subcommand_find(I); if (command){ fprintf(stderr,"Blacklist %s\n", command->name); command->type|=SC_BLACKLISTED; } if (blacklist>=endI) break; blacklist++; while (isspace(*blacklist)) blacklist++; // Advance to next. I=blacklist; } } }
struct runner * runner_new(const char *filename) { struct runner *r; const char *buf; size_t size; int err; SOL_NULL_CHECK(filename, NULL); r = calloc(1, sizeof(*r)); SOL_NULL_CHECK(r, NULL); sol_ptr_vector_init(&r->file_readers); r->parser_client.api_version = SOL_FLOW_PARSER_CLIENT_API_VERSION; r->parser_client.data = r; r->parser_client.read_file = read_file; r->parser = sol_flow_parser_new(&r->parser_client, NULL); if (!r->parser) goto error; r->filename = filename; r->dirname = strdup(dirname(strdupa(filename))); r->basename = strdup(basename(strdupa(filename))); err = read_file(r, r->basename, &buf, &size); if (err < 0) { errno = -err; goto error; } r->root_type = sol_flow_parse_buffer(r->parser, buf, size, filename); if (!r->root_type) goto error; close_files(r); return r; error: close_files(r); runner_del(r); return NULL; }
static bool thingspeak_channel_update_send(void *data) { struct thingspeak_channel_update_data *mdata = data; struct sol_http_param params; struct sol_http_client_connection *connection; char field_name[] = "fieldX"; size_t i; int r; sol_http_param_init(¶ms); if (!sol_http_param_add(¶ms, SOL_HTTP_REQUEST_PARAM_POST_FIELD("api_key", mdata->api_key))) { SOL_WRN("Could not add API key"); goto out; } if (mdata->status) { if (!sol_http_param_add(¶ms, SOL_HTTP_REQUEST_PARAM_POST_FIELD("status", mdata->status))) { SOL_WRN("Could not add status field to POST parameters"); goto out; } } for (i = 0; i < ARRAY_SIZE(mdata->fields); i++) { if (!mdata->fields[i]) continue; field_name[sizeof("field") - 1] = i + '1'; if (!sol_http_param_add(¶ms, SOL_HTTP_REQUEST_PARAM_POST_FIELD(strdupa(field_name), mdata->fields[i]))) { SOL_WRN("Could not add status field to POST %s parameters", field_name); goto out; } } connection = sol_http_client_request(SOL_HTTP_METHOD_POST, mdata->endpoint, ¶ms, thingspeak_channel_update_finished, mdata); if (!connection) { SOL_WRN("Could not create HTTP request"); goto out; } r = sol_ptr_vector_append(&mdata->pending_conns, connection); if (r < 0) { SOL_WRN("Failed to keep pending connection."); sol_http_client_connection_cancel(connection); } out: sol_http_param_free(¶ms); mdata->timeout = NULL; return false; }
static bool rule_satisfiable(multiset_table *cmt, pp_linkset *ls) { unsigned int hashval; const char * t; char *name, *s; pp_linkset_node *p; int bad, n_subscripts; for (hashval = 0; hashval < ls->hash_table_size; hashval++) { for (p = ls->hash_table[hashval]; p!=NULL; p=p->next) { /* ok, we've got our hands on one of the criterion links */ name = strdupa(p->str); /* could actually use the string in place because we change it back */ /* now we want to see if we can satisfy this criterion link */ /* with a collection of the links in the cms table */ s = name; if (islower((int)*s)) s++; /* skip head-dependent indicator */ for (; isupper((int)*s); s++) {} for (;*s != '\0'; s++) if (*s != '*') *s = '#'; s = name; t = p->str; if (islower((int)*s)) s++; /* skip head-dependent indicator */ if (islower((int)*t)) t++; /* skip head-dependent indicator */ for (; isupper((int) *s); s++, t++) {} /* s and t remain in lockstep */ bad = 0; n_subscripts = 0; for (;*s != '\0' && bad==0; s++, t++) { if (*s == '*') continue; n_subscripts++; /* after the upper case part, and is not a * so must be a regular subscript */ *s = *t; if (!match_in_cms_table(cmt, name)) bad++; *s = '#'; } if (n_subscripts == 0) { /* now we handle the special case which occurs if there were 0 subscripts */ if (!match_in_cms_table(cmt, name)) bad++; } /* now if bad==0 this criterion link does the job to satisfy the needs of the trigger link */ if (bad == 0) return true; } } return false; }
static gboolean write_checksum_file_at (OstreeRepo *self, int dfd, const char *name, const char *sha256, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; const char *lastslash; if (!ostree_validate_checksum_string (sha256, error)) goto out; if (ostree_validate_checksum_string (name, NULL)) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Rev name '%s' looks like a checksum", name); goto out; } if (!*name) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Invalid empty ref name"); goto out; } lastslash = strrchr (name, '/'); if (lastslash) { char *parent = strdupa (name); parent[lastslash - name] = '\0'; if (!glnx_shutil_mkdir_p_at (dfd, parent, 0777, cancellable, error)) goto out; } { size_t l = strlen (sha256); char *bufnl = alloca (l + 2); memcpy (bufnl, sha256, l); bufnl[l] = '\n'; bufnl[l+1] = '\0'; if (!_ostree_repo_file_replace_contents (self, dfd, name, (guint8*)bufnl, l + 1, cancellable, error)) goto out; } ret = TRUE; out: return ret; }
bool NXfnammchk(const char* fn, const char* nam) { if(!nam || nam[0] == '\0') return false; char* fna = _strlwr(strdupa(fn)); char* nama = _strlwr(strdupa(nam)); size_t l = strlen(fn); char* e = nama; for(;;) { char* ne = strchr(e, '|'); if(ne) ne[0] = '\0'; if(strstr(fna, e)) return true; if(!ne) break; e = ne+1; } return false; }