static void pr_error(const char *iname, const char *msg, bool is_warning) { fflush(stdout); fflush(stderr); char buf[1024]; buf[0] = 0; if (pr_need_nl == 2) printClearLine(stdout); else if (pr_need_nl) { buf[0] = '\n'; buf[1] = 0; printSetNl(0); } // This hack is needed, otherwise error messages may get lost // when the cursor is not yet at the bottom of the screen. // At least I can use some colors then... bool c = acc_isatty(STDERR_FILENO) ? 1 : 0; int fg = con_fg(stderr,FG_BRTRED); upx_snprintf(buf+strlen(buf),sizeof(buf)-strlen(buf),"%s: ", progname); pr_print(c,buf); //(void)con_fg(stderr,FG_RED); upx_snprintf(buf,sizeof(buf),"%s: ", iname); pr_print(c,buf); //(void)con_fg(stderr,FG_BRTRED); pr_print(c,msg); pr_print(c,"\n"); fflush(stdout); fflush(stderr); fg = con_fg(stderr,fg); UNUSED(is_warning); UNUSED(fg); }
bool maketempname(char *ofilename, size_t size, const char *ifilename, const char *ext, bool force) { char *ofext = NULL, *ofname; int ofile; if (size <= 0) return false; strcpy(ofilename, ifilename); for (ofname = fn_basename(ofilename); *ofname; ofname++) { if (*ofname == '.') ofext = ofname; } if (ofext == NULL) ofext = ofilename + strlen(ofilename); strcpy(ofext, ext); for (ofile = 0; ofile < 1000; ofile++) { assert(strlen(ofilename) < size); if (!file_exists(ofilename)) return true; if (!force) break; upx_snprintf(ofext, 5, ".%03d", ofile); } ofilename[0] = 0; return false; }
void tm2str(char *s, size_t size, const struct tm *tmp) { upx_snprintf(s, size, "%04d-%02d-%02d %02d:%02d:%02d", (int) tmp->tm_year + 1900, (int) tmp->tm_mon + 1, (int) tmp->tm_mday, (int) tmp->tm_hour, (int) tmp->tm_min, (int) tmp->tm_sec); }
bool set_method_name(char *buf, size_t size, int method, int level) { bool r = true; const char *alg; if (M_IS_NRV2B(method)) alg = "NRV2B"; else if (M_IS_NRV2D(method)) alg = "NRV2D"; else if (M_IS_NRV2E(method)) alg = "NRV2E"; else if (M_IS_LZMA(method)) alg = "LZMA"; else { alg = "???"; r = false; } if (level > 0) upx_snprintf(buf, size, "%s/%d", alg, level); else upx_snprintf(buf, size, "%s", alg); return r; }
void printErr(const char *iname, const Throwable *e) { char buf[1024]; size_t l; upx_snprintf(buf, sizeof(buf), "%s", prettyName(typeid(*e).name())); // upx_snprintf(buf, sizeof(buf), "%s", e->getMsg()); l = strlen(buf); if (l < sizeof(buf) && e->getMsg()) upx_snprintf(buf+l, sizeof(buf)-l, ": %s", e->getMsg()); l = strlen(buf); if (l < sizeof(buf) && e->getErrno()) { upx_snprintf(buf+l, sizeof(buf)-l, ": %s", strerror(e->getErrno())); #if 1 // some compilers (e.g. Borland C++) put a trailing '\n' // into strerror() result l = strlen(buf); while (l-- > 0 && (buf[l] == '\n' || buf[l] == ' ')) buf[l] = 0; #endif } pr_error(iname,buf,e->isWarning()); }
bool makebakname(char *ofilename, size_t size, const char *ifilename, bool force) { char *ofext = NULL, *ofname; int ofile; if (size <= 0) return false; strcpy(ofilename, ifilename); for (ofname = fn_basename(ofilename); *ofname; ofname++) { if (*ofname == '.') ofext = ofname; } if (ofext == NULL) { ofext = ofilename + strlen(ofilename); strcpy(ofext, ".~"); } else if (strlen(ofext) < 1 + 3) strcat(ofilename, "~"); else ofext[strlen(ofext)-1] = '~'; for (ofile = 0; ofile < 1000; ofile++) { assert(strlen(ofilename) < size); if (!file_exists(ofilename)) return true; if (!force) break; upx_snprintf(ofext, 5, ".%03d", ofile); } ofilename[0] = 0; return false; }