MCPcopy Index your code
hub / github.com/GJDuck/e9patch / realMain

Function realMain

src/e9patch/e9patch.cpp:718–869  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

716 int realMain(int argc, char **argv);
717};
718int realMain(int argc, char **argv)
719{
720 option_is_tty = (isatty(STDERR_FILENO) != 0);
721 parseOptions(argv);
722
723 if (option_input != "-")
724 {
725 FILE *input = freopen(option_input.c_str(), "r", stdin);
726 if (input == nullptr)
727 error("failed to open file \"%s\" for reading: %s",
728 option_input.c_str(), strerror(errno));
729 }
730 if (option_output != "-")
731 {
732 FILE *output = freopen(option_output.c_str(), "w", stdout);
733 if (output == nullptr)
734 error("failed to open file \"%s\" for writing: %s",
735 option_output.c_str(), strerror(errno));
736 }
737 if (isatty(STDIN_FILENO))
738 warning("reading JSON-RPC from a terminal (this is probably not "
739 "what you want, please use E9Tool instead!)");
740
741 Binary *B = nullptr;
742 Message msg;
743 size_t lineno = 1;
744 while (getMessage(stdin, lineno, msg))
745 {
746 B = parseMessage(B, msg);
747 lineno = msg.lineno;
748 }
749 if (B == nullptr)
750 exit(EXIT_SUCCESS);
751
752 struct rusage usage;
753 memset(&usage, 0x0, sizeof(usage));
754 if (getrusage(RUSAGE_SELF, &usage) < 0)
755 warning("failed to get resource usage measures: %s", strerror(errno));
756
757 size_t stat_num_total = stat_num_patched + stat_num_failed;
758 size_t stat_time = usage.ru_utime.tv_sec * 1000 +
759 usage.ru_utime.tv_usec / 1000 +
760 usage.ru_stime.tv_sec * 1000 +
761 usage.ru_stime.tv_usec / 1000;
762 size_t stat_memory = usage.ru_maxrss;
763
764 ssize_t MAX_MAPPINGS = 65530;
765 const ssize_t MAX_MAPPINGS_DELTA = 128;
766 FILE *stream = fopen("/proc/sys/vm/max_map_count", "r");
767 if (stream != nullptr)
768 {
769 if (fscanf(stream, "%zd", &MAX_MAPPINGS) != 1)
770 ;
771 fclose(stream);
772 }
773
774 char percent[16];
775 snprintf(percent, sizeof(percent)-1, "%.2f",

Callers

nothing calls this directly

Calls 15

isattyFunction · 0.85
freopenFunction · 0.85
errorFunction · 0.85
strerrorFunction · 0.85
warningFunction · 0.85
getMessageFunction · 0.85
parseMessageFunction · 0.85
exitFunction · 0.85
memsetFunction · 0.85
getrusageFunction · 0.85
fopenFunction · 0.85
fscanfFunction · 0.85

Tested by

no test coverage detected