/* ARGSUSED */ size_t r_regex_error(int errcode, const RRegex *preg, char *errbuf, size_t errbuf_size) { struct rerr *r; size_t len; int target = errcode &~ R_REGEX_ITOA; char *s; char convbuf[50]; if (errcode == R_REGEX_ATOI) s = regatoi(preg, convbuf, sizeof convbuf); else { for (r = rerrs; r->code != 0; r++) if (r->code == target) break; if (errcode&R_REGEX_ITOA) { if (r->code != 0) { (void) STRLCPY(convbuf, r->name, sizeof (convbuf)-1); } else (void)snprintf(convbuf, sizeof convbuf, "R_REGEX_0x%x", target); s = convbuf; } else s = r->explain; } len = strlen(s) + 1; if (errbuf_size > 0) STRLCPY(errbuf, s, errbuf_size); return(len); }
/* * For an xtended filemark: set the fnum from the fname. * This is used for marks obtained from the .shada file. It's postponed * until the mark is used to avoid a long startup delay. */ static void fname2fnum(xfmark_T *fm) { char_u *p; if (fm->fname != NULL) { /* * First expand "~/" in the file name to the home directory. * Don't expand the whole name, it may contain other '~' chars. */ if (fm->fname[0] == '~' && (fm->fname[1] == '/' #ifdef BACKSLASH_IN_FILENAME || fm->fname[1] == '\\' #endif )) { int len; expand_env((char_u *)"~/", NameBuff, MAXPATHL); len = (int)STRLEN(NameBuff); STRLCPY(NameBuff + len, fm->fname + 2, MAXPATHL - len); } else STRLCPY(NameBuff, fm->fname, MAXPATHL); /* Try to shorten the file name. */ os_dirname(IObuff, IOSIZE); p = path_shorten_fname(NameBuff, IObuff); /* buflist_new() will call fmarks_check_names() */ (void)buflist_new(NameBuff, p, (linenr_T)1, 0); } }
static int serverid_txt_record(dns_cache_rrset_t *rrset, dns_msg_question_t *q, char *txt_string, dns_tls_t *tls) { int len; dns_msg_resource_t res; STRLCPY(res.mr_q.mq_name, q->mq_name, sizeof(res.mr_q.mq_name)); res.mr_q.mq_class = DNS_CLASS_CH; res.mr_q.mq_type = DNS_TYPE_TXT; res.mr_ttl = 0; if ((len = strlen(txt_string)) >= DNS_RDATA_MAX) return -1; res.mr_datalen = len + 1; res.mr_data[0] = len; STRLCPY((char *) &res.mr_data[1], txt_string, sizeof(res.mr_data) - 1); if (dns_cache_add_answer(rrset, q, &res, tls) < 0) { plog(LOG_ERR, "%s: can't add cache resource", MODULE); return -1; } return 0; }
/* * Function given to ExpandGeneric() to obtain the list of menus and menu * entries. */ char_u *get_menu_names(expand_T *xp, int idx) { static vimmenu_T *menu = NULL; #define TBUFFER_LEN 256 static char_u tbuffer[TBUFFER_LEN]; /*hack*/ char_u *str; static int should_advance = FALSE; if (idx == 0) { /* first call: start at first item */ menu = expand_menu; should_advance = FALSE; } /* Skip Browse-style entries, popup menus and separators. */ while (menu != NULL && ( menu_is_hidden(menu->dname) || (expand_emenu && menu_is_separator(menu->dname)) || menu_is_tearoff(menu->dname) || menu->dname[STRLEN(menu->dname) - 1] == '.' )) menu = menu->next; if (menu == NULL) /* at end of linked list */ return NULL; if (menu->modes & expand_modes) { if (menu->children != NULL) { if (should_advance) STRLCPY(tbuffer, menu->en_dname, TBUFFER_LEN - 1); else { STRLCPY(tbuffer, menu->dname, TBUFFER_LEN - 1); if (menu->en_dname == NULL) should_advance = TRUE; } /* hack on menu separators: use a 'magic' char for the separator * so that '.' in names gets escaped properly */ STRCAT(tbuffer, "\001"); str = tbuffer; } else { if (should_advance) str = menu->en_dname; else { str = menu->dname; if (menu->en_dname == NULL) should_advance = TRUE; } } } else str = (char_u *)""; if (should_advance) /* Advance to next menu entry. */ menu = menu->next; should_advance = !should_advance; return str; }
INLINE BOOL Cartridge::Prepare(eCartridgeSize size) { iType = size; iSize = this->GetCardType(size); const char *p = pFileSystem->GetWriteableDirectory(); ASSERT_MSG(p!=NULL, "You must set a WriteableDirectory!"); MEMSET(strPath, '\0', PC_MAX_PATH); STRLCPY(strPath, p, PC_MAX_PATH); STRLCAT(strPath, "/", PC_MAX_PATH - 1); STRLCAT(strPath, CARTRIDGE_FILENAME, PC_MAX_PATH - strlen(strPath) - 1); this->pData = static_cast<u8 *>(pMemoryManager->Alloc(iSize)); memset(this->pData, 0, iSize); if (!this->Verify(strPath, iSize)) { if (!this->CreateSaveFile()) { Log(TAG "ERROR: trying to create save file!"); return FALSE; } } return TRUE; }
static char * type_str(char *buf0, int buf_len, const DNSBL_WORK *dlw, DNSBL_HIT hit) { const char *type; char sustr[DCC_SU2STR_SIZE]; char *buf; int i; buf = buf0; if (hit & DNSBL_HIT_WHITE) { hit &= ~DNSBL_HIT_WHITE; i = STRLCPY(buf, "whitelist ", buf_len); if (i > buf_len) i = buf_len; buf_len -= i; buf += i; } switch (hit) { case DNSBL_HIT_CLIENT: type = "SMTP client"; if (dlw->tgt.dom.c[0] == '\0') { snprintf(buf, buf_len, "%s %s", type, dcc_ipv6tostr2(sustr, sizeof(sustr), &dlw->tgt.addr)); return buf0; } break; case DNSBL_HIT_MHOST: type = "mail_host"; break; case DNSBL_HIT_MHOST_MX : type = "mail_host MX"; break; case DNSBL_HIT_MHOST_NS: type = "mail_host NS"; break; case DNSBL_HIT_URL: type = "URL"; break; case DNSBL_HIT_URL_MX: type = "URL MX"; break; case DNSBL_HIT_URL_NS: type = "URL NS"; break; default: dcc_logbad(EX_SOFTWARE, "impossible DNSBL hit type %#x", hit); break; } i = snprintf(buf, buf_len, "%s %s", type, dlw->tgt.dom.c); if (i >= buf_len && buf_len > 4) strcpy(&buf[buf_len-4], "..."); return buf0; }
/* * maintains the list of already visited files and dirs * returns FAIL if the given file/dir is already in the list * returns OK if it is newly added */ static int ff_check_visited(ff_visited_T **visited_list, char_u *fname, char_u *wc_path) { ff_visited_T *vp; bool url = false; FileInfo file_info; // For a URL we only compare the name, otherwise we compare the // device/inode. if (path_with_url(fname)) { STRLCPY(ff_expand_buffer, fname, MAXPATHL); url = true; } else { ff_expand_buffer[0] = NUL; if (!os_get_file_info((char *)fname, &file_info)) { return FAIL; } } /* check against list of already visited files */ for (vp = *visited_list; vp != NULL; vp = vp->ffv_next) { if ((url && fnamecmp(vp->ffv_fname, ff_expand_buffer) == 0) || (!url && vp->ffv_dev_valid && vp->ffv_dev == file_info.stat.st_dev && vp->ffv_ino == file_info.stat.st_ino)) { /* are the wildcard parts equal */ if (ff_wc_equal(vp->ffv_wc_path, wc_path) == TRUE) /* already visited */ return FAIL; } } /* * New file/dir. Add it to the list of visited files/dirs. */ vp = xmalloc(sizeof(ff_visited_T) + STRLEN(ff_expand_buffer)); if (!url) { vp->ffv_dev_valid = TRUE; vp->ffv_ino = file_info.stat.st_ino; vp->ffv_dev = file_info.stat.st_dev; vp->ffv_fname[0] = NUL; } else { vp->ffv_dev_valid = FALSE; STRCPY(vp->ffv_fname, ff_expand_buffer); } if (wc_path != NULL) vp->ffv_wc_path = vim_strsave(wc_path); else vp->ffv_wc_path = NULL; vp->ffv_next = *visited_list; *visited_list = vp; return OK; }
/* * maintains the list of already visited files and dirs * returns FAIL if the given file/dir is already in the list * returns OK if it is newly added */ static int ff_check_visited(ff_visited_T **visited_list, char_u *fname, char_u *wc_path) { ff_visited_T *vp; bool url = false; FileID file_id; // For an URL we only compare the name, otherwise we compare the // device/inode. if (path_with_url((char *)fname)) { STRLCPY(ff_expand_buffer, fname, MAXPATHL); url = true; } else { ff_expand_buffer[0] = NUL; if (!os_fileid((char *)fname, &file_id)) { return FAIL; } } /* check against list of already visited files */ for (vp = *visited_list; vp != NULL; vp = vp->ffv_next) { if ((url && fnamecmp(vp->ffv_fname, ff_expand_buffer) == 0) || (!url && vp->file_id_valid && os_fileid_equal(&(vp->file_id), &file_id))) { // are the wildcard parts equal if (ff_wc_equal(vp->ffv_wc_path, wc_path)) { // already visited return FAIL; } } } /* * New file/dir. Add it to the list of visited files/dirs. */ vp = xmalloc(sizeof(ff_visited_T) + STRLEN(ff_expand_buffer)); if (!url) { vp->file_id_valid = true; vp->file_id = file_id; vp->ffv_fname[0] = NUL; } else { vp->file_id_valid = false; STRCPY(vp->ffv_fname, ff_expand_buffer); } if (wc_path != NULL) vp->ffv_wc_path = vim_strsave(wc_path); else vp->ffv_wc_path = NULL; vp->ffv_next = *visited_list; *visited_list = vp; return OK; }
/// Get the name of current directory. /// /// @param buf Buffer to store the directory name. /// @param len Length of `buf`. /// @return `OK` for success, `FAIL` for failure. int os_dirname(char_u *buf, size_t len) { assert(buf && len); int error_number; if ((error_number = uv_cwd((char *)buf, &len)) != kLibuvSuccess) { STRLCPY(buf, uv_strerror(error_number), len); return FAIL; } return OK; }
char * thold2str(char *buf, u_int buf_len, DCC_CK_TYPES type, DCC_TGTS tgts) { if (tgts == THOLD_NEVER) { STRLCPY(buf, DCC_XHDR_THOLD_NEVER, buf_len); return buf; } if (type == DCC_CK_REP_BULK) { snprintf(buf, buf_len, "%u%%", tgts); return buf; } return tgts2str(buf, buf_len, tgts, 0); }
/// Checks if a file is inside the `$PATH` and is executable. /// /// @param[in] name The name of the executable. /// @param[out] abspath Path of the executable, if found and not `NULL`. /// /// @return `true` if `name` is an executable inside `$PATH`. static bool is_executable_in_path(const char_u *name, char_u **abspath) { const char *path = getenv("PATH"); // PATH environment variable does not exist or is empty. if (path == NULL || *path == NUL) { return false; } size_t buf_len = STRLEN(name) + STRLEN(path) + 2; char_u *buf = xmalloc(buf_len); // Walk through all entries in $PATH to check if "name" exists there and // is an executable file. for (;; ) { const char *e = strchr(path, ':'); if (e == NULL) { e = path + STRLEN(path); } // Glue together the given directory from $PATH with name and save into // buf. STRLCPY(buf, path, e - path + 1); append_path((char *) buf, (const char *) name, (int)buf_len); if (is_executable(buf)) { // Check if the caller asked for a copy of the path. if (abspath != NULL) { *abspath = save_absolute_path(buf); } free(buf); return true; } if (*e != ':') { // End of $PATH without finding any executable called name. free(buf); return false; } path = e + 1; } // We should never get to this point. assert(false); return false; }
/* - mcadd - add a collating element to a cset */ static void mcadd( struct parse *p, cset *cs, char *cp) { size_t oldend = cs->smultis; void *np; cs->smultis += strlen(cp) + 1; np = realloc(cs->multis, cs->smultis); if (np == NULL) { if (cs->multis) free(cs->multis); cs->multis = NULL; SETERROR(R_REGEX_ESPACE); return; } cs->multis = np; STRLCPY(cs->multis + oldend - 1, cp, cs->smultis - oldend + 1); }
int dns_util_sa2str(char *buf, int bufmax, struct sockaddr *sa) { int port; char host[256]; if (dns_util_sa2str_wop(host, sizeof(host), sa) < 0) return -1; if ((port = dns_util_sagetport(sa)) == 0) STRLCPY(buf, host, bufmax); else { if (sa->sa_family == AF_INET) snprintf(buf, bufmax, "%s:%d", host, port); if (sa->sa_family == AF_INET6) snprintf(buf, bufmax, "[%s]:%d", host, port); } return 0; }
static int notify_make_message(char *buf, int bufmax, char *zone_name) { int len; uint16_t msgid, flags; dns_msg_handle_t handle; dns_msg_question_t q; arc4_ctx_t tmp_ctx; memset(&tmp_ctx, 0, sizeof(tmp_ctx)); msgid = xarc4random(&tmp_ctx); flags = DNS_OP2FLAG(DNS_OP_NOTIFY) | DNS_FLAG_AA; if (dns_msg_write_open(&handle, buf, bufmax) < 0) { plog(LOG_ERR, "%s: dns_msg_write_open() failed", __func__); return -1; } if (dns_msg_write_header(&handle, msgid, flags) < 0) { plog(LOG_ERR, "%s: dns_msg_write_header() failed", __func__); dns_msg_write_close(&handle); return -1; } STRLCPY(q.mq_name, zone_name, sizeof(q.mq_name)); q.mq_type = DNS_TYPE_SOA; q.mq_class = DNS_CLASS_IN; if (dns_msg_write_question(&handle, &q) < 0) { plog(LOG_ERR, "%s: dns_msg_write_question() failed", __func__); dns_msg_write_close(&handle); return -1; } if ((len = dns_msg_write_close(&handle)) < 0) { plog(LOG_ERR, "%s: dns_msg_write_close() failed", __func__); return -1; } return len; }
es_Status es_rcontrol_run_tcl(es_TCPMessage *msg, es_TCPStream *responseStream) { static es_Interp *interp = NULL; if( interp == NULL ) { interp = es_get_interp(); } char *path = malloc(msg->len+1); STRLCPY(path,msg->data,msg->len+1); char buf[500]; snprintf(buf,500,"source {%s}",path); es_Status rc = es_eval_tcl(interp,buf); if( rc != ES_OK ) { const char *errmsg = es_tcl_last_result(interp); es_rcontrol_send_error(responseStream,errmsg); return ES_TCL_ERROR; } else { es_rcontrol_send_ok(responseStream,TCPMSG_ES_RUNTCL); return ES_OK; } }
bool CContactInfo::SetValue(char **pszValue, char *pszXml, char *pszTag) { FREEIF(*pszValue); char pszT[20]; SPRINTF(pszT, "<%s>", pszTag); char *pszFound=NULL; char *pszNext = pszXml; if ( NULL != (pszFound=STRSTR(pszNext, pszT))) { //<ct><id>3</id></ct> SPRINTF(pszT, "</%s>", pszTag); char *pszEndTag=NULL; pszEndTag=STRSTR(pszFound, pszT); if ( NULL==pszEndTag ) return false; int nLen=0; SPRINTF(pszT, "<%s>", pszTag); int nTagLen = STRLEN(pszT); nLen = STRLEN(pszFound)-STRLEN(pszEndTag)-nTagLen; // len of <id>3 if ( nLen>0 ) { *pszValue = (char*)MALLOC((nLen+1)*sizeof(AECHAR)); if (NULL==(*pszValue)) return false; STRLCPY(*pszValue, pszFound+nTagLen, nLen+1); DBGPRINTF(*pszValue); } } return true; }
static void dn_pas_config_chassis(std_config_node_t nd) { char *a; if ((a = std_config_attr_get(nd, "vendor-name")) != 0) { STRLCPY(chassis_cfg->vendor_name, a); } if ((a = std_config_attr_get(nd, "product-name")) != 0) { STRLCPY(chassis_cfg->prod_name, a); } if ((a = std_config_attr_get(nd, "hw-version")) != 0) { STRLCPY(chassis_cfg->hw_revision, a); } if ((a = std_config_attr_get(nd, "platform-name")) != 0) { STRLCPY(chassis_cfg->platform_name, a); } if ((a = std_config_attr_get(nd, "ppid")) != 0) { STRLCPY(chassis_cfg->ppid, a); } if ((a = std_config_attr_get(nd, "service-tag")) != 0) { STRLCPY(chassis_cfg->service_tag, a); } if ((a = std_config_attr_get(nd, "base-mac-addresses")) != 0 && sscanf(a, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &chassis_cfg->base_mac[0], &chassis_cfg->base_mac[1], &chassis_cfg->base_mac[2], &chassis_cfg->base_mac[3], &chassis_cfg->base_mac[4], &chassis_cfg->base_mac[5] ) != 6 ) { memset(chassis_cfg->base_mac, 0, sizeof(chassis_cfg->base_mac)); } if ((a = std_config_attr_get(nd, "num-mac-addresses")) != 0 && sscanf(a, "%u", &chassis_cfg->mac_size) != 1 ) { chassis_cfg->mac_size = 0; } }
void dn_cache_init_led( sdi_resource_hdl_t sdi_resource_hdl, void *data ) { pas_entity_t *parent = (pas_entity_t *) data; const char *led_name; char ckey[PAS_CPS_KEY_STR_LEN]; cps_api_key_t cps_key[1]; pas_led_t *rec; ++parent->num_leds; rec = CALLOC_T(pas_led_t, 1); if (rec == 0) return; led_name = sdi_resource_alias_get(sdi_resource_hdl); rec->parent = parent; rec->led_idx = parent->num_leds; STRLCPY(rec->name, led_name); rec->name_len = strlen(rec->name); rec->sdi_resource_hdl = sdi_resource_hdl; dn_pas_oper_fault_state_init(rec->oper_fault_state); dn_led_res_key_name(ckey, sizeof(ckey), parent->entity_type, parent->slot, rec->name, rec->name_len ); if (!dn_pas_res_insertc(ckey, rec)) { free(rec); return; } cps_api_key_init(cps_key, cps_api_qualifier_OBSERVED, cps_api_obj_CAT_BASE_PAS, BASE_PAS_LED_OBJ, 3, parent->entity_type, parent->slot, rec->led_idx ); if (!dn_pas_res_insert(cps_key, rec)) { dn_pas_res_removec(ckey); free(rec); return; } /* Set LED to default */ struct pas_config_led *cfg = dn_pas_config_led_get(parent->entity_type, rec->name); (*(cfg != 0 && cfg->deflt ? sdi_led_on : sdi_led_off))(sdi_resource_hdl); }
static void do_intro_line(int row, char_u *mesg, int add_version, int attr) { char_u vers[20]; int col; char_u *p; int l; int clen; #ifdef MODIFIED_BY # define MODBY_LEN 150 char_u modby[MODBY_LEN]; if (*mesg == ' ') { l = STRLCPY(modby, _("Modified by "), MODBY_LEN); if (l < MODBY_LEN - 1) { STRLCPY(modby + l, MODIFIED_BY, MODBY_LEN - l); } mesg = modby; } #endif // ifdef MODIFIED_BY // Center the message horizontally. col = vim_strsize(mesg); if (add_version) { STRCPY(vers, mediumVersion); if (highest_patch()) { // Check for 9.9x or 9.9xx, alpha/beta version if (isalpha((int)vers[3])) { int len = (isalpha((int)vers[4])) ? 5 : 4; sprintf((char *)vers + len, ".%d%s", highest_patch(), mediumVersion + len); } else { sprintf((char *)vers + 3, ".%d", highest_patch()); } } col += (int)STRLEN(vers); } col = (Columns - col) / 2; if (col < 0) { col = 0; } // Split up in parts to highlight <> items differently. for (p = mesg; *p != NUL; p += l) { clen = 0; for (l = 0; p[l] != NUL && (l == 0 || (p[l] != '<' && p[l - 1] != '>')); ++l) { if (has_mbyte) { clen += ptr2cells(p + l); l += (*mb_ptr2len)(p + l) - 1; } else { clen += byte2cells(p[l]); } } screen_puts_len(p, l, row, col, *p == '<' ? hl_attr(HLF_8) : attr); col += clen; } // Add the version number to the version line. if (add_version) { screen_puts(vers, row, col, 0); } }
/* * Initialization routine for vim_findfile(). * * Returns the newly allocated search context or NULL if an error occurred. * * Don't forget to clean up by calling vim_findfile_cleanup() if you are done * with the search context. * * Find the file 'filename' in the directory 'path'. * The parameter 'path' may contain wildcards. If so only search 'level' * directories deep. The parameter 'level' is the absolute maximum and is * not related to restricts given to the '**' wildcard. If 'level' is 100 * and you use '**200' vim_findfile() will stop after 100 levels. * * 'filename' cannot contain wildcards! It is used as-is, no backslashes to * escape special characters. * * If 'stopdirs' is not NULL and nothing is found downward, the search is * restarted on the next higher directory level. This is repeated until the * start-directory of a search is contained in 'stopdirs'. 'stopdirs' has the * format ";*<dirname>*\(;<dirname>\)*;\=$". * * If the 'path' is relative, the starting dir for the search is either VIM's * current dir or if the path starts with "./" the current files dir. * If the 'path' is absolute, the starting dir is that part of the path before * the first wildcard. * * Upward search is only done on the starting dir. * * If 'free_visited' is TRUE the list of already visited files/directories is * cleared. Set this to FALSE if you just want to search from another * directory, but want to be sure that no directory from a previous search is * searched again. This is useful if you search for a file at different places. * The list of visited files/dirs can also be cleared with the function * vim_findfile_free_visited(). * * Set the parameter 'find_what' to FINDFILE_DIR if you want to search for * directories only, FINDFILE_FILE for files only, FINDFILE_BOTH for both. * * A search context returned by a previous call to vim_findfile_init() can be * passed in the parameter "search_ctx_arg". This context is reused and * reinitialized with the new parameters. The list of already visited * directories from this context is only deleted if the parameter * "free_visited" is true. Be aware that the passed "search_ctx_arg" is freed * if the reinitialization fails. * * If you don't have a search context from a previous call "search_ctx_arg" * must be NULL. * * This function silently ignores a few errors, vim_findfile() will have * limited functionality then. */ void * vim_findfile_init ( char_u *path, char_u *filename, char_u *stopdirs, int level, int free_visited, int find_what, void *search_ctx_arg, int tagfile, /* expanding names of tags files */ char_u *rel_fname /* file name to use for "." */ ) { char_u *wc_part; ff_stack_T *sptr; ff_search_ctx_T *search_ctx; /* If a search context is given by the caller, reuse it, else allocate a * new one. */ if (search_ctx_arg != NULL) search_ctx = search_ctx_arg; else { search_ctx = xcalloc(1, sizeof(ff_search_ctx_T)); } search_ctx->ffsc_find_what = find_what; search_ctx->ffsc_tagfile = tagfile; /* clear the search context, but NOT the visited lists */ ff_clear(search_ctx); /* clear visited list if wanted */ if (free_visited == TRUE) vim_findfile_free_visited(search_ctx); else { /* Reuse old visited lists. Get the visited list for the given * filename. If no list for the current filename exists, creates a new * one. */ search_ctx->ffsc_visited_list = ff_get_visited_list(filename, &search_ctx->ffsc_visited_lists_list); if (search_ctx->ffsc_visited_list == NULL) goto error_return; search_ctx->ffsc_dir_visited_list = ff_get_visited_list(filename, &search_ctx->ffsc_dir_visited_lists_list); if (search_ctx->ffsc_dir_visited_list == NULL) goto error_return; } if (ff_expand_buffer == NULL) { ff_expand_buffer = xmalloc(MAXPATHL); } /* Store information on starting dir now if path is relative. * If path is absolute, we do that later. */ if (path[0] == '.' && (vim_ispathsep(path[1]) || path[1] == NUL) && (!tagfile || vim_strchr(p_cpo, CPO_DOTTAG) == NULL) && rel_fname != NULL) { int len = (int)(path_tail(rel_fname) - rel_fname); if (!vim_isAbsName(rel_fname) && len + 1 < MAXPATHL) { /* Make the start dir an absolute path name. */ STRLCPY(ff_expand_buffer, rel_fname, len + 1); search_ctx->ffsc_start_dir = FullName_save(ff_expand_buffer, FALSE); } else search_ctx->ffsc_start_dir = vim_strnsave(rel_fname, len); if (*++path != NUL) ++path; } else if (*path == NUL || !vim_isAbsName(path)) { #ifdef BACKSLASH_IN_FILENAME /* "c:dir" needs "c:" to be expanded, otherwise use current dir */ if (*path != NUL && path[1] == ':') { char_u drive[3]; drive[0] = path[0]; drive[1] = ':'; drive[2] = NUL; if (vim_FullName(drive, ff_expand_buffer, MAXPATHL, TRUE) == FAIL) goto error_return; path += 2; } else #endif if (os_dirname(ff_expand_buffer, MAXPATHL) == FAIL) goto error_return; search_ctx->ffsc_start_dir = vim_strsave(ff_expand_buffer); #ifdef BACKSLASH_IN_FILENAME /* A path that starts with "/dir" is relative to the drive, not to the * directory (but not for "//machine/dir"). Only use the drive name. */ if ((*path == '/' || *path == '\\') && path[1] != path[0] && search_ctx->ffsc_start_dir[1] == ':') search_ctx->ffsc_start_dir[2] = NUL; #endif } /* * If stopdirs are given, split them into an array of pointers. * If this fails (mem allocation), there is no upward search at all or a * stop directory is not recognized -> continue silently. * If stopdirs just contains a ";" or is empty, * search_ctx->ffsc_stopdirs_v will only contain a NULL pointer. This * is handled as unlimited upward search. See function * ff_path_in_stoplist() for details. */ if (stopdirs != NULL) { char_u *walker = stopdirs; int dircount; while (*walker == ';') walker++; dircount = 1; search_ctx->ffsc_stopdirs_v = xmalloc(sizeof(char_u *)); do { char_u *helper; void *ptr; helper = walker; ptr = xrealloc(search_ctx->ffsc_stopdirs_v, (dircount + 1) * sizeof(char_u *)); search_ctx->ffsc_stopdirs_v = ptr; walker = vim_strchr(walker, ';'); if (walker) { search_ctx->ffsc_stopdirs_v[dircount-1] = vim_strnsave(helper, (int)(walker - helper)); walker++; } else /* this might be "", which means ascent till top * of directory tree. */ search_ctx->ffsc_stopdirs_v[dircount-1] = vim_strsave(helper); dircount++; } while (walker != NULL); search_ctx->ffsc_stopdirs_v[dircount-1] = NULL; } search_ctx->ffsc_level = level; /* split into: * -fix path * -wildcard_stuff (might be NULL) */ wc_part = vim_strchr(path, '*'); if (wc_part != NULL) { int llevel; int len; char *errpt; /* save the fix part of the path */ search_ctx->ffsc_fix_path = vim_strnsave(path, (int)(wc_part - path)); /* * copy wc_path and add restricts to the '**' wildcard. * The octet after a '**' is used as a (binary) counter. * So '**3' is transposed to '**^C' ('^C' is ASCII value 3) * or '**76' is transposed to '**N'( 'N' is ASCII value 76). * For EBCDIC you get different character values. * If no restrict is given after '**' the default is used. * Due to this technique the path looks awful if you print it as a * string. */ len = 0; while (*wc_part != NUL) { if (len + 5 >= MAXPATHL) { EMSG(_(e_pathtoolong)); break; } if (STRNCMP(wc_part, "**", 2) == 0) { ff_expand_buffer[len++] = *wc_part++; ff_expand_buffer[len++] = *wc_part++; llevel = strtol((char *)wc_part, &errpt, 10); if ((char_u *)errpt != wc_part && llevel > 0 && llevel < 255) ff_expand_buffer[len++] = llevel; else if ((char_u *)errpt != wc_part && llevel == 0) /* restrict is 0 -> remove already added '**' */ len -= 2; else ff_expand_buffer[len++] = FF_MAX_STAR_STAR_EXPAND; wc_part = (char_u *)errpt; if (*wc_part != NUL && !vim_ispathsep(*wc_part)) { EMSG2(_( "E343: Invalid path: '**[number]' must be at the end of the path or be followed by '%s'."), PATHSEPSTR); goto error_return; } } else ff_expand_buffer[len++] = *wc_part++; } ff_expand_buffer[len] = NUL; search_ctx->ffsc_wc_path = vim_strsave(ff_expand_buffer); } else search_ctx->ffsc_fix_path = vim_strsave(path); if (search_ctx->ffsc_start_dir == NULL) { /* store the fix part as startdir. * This is needed if the parameter path is fully qualified. */ search_ctx->ffsc_start_dir = vim_strsave(search_ctx->ffsc_fix_path); search_ctx->ffsc_fix_path[0] = NUL; } /* create an absolute path */ if (STRLEN(search_ctx->ffsc_start_dir) + STRLEN(search_ctx->ffsc_fix_path) + 3 >= MAXPATHL) { EMSG(_(e_pathtoolong)); goto error_return; } STRCPY(ff_expand_buffer, search_ctx->ffsc_start_dir); add_pathsep(ff_expand_buffer); { size_t eb_len = STRLEN(ff_expand_buffer); char_u *buf = xmalloc(eb_len + STRLEN(search_ctx->ffsc_fix_path) + 1); STRCPY(buf, ff_expand_buffer); STRCPY(buf + eb_len, search_ctx->ffsc_fix_path); if (os_isdir(buf)) { STRCAT(ff_expand_buffer, search_ctx->ffsc_fix_path); add_pathsep(ff_expand_buffer); } else { char_u *p = path_tail(search_ctx->ffsc_fix_path); char_u *wc_path = NULL; char_u *temp = NULL; int len = 0; if (p > search_ctx->ffsc_fix_path) { len = (int)(p - search_ctx->ffsc_fix_path) - 1; STRNCAT(ff_expand_buffer, search_ctx->ffsc_fix_path, len); add_pathsep(ff_expand_buffer); } else len = (int)STRLEN(search_ctx->ffsc_fix_path); if (search_ctx->ffsc_wc_path != NULL) { wc_path = vim_strsave(search_ctx->ffsc_wc_path); temp = xmalloc(STRLEN(search_ctx->ffsc_wc_path) + STRLEN(search_ctx->ffsc_fix_path + len) + 1); } if (temp == NULL || wc_path == NULL) { free(buf); free(temp); free(wc_path); goto error_return; } STRCPY(temp, search_ctx->ffsc_fix_path + len); STRCAT(temp, search_ctx->ffsc_wc_path); free(search_ctx->ffsc_wc_path); free(wc_path); search_ctx->ffsc_wc_path = temp; } free(buf); } sptr = ff_create_stack_element(ff_expand_buffer, search_ctx->ffsc_wc_path, level, 0); ff_push(search_ctx, sptr); search_ctx->ffsc_file_to_search = vim_strsave(filename); return search_ctx; error_return: /* * We clear the search context now! * Even when the caller gave us a (perhaps valid) context we free it here, * as we might have already destroyed it. */ vim_findfile_cleanup(search_ctx); return NULL; }
size_t pmm_mapinfo(PROCESS *prp, uintptr_t vaddr, struct _procfs_map_info *mip, struct _procfs_debug_info *mdp, size_t dbginfo_pathlen, OBJECT **obpp, int *fdp, size_t *contigp) { struct mem_phys_entry *mem, *closest, text_tmp, data_tmp; uintptr_t addr; if(obpp != NULL) *obpp = NULL; closest = 0; addr = 0; for(mem = (struct mem_phys_entry *)prp->memory; mem; mem = mem->next) { if(pmm_check(vaddr, mem, (unsigned)(mem + 1), &closest, &addr)) { break; } } if(!mem && (!closest || (!(closest->flags & MAP_ELF) && closest->reloc == 0))) { text_tmp.flags = MAP_ELF | MAP_PRIVATE; text_tmp.reloc = prp->kdebug.text_reloc; text_tmp.size = prp->kdebug.text_size; if(text_tmp.size && pmm_check(vaddr, &text_tmp, prp->kdebug.text_addr, &closest, &addr)) { mem = &text_tmp; } else { data_tmp.flags = MAP_ELF | MAP_PRIVATE; data_tmp.reloc = prp->kdebug.data_reloc; data_tmp.size = prp->kdebug.data_size; if(data_tmp.size && pmm_check(vaddr, &data_tmp, prp->kdebug.data_addr, &closest, &addr)) { mem = &data_tmp; } } } if(mem || (mip && (mem = closest))) { if(mip) { mip->vaddr = addr; vaddr = addr; mip->flags = mem->flags; mip->size = mem->size; mip->offset = 0; if(mem->reloc || (mem->flags & MAP_ELF)) { mip->dev = 1; mip->ino = PID_TO_INO(prp->pid, 0); } else if((mem->flags & MAP_TYPE) == MAP_PRIVATE) { mip->dev = 2; mip->ino = 1; } else { mip->dev = 3; mip->ino = 1; } } if(mdp) { mdp->vaddr = vaddr - mem->reloc; if(mem->reloc || (mem->flags & MAP_ELF)) { if (prp->debug_name) STRLCPY(mdp->path, prp->debug_name, dbginfo_pathlen); else mdp->path[0] = '\0'; } else if((mem->flags & MAP_TYPE) == MAP_PRIVATE) { STRLCPY(mdp->path, "/dev/zero", dbginfo_pathlen); } else { STRLCPY(mdp->path, "/dev/mem", dbginfo_pathlen); } } return (mem->size - vaddr) - (mip ? mip->vaddr : vaddr); } return 0; }
/* * Work out what to complete when doing command line completion of menu names. */ char_u *set_context_in_menu_cmd(expand_T *xp, char_u *cmd, char_u *arg, int forceit) { char_u *after_dot; char_u *p; char_u *path_name = NULL; char_u *name; int unmenu; vimmenu_T *menu; int expand_menus; xp->xp_context = EXPAND_UNSUCCESSFUL; /* Check for priority numbers, enable and disable */ for (p = arg; *p; ++p) if (!VIM_ISDIGIT(*p) && *p != '.') break; if (!vim_iswhite(*p)) { if (STRNCMP(arg, "enable", 6) == 0 && (arg[6] == NUL || vim_iswhite(arg[6]))) p = arg + 6; else if (STRNCMP(arg, "disable", 7) == 0 && (arg[7] == NUL || vim_iswhite(arg[7]))) p = arg + 7; else p = arg; } while (*p != NUL && vim_iswhite(*p)) ++p; arg = after_dot = p; for (; *p && !vim_iswhite(*p); ++p) { if ((*p == '\\' || *p == Ctrl_V) && p[1] != NUL) p++; else if (*p == '.') after_dot = p + 1; } /* ":tearoff" and ":popup" only use menus, not entries */ expand_menus = !((*cmd == 't' && cmd[1] == 'e') || *cmd == 'p'); expand_emenu = (*cmd == 'e'); if (expand_menus && vim_iswhite(*p)) return NULL; /* TODO: check for next command? */ if (*p == NUL) { /* Complete the menu name */ /* * With :unmenu, you only want to match menus for the appropriate mode. * With :menu though you might want to add a menu with the same name as * one in another mode, so match menus from other modes too. */ expand_modes = get_menu_cmd_modes(cmd, forceit, NULL, &unmenu); if (!unmenu) expand_modes = MENU_ALL_MODES; menu = root_menu; if (after_dot != arg) { path_name = xmalloc(after_dot - arg); STRLCPY(path_name, arg, after_dot - arg); } name = path_name; while (name != NULL && *name) { p = menu_name_skip(name); while (menu != NULL) { if (menu_name_equal(name, menu)) { /* Found menu */ if ((*p != NUL && menu->children == NULL) || ((menu->modes & expand_modes) == 0x0)) { /* * Menu path continues, but we have reached a leaf. * Or menu exists only in another mode. */ free(path_name); return NULL; } break; } menu = menu->next; } if (menu == NULL) { /* No menu found with the name we were looking for */ free(path_name); return NULL; } name = p; menu = menu->children; } free(path_name); xp->xp_context = expand_menus ? EXPAND_MENUNAMES : EXPAND_MENUS; xp->xp_pattern = after_dot; expand_menu = menu; } else /* We're in the mapping part */ xp->xp_context = EXPAND_NOTHING; return NULL; }
void OS_get_table() { kvm_t *kd; char errbuf[_POSIX2_LINE_MAX]; struct kinfo_proc *procs; int count; int i, argcount; int ttynum; long start; char *ttydev; char cmndline[ARG_MAX+1]; char **pargv; /* for bless_into_proc */ static char format[F_LASTFIELD + 2]; char state[20]; /* open the kvm interface */ if ((kd = kvm_open(NULL, NULL, NULL, KVM_NO_FILES, errbuf)) == NULL) { ppt_croak("kvm_open: %s", errbuf); } /* get processes */ if ((procs = kvm_getprocs(kd, KERN_PROC_ALL, 0, sizeof(*procs), &count)) == NULL) { kvm_close(kd); ppt_croak("kvm_getprocs: %s", kvm_geterr(kd)); } /* bless_into_proc each process's information */ for (i=0; i < count; i++) { STRLCPY(1,format,Defaultformat); /* get ttydev */ ttynum=procs[i].p_tdev; ttydev=devname(ttynum, S_IFCHR); if (ttydev == NULL) ttydev = "??"; /* process state */ switch (procs[i].p_stat) { case SIDL: STRLCPY(2,state,"IDLE"); break; case SRUN: STRLCPY(3,state,"RUN"); break; case SSLEEP: STRLCPY(4,state,"SLEEP"); break; case SSTOP: STRLCPY(5,state,"STOP"); break; case SZOMB: STRLCPY(6,state,"ZOMBIE"); break; default: STRLCPY(7,state,"UNKNOWN"); break; } /* arguments */ cmndline[0] = '\0'; pargv = kvm_getargv(kd, (const struct kinfo_proc *) &(procs[i]), 0); if (pargv) { argcount = 0; while (pargv[argcount] && strlen(cmndline)+strlen(pargv[argcount])+1 <= ARG_MAX) { STRLCAT(1,cmndline,pargv[argcount]); if (pargv[argcount+1]) { STRLCAT(2,cmndline," "); } argcount++; } } /* everything else is straightforward, bless the lot */ bless_into_proc( format, Fields, ttynum, procs[i].p_ruid, procs[i].p_rgid, procs[i].p_uid, procs[i].p_gid, procs[i].p_pid, procs[i].p_ppid, procs[i].p__pgid, procs[i].p_sid, procs[i].p_rtime_sec, procs[i].p_uutime_sec, procs[i].p_ustime_sec, procs[i].p_ustart_sec, procs[i].p_comm, state, ttydev, cmndline ); } if (kd) { kvm_close(kd); } }
char * tgts2str(char *buf, u_int buf_len, DCC_TGTS tgts, u_char grey) { switch (tgts) { case DCC_TGTS_TOO_MANY: if (grey) STRLCPY(buf, DCC_XHDR_GREY_PASS, buf_len); else STRLCPY(buf, DCC_XHDR_TOO_MANY, buf_len); break; case DCC_TGTS_OK: STRLCPY(buf, DCC_XHDR_OK, buf_len); break; case DCC_TGTS_OK2: if (grey) /* DCC_TGTS_GREY_WHITE */ STRLCPY(buf, DCC_XHDR_OK, buf_len); else STRLCPY(buf, DCC_XHDR_OK2, buf_len); break; case DCC_TGTS_DEL: STRLCPY(buf, DCC_XHDR_DEL, buf_len); break; case DCC_TGTS_REP_ADJ: STRLCPY(buf, DCC_XHDR_TGTS_REP_ADJ, buf_len); break; case DCC_TGTS_OK_MX: STRLCPY(buf, DCC_XHDR_OK_MX, buf_len); break; case DCC_TGTS_OK_MXDCC: STRLCPY(buf, DCC_XHDR_OK_MXDCC, buf_len); break; case DCC_TGTS_SUBMIT_CLIENT: STRLCPY(buf, DCC_XHDR_SUBMIT_CLIENT, buf_len); break; case DCC_TGTS_INVALID: STRLCPY(buf, DCC_XHDR_INVALID, buf_len); break; default: if (tgts & DCC_TGTS_SPAM) snprintf(buf, buf_len, "%d spam", tgts & ~DCC_TGTS_SPAM); else snprintf(buf, buf_len, "%d", tgts); break; } return buf; }
static int bootimage_start(message_context_t *ctp, int code, unsigned flags, void *handle) { union image_dirent *dir; struct image_file *pfp; int fds[3]; int size; pid_t pid; PROCESS *prp; char *tty; char *tmp1, *tmp2; #ifdef PROC_BOOTIMAGE_DIR static char boot[_POSIX_PATH_MAX + 1] = "/" PROC_BOOTIMAGE_DIR "/"; #endif union script_cmd *scp; siginfo_t info; struct boot_data data; struct image_header *boot_image; struct sched_query query; size_t slen; data.boot = NULL; walk_asinfo("imagefs", map_ifs, &data); if(data.boot == NULL) { crash(); } boot_image = data.boot; if(proc_thread_pool_reserve() != 0) return(-1); prp = proc_lock_pid(SYSMGR_PID); if(sigismember(&prp->sig_ignore, SIGCHLD)) { proc_unlock(prp); proc_thread_pool_reserve_done(); return -1; } prp->flags |= _NTO_PF_LOADING; proc_unlock(prp); dir = (union image_dirent *)((char *)boot_image + boot_image->dir_offset); for(pfp = 0, scp = 0; dir->attr.size; dir = (union image_dirent *)((unsigned)dir + dir->attr.size)) { switch(dir->attr.mode & S_IFMT) { #ifdef PROC_BOOTIMAGE_DIR case S_IFLNK: pathmgr_symlink(&dir->symlink.path[dir->symlink.sym_offset], dir->symlink.path); break; case S_IFIFO: #endif case S_IFREG: if((boot_image->flags & IMAGE_FLAGS_INO_BITS) && (dir->attr.ino & IFS_INO_BOOTSTRAP_EXE)) { //If we have the INO flag bits, proc is the last bootstrap //executable. pfp = &dir->file; } else if(dir->file.offset == data.proc_offset) { pfp = &dir->file; } else if(dir->file.attr.ino == boot_image->script_ino) { scp = (union script_cmd *)((char *)boot_image + dir->file.offset); } #ifdef PROC_BOOTIMAGE_DIR if(strncmp(dir->file.path, boot + 1, sizeof PROC_BOOTIMAGE_DIR) || strchr(dir->file.path + sizeof PROC_BOOTIMAGE_DIR + 1, '/')) { static char link[_POSIX_PATH_MAX + 1] = "/"; char *p1, *p2; STRLCPY(&link[1], dir->file.path, sizeof(link) - 1); p1 = &boot[sizeof PROC_BOOTIMAGE_DIR + 1]; *p1++ = '.'; for(p2 = dir->file.path; *p1++ = (*p2 == '/' ? '.' : *p2); p2++); pathmgr_symlink(boot, link); } #endif break; default: break; } } if(!scp) { kprintf("Unable to find startup script\n"); proc_thread_pool_reserve_done(); return -1; } if(!pfp) { crash(); } slen = strlen(pfp->path) + 2; tmp1 = alloca(slen); if(!tmp1) { crash(); } tmp1[0] = '/'; memcpy(tmp1 + 1, pfp->path, slen - 1); // '\0' guaranteed to be copied tmp1 = dirname(tmp1); sysmgr_confstr_set(0, _CS_SYSNAME, "QNX"); sysmgr_confstr_set(0, _CS_PATH, (tmp2 = getenv("PATH")) ? tmp2 : tmp1); sysmgr_confstr_set(0, _CS_LIBPATH, (tmp2 = getenv("LD_LIBRARY_PATH")) ? tmp2 : tmp1); /* * Get the default path for shell for scripts without a #! interpreter */ shell_path = getenv("SHELL"); if (shell_path == NULL) { shell_path = "/bin/sh"; } if((fds[0] = sopen(pfp->path, O_RDONLY, SH_DENYNO)) == -1) { kprintf("bootimage: Unable to open '%s' (%d)\n", pfp->path, errno); proc_thread_pool_reserve_done(); return -1; } if(elf_load(fds[0], pfp->path, 0, 0, 0) != EOK) { kprintf("bootimage: Unable to load '%s'(%d)\n", pfp->path, errno); proc_thread_pool_reserve_done(); return -1; } close(fds[0]); #ifndef NKDEBUG kdebug_init(kdebug_path); (void)kdebug_attach(&prp->kdebug, 1); #endif prp->flags &= ~_NTO_PF_LOADING; fds[0] = fds[1] = fds[2] = sopen(tty = "/dev/text", O_RDWR, SH_DENYNO); if(SchedCtl(SCHED_QUERY_SCHED_EXT, &query, sizeof(query)) == -1) query.extsched = SCHED_EXT_NONE; for(pid = 0; (size = scp->hdr.size_lo | (scp->hdr.size_hi << 8)); scp = (union script_cmd *)((char *)scp + ((size + 3) & ~3))) { if(pid) { (void)waitid(P_PID, pid, &info, WEXITED|WTRAPPED); pid = 0; } switch(scp->hdr.type) { case SCRIPT_TYPE_DISPLAY_MSG: write(fds[0], scp->display_msg.msg, strlen(scp->display_msg.msg)); break; case SCRIPT_TYPE_WAITFOR: case SCRIPT_TYPE_REOPEN: tty = boot_waitfor_reopen(&scp->waitfor_reopen, fds, tty); break; case SCRIPT_TYPE_PROCMGR_SYMLINK: tmp1 = scp->procmgr_symlink.src_dest; (void)pathmgr_symlink(tmp1, &tmp1[strlen(tmp1) + 1]); break; case SCRIPT_TYPE_EXTSCHED_APS: if(query.extsched == SCHED_EXT_APS) { sched_aps_create_parms aps; APS_INIT_DATA(&aps); aps.name = scp->extsched_aps.pname; aps.budget_percent = scp->extsched_aps.budget; aps.critical_budget_ms = scp->extsched_aps.critical_hi << 8 | scp->extsched_aps.critical_lo; if(SchedCtl(SCHED_APS_CREATE_PARTITION, &aps, sizeof(aps))) kprintf("Unable to create APS '%s' (%d)\n", aps.name, errno); else if(aps.id != scp->extsched_aps.id) kprintf("Unexpected ID for APS '%s'\n", aps.name); } else { kprintf("Ignoring APS schedulling specification\n"); } break; case SCRIPT_TYPE_EXTERNAL: pid = boot_external(&scp->external, query.extsched, fds); break; default: kprintf("Unknown type %d\n", scp->hdr.type); break; } } prp = proc_lock_pid(SYSMGR_PID); sigaddset(&prp->sig_ignore, SIGCHLD); proc_unlock(prp); while(waitid(P_ALL, 0, &info, WNOHANG|WEXITED|WTRAPPED) > 0) { // Collect any grandchildren that might have been retargeted to proc // while we were running the boot image script file } close(fds[0]); proc_thread_pool_reserve_done(); return 0; }