/* * Return an allocated string with the string representation of a Dictionary. * May return NULL. */ char_u * dict2string(typval_T *tv, int copyID, int restore_copyID) { garray_T ga; int first = TRUE; char_u *tofree; char_u numbuf[NUMBUFLEN]; hashitem_T *hi; char_u *s; dict_T *d; int todo; if ((d = tv->vval.v_dict) == NULL) return NULL; ga_init2(&ga, (int)sizeof(char), 80); ga_append(&ga, '{'); todo = (int)d->dv_hashtab.ht_used; for (hi = d->dv_hashtab.ht_array; todo > 0 && !got_int; ++hi) { if (!HASHITEM_EMPTY(hi)) { --todo; if (first) first = FALSE; else ga_concat(&ga, (char_u *)", "); tofree = string_quote(hi->hi_key, FALSE); if (tofree != NULL) { ga_concat(&ga, tofree); vim_free(tofree); } ga_concat(&ga, (char_u *)": "); s = echo_string_core(&HI2DI(hi)->di_tv, &tofree, numbuf, copyID, FALSE, restore_copyID, TRUE); if (s != NULL) ga_concat(&ga, s); vim_free(tofree); if (s == NULL || did_echo_string_emsg) break; line_breakcheck(); } } if (todo > 0) { vim_free(ga.ga_data); return NULL; } ga_append(&ga, '}'); ga_append(&ga, NUL); return (char_u *)ga.ga_data; }
int s6dns_analyze_record_strings (genwrite_t *gp, s6dns_message_rr_t const *rr, char const *packet, unsigned int packetlen, unsigned int start) { stralloc sa = STRALLOC_ZERO ; char buf[rr->rdlength] ; unsigned int pos = start ; register int r = s6dns_message_get_strings(buf, rr->rdlength, packet, packetlen, &pos) ; if (r < 0) return 0 ; if (rr->rdlength != pos - start) return (errno = EPROTO, 0) ; if (!string_quote(&sa, buf, r)) return 0 ; r = (*gp->put)(gp->target, sa.s, sa.len) >= 0 ; stralloc_free(&sa) ; return r ; }
static bool receive_responses(struct tcb *tcp, const int fd, const unsigned long inode, const unsigned long expected_msg_type, int (*parser)(const void *, int, unsigned long, void *), void *opaque_data) { static union { struct nlmsghdr hdr; long buf[8192 / sizeof(long)]; } hdr_buf; struct sockaddr_nl nladdr = { .nl_family = AF_NETLINK }; struct iovec iov = { .iov_base = hdr_buf.buf, .iov_len = sizeof(hdr_buf.buf) }; int flags = 0; for (;;) { struct msghdr msg = { .msg_name = &nladdr, .msg_namelen = sizeof(nladdr), .msg_iov = &iov, .msg_iovlen = 1 }; ssize_t ret = recvmsg(fd, &msg, flags); if (ret < 0) { if (errno == EINTR) continue; return false; } const struct nlmsghdr *h = &hdr_buf.hdr; if (!NLMSG_OK(h, ret)) return false; for (; NLMSG_OK(h, ret); h = NLMSG_NEXT(h, ret)) { if (h->nlmsg_type != expected_msg_type) return false; const int rc = parser(NLMSG_DATA(h), h->nlmsg_len, inode, opaque_data); if (rc > 0) return true; if (rc < 0) return false; } flags = MSG_DONTWAIT; } } static bool unix_send_query(struct tcb *tcp, const int fd, const unsigned long inode) { struct { const struct nlmsghdr nlh; const struct unix_diag_req udr; } req = { .nlh = { .nlmsg_len = sizeof(req), .nlmsg_type = SOCK_DIAG_BY_FAMILY, .nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST }, .udr = { .sdiag_family = AF_UNIX, .udiag_ino = inode, .udiag_states = -1, .udiag_show = UDIAG_SHOW_NAME | UDIAG_SHOW_PEER } }; return send_query(tcp, fd, &req, sizeof(req)); } static int unix_parse_response(const void *data, const int data_len, const unsigned long inode, void *opaque_data) { const char *proto_name = opaque_data; const struct unix_diag_msg *diag_msg = data; struct rtattr *attr; int rta_len = data_len - NLMSG_LENGTH(sizeof(*diag_msg)); uint32_t peer = 0; size_t path_len = 0; char path[UNIX_PATH_MAX + 1]; if (rta_len < 0) return -1; if (diag_msg->udiag_ino != inode) return 0; if (diag_msg->udiag_family != AF_UNIX) return -1; for (attr = (struct rtattr *) (diag_msg + 1); RTA_OK(attr, rta_len); attr = RTA_NEXT(attr, rta_len)) { switch (attr->rta_type) { case UNIX_DIAG_NAME: if (!path_len) { path_len = RTA_PAYLOAD(attr); if (path_len > UNIX_PATH_MAX) path_len = UNIX_PATH_MAX; memcpy(path, RTA_DATA(attr), path_len); path[path_len] = '\0'; } break; case UNIX_DIAG_PEER: if (RTA_PAYLOAD(attr) >= 4) peer = *(uint32_t *) RTA_DATA(attr); break; } } /* * print obtained information in the following format: * "UNIX:[" SELF_INODE [ "->" PEER_INODE ][ "," SOCKET_FILE ] "]" */ if (!peer && !path_len) return -1; char peer_str[3 + sizeof(peer) * 3]; if (peer) xsprintf(peer_str, "->%u", peer); else peer_str[0] = '\0'; const char *path_str; if (path_len) { char *outstr = alloca(4 * path_len + 4); outstr[0] = ','; if (path[0] == '\0') { outstr[1] = '@'; string_quote(path + 1, outstr + 2, path_len - 1, QUOTE_0_TERMINATED); } else { string_quote(path, outstr + 1, path_len, QUOTE_0_TERMINATED); } path_str = outstr; } else { path_str = ""; } char *details; if (asprintf(&details, "%s:[%lu%s%s]", proto_name, inode, peer_str, path_str) < 0) return -1; return cache_inode_details(inode, details); } static bool netlink_send_query(struct tcb *tcp, const int fd, const unsigned long inode) { struct { const struct nlmsghdr nlh; const struct netlink_diag_req ndr; } req = { .nlh = { .nlmsg_len = sizeof(req), .nlmsg_type = SOCK_DIAG_BY_FAMILY, .nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST }, .ndr = { .sdiag_family = AF_NETLINK, .sdiag_protocol = NDIAG_PROTO_ALL, .ndiag_show = NDIAG_SHOW_MEMINFO } }; return send_query(tcp, fd, &req, sizeof(req)); }
int fileop_put_by_name( char *file_name ) { FILE *fp; char name[ MAX_TOKEN_LENGTH ]; char s[80]; char **strp; char *quoted; int i; strcpy( name, file_name ); file_handle_path( name, MAX_TOKEN_LENGTH ); if ( NULL == (fp = fopen( name, "w" )) ) { cprintf( ERROR, CONT, "fail to put file \"%s\"\n", name ); return ( ERROR ); } fprintf( fp, "###\n" ); fprintf( fp, "### CaFE file made by \"put\" command.\n" ); fprintf( fp, "### --- %s ---\n", version_string( s ) ); fprintf( fp, "###\n" ); fprintf( fp, "\n" ); time_now( s ); fprintf( fp, "###\n### ### saved : %s\n###\n", s ); fprintf( fp, "\n\n### functions\n\n" ); if ( !(strcmp( file_name, PREFERENCE_FILE3 )) ) fprintf( fp, "\"\" package\n\n" ); function_list( fp ); fprintf( fp, "\n\n### history section\n\n" ); if ( NULL == (strp =( char **)malloc( sizeof( char * ) * g_cafe_mode.n_history.value )) ) { fclose( fp ); cprintf( ERROR, CONT, "fail to put file (@malloc)\"%s\"\n", name ); return ( ERROR ); } history_strings( strp, g_cafe_mode.n_history.value ); for ( i = (g_cafe_mode.n_history.value - 1); i >= 0 ; --i ) { if ( !strp[ i ] ) continue; if ( strstr( strp[ i ], "qq" ) ) continue; if ( strstr( strp[ i ], "quit" ) ) continue; quoted = string_quote( strp[ i ], '\"' ); fprintf( fp, "%s\thistory\n", quoted ); dispose_string_object( quoted ); } free( strp ); fclose( fp ); return ( NO_ERROR ); }
int loop_ioctl(struct tcb *tcp, long code, long arg) { struct loop_info info; struct loop_info64 info64; char *s = (char*)alloca((LO_NAME_SIZE + LO_KEY_SIZE) * 4); if (entering(tcp)) return 0; switch (code) { case LOOP_SET_STATUS: case LOOP_GET_STATUS: if (!verbose(tcp) || umove(tcp, arg, &info) < 0) return 0; tprintf(", {number=%d", info.lo_number); if (!abbrev(tcp)) { tprintf(", device=%#lx, inode=%lu, rdevice=%#lx", (unsigned long) info.lo_device, info.lo_inode, (unsigned long) info.lo_rdevice); } tprintf(", offset=%#x", info.lo_offset); if (!abbrev(tcp) || info.lo_encrypt_type != LO_CRYPT_NONE) { tprints(", encrypt_type="); printxval(loop_crypt_type_options, info.lo_encrypt_type, "LO_CRYPT_???"); tprintf(", encrypt_key_size=%d", info.lo_encrypt_key_size); } tprints(", flags="); printflags(loop_flags_options, info.lo_flags, "LO_FLAGS_???"); string_quote(info.lo_name, s, -1, LO_NAME_SIZE); tprintf(", name=%s", s); if (!abbrev(tcp) || info.lo_encrypt_type != LO_CRYPT_NONE) { string_quote((const char*) info.lo_encrypt_key, s, 0, LO_KEY_SIZE); tprintf(", encrypt_key=%s", s); } if (!abbrev(tcp)) tprintf(", init={%#lx, %#lx}" ", reserved={%#x, %#x, %#x, %#x}}", info.lo_init[0], info.lo_init[1], info.reserved[0], info.reserved[1], info.reserved[2], info.reserved[3]); else tprints(", ...}"); return 1; case LOOP_SET_STATUS64: case LOOP_GET_STATUS64: if (!verbose(tcp) || umove(tcp, arg, &info64) < 0) return 0; tprints(", {"); if (!abbrev(tcp)) { tprintf("device=%" PRIu64 ", inode=%" PRIu64 ", " "rdevice=%" PRIu64 ", offset=%#" PRIx64 ", " "sizelimit=%" PRIu64 ", number=%" PRIu32, (uint64_t) info64.lo_device, (uint64_t) info64.lo_inode, (uint64_t) info64.lo_rdevice, (uint64_t) info64.lo_offset, (uint64_t) info64.lo_sizelimit, (uint32_t) info64.lo_number); } else { tprintf("offset=%#" PRIx64 ", number=%" PRIu32, (uint64_t) info64.lo_offset, (uint32_t) info64.lo_number); } if (!abbrev(tcp) || info64.lo_encrypt_type != LO_CRYPT_NONE) { tprints(", encrypt_type="); printxval(loop_crypt_type_options, info64.lo_encrypt_type, "LO_CRYPT_???"); tprintf(", encrypt_key_size=%" PRIu32, info64.lo_encrypt_key_size); } tprints(", flags="); printflags(loop_flags_options, info64.lo_flags, "LO_FLAGS_???"); string_quote((const char*) info64.lo_file_name, s, -1, LO_NAME_SIZE); tprintf(", file_name=%s", s); if (!abbrev(tcp) || info64.lo_encrypt_type != LO_CRYPT_NONE) { string_quote((const char*) info64.lo_crypt_name, s, -1, LO_NAME_SIZE); tprintf(", crypt_name=%s", s); string_quote((const char*) info64.lo_encrypt_key, s, 0, LO_KEY_SIZE); tprintf(", encrypt_key=%s", s); } if (!abbrev(tcp)) tprintf(", init={%#" PRIx64 ", %#" PRIx64 "}}", (uint64_t) info64.lo_init[0], (uint64_t) info64.lo_init[1]); else tprints(", ...}"); return 1; case LOOP_CLR_FD: #ifdef LOOP_SET_CAPACITY case LOOP_SET_CAPACITY: #endif #ifdef LOOP_CTL_GET_FREE /* newer loop-control stuff */ case LOOP_CTL_GET_FREE: #endif /* Takes no arguments */ return 1; case LOOP_SET_FD: case LOOP_CHANGE_FD: #ifdef LOOP_CTL_ADD /* newer loop-control stuff */ case LOOP_CTL_ADD: case LOOP_CTL_REMOVE: #endif /* These take simple args, so let default printer handle it */ default: return 0; } }