static GOOD_OR_BAD LINK_sendback_data(const BYTE * data, BYTE * resp, const size_t size, const struct parsedname *pn) { struct connection_in * in = pn->selected_connection ; size_t left = size; size_t location = 0 ; BYTE buf[1+LINK_SEND_SIZE*2+1+1+in->CRLF_size] ; if (size == 0) { return gbGOOD; } //Debug_Bytes( "ELINK sendback send", data, size) ; while (left > 0) { // Loop through taking only 32 bytes at a time size_t this_length = (left > LINK_SEND_SIZE) ? LINK_SEND_SIZE : left; size_t this_length2 = 2 * this_length ; // doubled for switch from hex to ascii buf[0] = 'b'; //put in byte mode bytes2string((char *) &buf[1], &data[location], this_length); // load in data as ascii data buf[1+this_length2] = '\r'; // take out of byte mode // send to LINK RETURN_BAD_IF_BAD(LINK_write(buf, 1+this_length2+1, in) ) ; // read back RETURN_BAD_IF_BAD( LINK_readback_data(buf, this_length2, in) ) ; // place data (converted back to hex) in resp string2bytes((char *) buf, &resp[location], this_length); left -= this_length; location += this_length ; } //Debug_Bytes( "ELINK sendback get", resp, size) ; return gbGOOD; }
std::string WriteRequestPDU::toString() { std::ostringstream stream; stream << " targetAttribute: " << targetAttribute.toString(); stream << ", parameters: " << bytes2string(*value); return stream.str(); }
void dbrew_print_decoded(DBB* bb) { int i; for(i = 0; i < bb->count; i++) { Instr* instr = bb->instr + i; printf(" %18s: ", prettyAddress(instr->addr, bb->fc)); printf("%s %s\n", bytes2string(instr, 0, 7), instr2string(instr, 1, bb->fc)); if (instr->len > 7) printf(" %18s: %s\n", prettyAddress(instr->addr + 7, bb->fc), bytes2string(instr, 7, 7)); if (instr->len > 14) printf(" %18s: %s\n", prettyAddress(instr->addr + 14, bb->fc), bytes2string(instr, 14, 7)); } }
static void Aliaslistaction(const void *node, const VISIT which, const int depth) { const struct tree_node *p = *(struct tree_node * const *) node; (void) depth; char SN_address[SERIAL_NUMBER_SIZE*2] ; switch (which) { case leaf: case postorder: if ( p->tk.p != Alias_Marker ) { return ; } // Add sn address bytes2string(SN_address, p->tk.sn, SERIAL_NUMBER_SIZE); MemblobAdd( (BYTE *) SN_address, SERIAL_NUMBER_SIZE*2, aliaslist_mb ) ; // Add '=' MemblobAdd( (BYTE *) "=", 1, aliaslist_mb ) ; // Add alias name MemblobAdd( (const BYTE *)CONST_TREE_DATA(p), p->dsize, aliaslist_mb ) ; // Add <CR> MemblobAdd( (BYTE *) "\x0D\x0A", 2, aliaslist_mb ) ; return ; case preorder: case endorder: break; } }
std::string ExecuteResponsePDU::toString() { std::ostringstream stream; stream << " forwardCongestionNotificationEcho: " << (int) forwardCongestionNotificationEcho; stream << ", feedbackCode: " << (int) feedbackCode; stream << ", parameters: " << bytes2string(*parameters); return stream.str(); }
/* replace alias with sn */ static void ReplaceAliasInPath( char * filename, struct parsedname * pn) { int alias_len = strlen(filename) ; // check total length if ( strlen(pn->path_to_server) + 14 - alias_len <= PATH_MAX ) { // find the alias char * alias_loc = find_segment_in_path( filename, pn->path_to_server ) ; if ( alias_loc != NULL ) { char * post_alias_loc ; post_alias_loc = alias_loc + alias_len ; // move rest of path memmove( &alias_loc[14], post_alias_loc, strlen(post_alias_loc)+1 ) ; //write in serial number for alias bytes2string( alias_loc, pn->sn, 7 ) ; } } }
// generate code for a captured BB void generate(Rewriter* r, CBB* cbb) { uint8_t* buf; uint64_t buf0; int used, i, usedTotal; if (cbb == 0) return; if (r->cs == 0) return; if (r->showEmuSteps) printf("Generating code for BB %s (%d instructions)\n", cbb_prettyName(cbb), cbb->count); usedTotal = 0; buf0 = (uint64_t) reserveCodeStorage(r->cs, 0); // remember start address for(i = 0; i < cbb->count; i++) { Instr* instr = cbb->instr + i; buf = reserveCodeStorage(r->cs, 15); if (instr->ptLen > 0) { used = genPassThrough(buf, instr); } else { switch(instr->type) { case IT_ADD: used = genAdd(buf, &(instr->src), &(instr->dst)); break; case IT_CLTQ: used = genCltq(buf, instr->vtype); break; case IT_CQTO: used = genCqto(buf, instr->vtype); break; case IT_CMP: used = genCmp(buf, &(instr->src), &(instr->dst)); break; case IT_DEC: used = genDec(buf, &(instr->dst)); break; case IT_IMUL: used = genIMul(buf, &(instr->src), &(instr->dst)); break; case IT_IDIV1: used = genIDiv1(buf, &(instr->dst)); break; case IT_INC: used = genInc(buf, &(instr->dst)); break; case IT_XOR: used = genXor(buf, &(instr->src), &(instr->dst)); break; case IT_OR: used = genOr(buf, &(instr->src), &(instr->dst)); break; case IT_AND: used = genAnd(buf, &(instr->src), &(instr->dst)); break; case IT_SHL: used = genShl(buf, &(instr->src), &(instr->dst)); break; case IT_SHR: used = genShr(buf, &(instr->src), &(instr->dst)); break; case IT_SAR: used = genSar(buf, &(instr->src), &(instr->dst)); break; case IT_LEA: used = genLea(buf, &(instr->src), &(instr->dst)); break; case IT_MOV: case IT_MOVSX: // converting move used = genMov(buf, &(instr->src), &(instr->dst)); break; case IT_CMOVO: case IT_CMOVNO: case IT_CMOVC: case IT_CMOVNC: case IT_CMOVZ: case IT_CMOVNZ: case IT_CMOVBE: case IT_CMOVA: case IT_CMOVS: case IT_CMOVNS: case IT_CMOVP: case IT_CMOVNP: case IT_CMOVL: case IT_CMOVGE: case IT_CMOVLE: case IT_CMOVG: used = genCMov(buf, instr->type, &(instr->src), &(instr->dst)); break; case IT_POP: used = genPop(buf, &(instr->dst)); break; case IT_PUSH: used = genPush(buf, &(instr->dst)); break; case IT_RET: used = genRet(buf); break; case IT_SUB: used = genSub(buf, &(instr->src), &(instr->dst)); break; case IT_TEST: used = genTest(buf, &(instr->src), &(instr->dst)); break; case IT_HINT_CALL: case IT_HINT_RET: used = 0; break; default: assert(0); } } assert(used < 15); instr->addr = (uint64_t) buf; instr->len = used; usedTotal += used; if (r->showEmuSteps) { printf(" I%2d : %-32s", i, instr2string(instr, 1, 0)); printf(" (%s)+%lx %s\n", cbb_prettyName(cbb), instr->addr - buf0, bytes2string(instr, 0, used)); } useCodeStorage(r->cs, used); } if (r->showEmuSteps) { if (instrIsJcc(cbb->endType)) { assert(cbb->nextBranch != 0); assert(cbb->nextFallThrough != 0); printf(" I%2d : %s (%s),", i, instrName(cbb->endType, 0), cbb_prettyName(cbb->nextBranch)); printf(" fall-through to (%s)\n", cbb_prettyName(cbb->nextFallThrough)); } } // add padding space after generated code for jump instruction buf = useCodeStorage(r->cs, 10); cbb->size = usedTotal; // start address of generated code. // if CBB had no instruction, this points to the padding buffer cbb->addr1 = (cbb->count == 0) ? ((uint64_t)buf) : cbb->instr[0].addr; }
void CDBoxInfoWidget::paint() { const int head_info_lines = 3; const char *head_info[head_info_lines] = {"Uptime", "Load average", "Current load"}; height = hheight; height += mheight/2; // space int cpuload_y0 = height; int head_info_ypos = height; height += mheight*head_info_lines; // head info lines int cpuload_y1 = height; height += mheight/2; // space int icon_w = 0, icon_h = 0; frameBuffer->getIconSize(NEUTRINO_ICON_REC, &icon_w, &icon_h); #define MEMINFO_TOTAL 0 #define MEMINFO_USED 1 #define MEMINFO_FREE 2 #define MEMINFO_COLUMNS 3 #define MEMINFO_RAM 0 #define MEMINFO_SWAP 1 #define MEMINFO_ROWS 2 unsigned long memstat[MEMINFO_ROWS][MEMINFO_COLUMNS] = { { 0, 0, 0 }, { 0, 0, 0 } }; // total, used, free const char *memtype[MEMINFO_ROWS] = { "RAM", "Swap" }; FILE *procmeminfo = fopen("/proc/meminfo", "r"); if (procmeminfo) { char buf[80], a[80]; unsigned long v; while (fgets(buf, sizeof(buf), procmeminfo)) { if (2 == sscanf(buf, "%[^:]: %lu", a, &v)) { if (!strcasecmp(a, "MemTotal")) memstat[MEMINFO_RAM][MEMINFO_TOTAL] += v; else if (!strcasecmp(a, "MemFree")) memstat[MEMINFO_RAM][MEMINFO_FREE] += v; else if (!strcasecmp(a, "Inactive")) memstat[MEMINFO_RAM][MEMINFO_FREE] += v; else if (!strcasecmp(a, "SwapTotal")) memstat[MEMINFO_SWAP][MEMINFO_TOTAL] = v; else if (!strcasecmp(a, "SwapFree")) memstat[MEMINFO_SWAP][MEMINFO_FREE] += v; } } fclose(procmeminfo); } bool have_swap = memstat[MEMINFO_SWAP][MEMINFO_TOTAL]; height += mheight; // header height += mheight; // ram height += have_swap * mheight; // swap height += mheight/2; // space std::ifstream in; std::map<std::string,bool> mounts; in.open("/proc/mounts"); if (in.is_open()) { struct stat rec_st; struct statfs s; if (stat(g_settings.network_nfs_recordingdir.c_str(), &rec_st) || (!::statfs(g_settings.network_nfs_recordingdir.c_str(), &s) && ((s.f_type == 0x72b6) || (s.f_type == 0x5941ff53)))) memset(&rec_st, 0, sizeof(rec_st)); std::map<dev_t,std::string> seen; std::string line; while (getline(in, line)) { size_t firstslash = line.find_first_of('/'); size_t firstspace = line.find_first_of(' '); if ( (firstspace != string::npos && firstslash != string::npos && firstslash < firstspace) || (line.find("rootfs") == 0) ) { firstspace++; size_t nextspace = line.find_first_of(' ', firstspace); if (nextspace == string::npos || line.find("nodev", nextspace + 1) != string::npos) continue; std::string mountpoint = line.substr(firstspace, nextspace - firstspace); struct stat st; if (stat(mountpoint.c_str(), &st) || (seen.find(st.st_dev) != seen.end())) continue; seen[st.st_dev] = mountpoint; bool is_rec = (st.st_dev == rec_st.st_dev); mounts[mountpoint] = is_rec; int icon_space = is_rec ? 10 + icon_w : 0; const char *mnt = mountpoint.c_str(); nameWidth = std::max(nameWidth, g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getRenderWidth(basename((char *)mnt), true) + icon_space + 10); } } in.close(); } height += mheight; // header height += mounts.size() * mheight; // file systems height += mheight/2; // space int offsetw = nameWidth+ (sizeWidth+10)*3 +10+percWidth+10; width = offsetw + 10 + 120; int diff = frameBuffer->getScreenWidth() - width; if (diff < 0) { width += diff; offsetw += diff; nameWidth += diff; } height = h_max(height, 0); x = getScreenStartX(width); y = getScreenStartY(height); // fprintf(stderr, "CDBoxInfoWidget::CDBoxInfoWidget() x = %d, y = %d, width = %d height = %d\n", x, y, width, height); int ypos=y; //paint head std::string title(g_Locale->getText(LOCALE_EXTRA_DBOXINFO)); std::map<std::string,std::string> cpuinfo; in.open("/proc/cpuinfo"); if (in.is_open()) { std::string line; while (getline(in, line)) { size_t colon = line.find_first_of(':'); if (colon != string::npos && colon > 1) { std::string key = line.substr(0, colon - 1); std::string val = line.substr(colon + 1); cpuinfo[trim(key)] = trim(val); } } in.close(); } if (!cpuinfo["Hardware"].empty()) { title += ": "; title += cpuinfo["Hardware"]; } else if (!cpuinfo["machine"].empty()) { title += ": "; title + cpuinfo["machine"]; } CComponentsHeader header(x, ypos, width, hheight, title, NEUTRINO_ICON_SHELL); header.paint(CC_SAVE_SCREEN_NO); //paint body frameBuffer->paintBoxRel(x, ypos+ hheight, width, height- hheight, COL_MENUCONTENT_PLUS_0, RADIUS_LARGE, CORNER_BOTTOM); ypos += hheight + mheight/2; int head_info_rw = 0; for (int line = 0; line < head_info_lines; line++) { head_info_rw = std::max(head_info_rw, g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getRenderWidth(head_info[line], true)); } int dw = offsetw - 3*10 - head_info_rw; int buf_size=256; char ubuf[buf_size]; char sbuf[buf_size]; memset(sbuf, 0, 256); struct sysinfo info; sysinfo(&info); //get uptime #if 0 struct tm *current_time; time_t current_secs; time(¤t_secs); current_time = localtime(¤t_secs); snprintf( ubuf,buf_size, "%02d:%02d%s up ", current_time->tm_hour%12 ? current_time->tm_hour%12 : 12, current_time->tm_min, current_time->tm_hour > 11 ? "pm" : "am"); strcat(sbuf, ubuf); #endif int updays, uphours, upminutes; updays = (int) info.uptime / (60*60*24); upminutes = (int) info.uptime / 60; uphours = (upminutes / 60) % 24; upminutes %= 60; if (updays) { snprintf(ubuf,buf_size, "%d day%s, ", updays, (updays != 1) ? "s" : ""); strcat(sbuf, ubuf); } if (uphours) { snprintf(ubuf,buf_size,"%d hour%s, ", uphours, (uphours != 1) ? "s" : ""); strcat(sbuf, ubuf); } snprintf(ubuf,buf_size,"%d minute%s", upminutes, (upminutes != 1) ? "s" : ""); strcat(sbuf, ubuf); //paint uptime g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->RenderString(x + 2*10 + head_info_rw, ypos+ mheight, dw, sbuf, COL_MENUCONTENT_TEXT); ypos += mheight; //get load avg snprintf(ubuf,buf_size, "%ld.%02ld, %ld.%02ld, %ld.%02ld", LOAD_INT(info.loads[0]), LOAD_FRAC(info.loads[0]), LOAD_INT(info.loads[1]), LOAD_FRAC(info.loads[1]), LOAD_INT(info.loads[2]), LOAD_FRAC(info.loads[2])); //paint load avg g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->RenderString(x + 2*10 + head_info_rw, ypos+ mheight, dw, ubuf, COL_MENUCONTENT_TEXT); ypos += mheight; //get current load cSysLoad *sysload = cSysLoad::getInstance(); int data_last = sysload->data_last; //paint current load if (data_last > -1) { snprintf(ubuf, sizeof(ubuf), "%d%s%d%%", data_last/10, g_Locale->getText(LOCALE_UNIT_DECIMAL), data_last%10); g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->RenderString(x + 2*10 + head_info_rw, ypos+ mheight, dw, ubuf, COL_MENUCONTENT_TEXT); } ypos += mheight; int pbw = width - offsetw - 10; if (pbw > 8) /* smaller progressbar is not useful ;) */ { unsigned int h = cpuload_y1 - cpuload_y0; cpuload_y0 += y; cpuload_y1 += y; frameBuffer->paintBoxRel(x + offsetw, cpuload_y0, pbw, h, COL_MENUCONTENT_PLUS_2); int off = std::max(0, (int)sysload->data_avail - pbw); for (unsigned int i = 0; i < sysload->data_avail - off; i++) { if (sysload->data[i + off] > -1) frameBuffer->paintVLine(x+offsetw + i, cpuload_y1 - sysload->data[i + off] * h / 1000, cpuload_y1, COL_MENUCONTENT_PLUS_7); } } ypos += mheight/2; int headOffset=0; int mpOffset=0; int offsets[] = { 10, nameWidth + 10, nameWidth + 10 + (sizeWidth+10)*1, nameWidth + 10 + (sizeWidth+10)*2, nameWidth + 10 + (sizeWidth+10)*3, }; int widths[] = { 0, sizeWidth, sizeWidth, sizeWidth, percWidth }; const int headSize = 5; int maxWidth[headSize]; memset(maxWidth, 0, headSize * sizeof(int)); int ypos_mem_head = ypos; ypos += mheight; for (int row = 0; row < 1 + have_swap; row++) { std::string tmp; memstat[row][MEMINFO_USED] = memstat[row][MEMINFO_TOTAL] - memstat[row][MEMINFO_FREE]; for (int column = 0; column < headSize; column++) { switch (column) { case 0: tmp = memtype[row]; break; case 1: tmp = bytes2string(memstat[row][MEMINFO_TOTAL] << 10); break; case 2: tmp = bytes2string(memstat[row][MEMINFO_USED] << 10); break; case 3: tmp = bytes2string(memstat[row][MEMINFO_FREE] << 10); break; case 4: tmp = to_string(memstat[row][MEMINFO_TOTAL] ? (memstat[row][MEMINFO_USED] * 100) / memstat[row][MEMINFO_TOTAL] : 0) + "%"; break; } mpOffset = offsets[column]; int space = 0; int rw = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getRenderWidth(tmp, true); if (column > 0) { space = widths[column] - rw; } maxWidth[column] = std::max(maxWidth[column], rw)+6; if ((mpOffset + space + maxWidth[column]) > width) maxWidth[column] = width - (mpOffset + space); g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->RenderString(x + mpOffset + space, ypos+ mheight, maxWidth[column], tmp, COL_MENUCONTENT_TEXT); } if (pbw > 8) /* smaller progressbar is not useful ;) */ { CProgressBar pb(x+offsetw, ypos+3, pbw, mheight-10); pb.setBlink(); pb.setInvert(); pb.setValues(memstat[row][MEMINFO_TOTAL] ? (memstat[row][MEMINFO_USED] * 100) / memstat[row][MEMINFO_TOTAL] : 0, 100); pb.paint(false); } ypos += mheight; } ypos += mheight/2; int ypos_mnt_head = ypos; ypos += mheight; int width_i = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getRenderWidth("i", true); for (std::map<std::string, bool>::iterator it = mounts.begin(); it != mounts.end(); ++it) { struct statfs s; if (::statfs((*it).first.c_str(), &s) == 0) { if (s.f_blocks > 0) { uint64_t bytes_total = s.f_blocks * s.f_bsize; uint64_t bytes_free = s.f_bfree * s.f_bsize; uint64_t bytes_used = bytes_total - bytes_free; int percent_used = (bytes_used * 200 + bytes_total) / 2 / bytes_total; //paint mountpoints for (int column = 0; column < headSize; column++) { std::string tmp; const char *mnt; mpOffset = offsets[column]; int _w = maxWidth[column]; switch (column) { case 0: tmp = (*it).first; if (tmp == "/") tmp = "rootfs"; mnt = tmp.c_str(); tmp = basename((char *)mnt); _w = nameWidth - mpOffset; if ((*it).second) _w -= icon_w + 10; _w += width_i/2; break; case 1: tmp = bytes2string(bytes_total, false); break; case 2: tmp = bytes2string(bytes_used, false); break; case 3: tmp = bytes2string(bytes_free, false); break; case 4: tmp = to_string(percent_used) + "%"; break; } int space = 0; if (column > 0) { int rw = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getRenderWidth(tmp, true); maxWidth[column] = std::max(maxWidth[column], rw); space = widths[column] - rw; _w = rw; } if ((mpOffset + space + _w) > width) _w = width - (mpOffset + space); g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->RenderString(x + mpOffset + space, ypos+ mheight, _w, tmp, COL_MENUCONTENT_TEXT); if ((*it).second && icon_w>0 && icon_h>0) frameBuffer->paintIcon(NEUTRINO_ICON_REC, x + nameWidth - icon_w + width_i/2, ypos + (mheight/2 - icon_h/2)); } if (pbw > 8) /* smaller progressbar is not useful ;) */ { CProgressBar pb(x+offsetw, ypos+3, pbw, mheight-10); pb.setBlink(); pb.setInvert(); pb.setValues(percent_used, 100); pb.paint(false); } ypos += mheight; } } if (ypos > y + height - mheight) /* the screen is not high enough */ break; /* todo: scrolling? */ } // paint info heads head_info_ypos += y; for (int line = 0; line < head_info_lines; line++) { g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->RenderString(x + 10, head_info_ypos + mheight*(line+1), head_info_rw, head_info[line], COL_MENUCONTENTINACTIVE_TEXT); } // paint mem head const char *head_mem[headSize] = {"Memory", "Size", "Used", "Available", "Use"}; for (int column = 0; column < headSize; column++) { headOffset = offsets[column]; int space = 0; int rw = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getRenderWidth(head_mem[column], true); int _w = rw; if (column > 0) { if (rw > maxWidth[column]) space = widths[column] - rw; else space = widths[column] - maxWidth[column] + (maxWidth[column] - rw)/2; } g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->RenderString(x+ headOffset + space, ypos_mem_head + mheight, _w, head_mem[column], COL_MENUCONTENTINACTIVE_TEXT); } // paint mount head const char *head_mnt[headSize] = {"Filesystem", "Size", "Used", "Available", "Use"}; for (int column = 0; column < headSize; column++) { headOffset = offsets[column]; int space = 0; int rw = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getRenderWidth(head_mnt[column], true); int _w = rw; if (column > 0) { if (rw > maxWidth[column]) space = widths[column] - rw; else space = widths[column] - maxWidth[column] + (maxWidth[column] - rw)/2; } g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->RenderString(x+ headOffset + space, ypos_mnt_head + mheight, _w, head_mnt[column], COL_MENUCONTENTINACTIVE_TEXT); } }
static ZERO_OR_ERROR FS_read_tester_single(struct one_wire_query *owq) { struct parsedname *pn = PN(owq); int tester_bus = (pn->sn[2] << 8) + pn->sn[1]; int device = (pn->sn[6] << 8) + pn->sn[5]; int family_code = pn->sn[0]; int calculated_value = family_code + tester_bus + device + pn->extension; switch (OWQ_pn(owq).selected_filetype->format) { case ft_integer: OWQ_I(owq) = calculated_value; break; case ft_yesno: OWQ_Y(owq) = calculated_value & 0x1; break; case ft_bitfield: if (OWQ_pn(owq).extension == EXTENSION_BYTE) { OWQ_U(owq) = calculated_value; } else { OWQ_Y(owq) = calculated_value & 0x1; } break; case ft_unsigned: OWQ_U(owq) = calculated_value; break; case ft_pressure: case ft_temperature: case ft_tempgap: case ft_float: OWQ_F(owq) = (_FLOAT) calculated_value *0.1;; break; case ft_date: OWQ_D(owq) = 1174622400; break; case ft_alias: case ft_vascii: case ft_ascii: { ASCII address[16]; size_t length_left = OWQ_size(owq); size_t buffer_index; size_t length = FileLength(PN(owq)); ASCII return_chars[length]; bytes2string(address, pn->sn, SERIAL_NUMBER_SIZE); OWQ_length(owq) = OWQ_size(owq); for (buffer_index = 0; buffer_index < length; buffer_index += sizeof(address)) { size_t copy_length = length_left; if (copy_length > sizeof(address)) { copy_length = sizeof(address); } memcpy(&return_chars[buffer_index], address, copy_length); length_left -= copy_length; } return OWQ_format_output_offset_and_size(return_chars, length, owq); } case ft_binary: { size_t length_left = OWQ_size(owq); size_t buffer_index; size_t length = FileLength(PN(owq)); ASCII return_chars[length]; OWQ_length(owq) = OWQ_size(owq); for (buffer_index = 0; buffer_index < length; buffer_index += SERIAL_NUMBER_SIZE) { size_t copy_length = length_left; if (copy_length > SERIAL_NUMBER_SIZE) { copy_length = SERIAL_NUMBER_SIZE; } memcpy(&return_chars[buffer_index], pn->sn, copy_length); length_left -= copy_length; } return OWQ_format_output_offset_and_size(return_chars, length, owq); } case ft_directory: case ft_subdir: case ft_unknown: return -ENOENT; } return 0; // put data as string into buffer and return length }