| 98 | } |
| 99 | |
| 100 | int do_stream(const char *streamfn, uint8_t ignoreinput) { |
| 101 | char tmpfn[20], line[256]; |
| 102 | uint8_t tn; |
| 103 | size_t start, len; |
| 104 | int ret = 1; |
| 105 | int fdout = -1; |
| 106 | FILE *fin = NULL, *fout = NULL; |
| 107 | uint32_t addr, linenum; |
| 108 | struct msr m = MSR1(0); |
| 109 | |
| 110 | if (0 == strcmp(streamfn, "-")) { |
| 111 | fin = stdin; |
| 112 | fout = stdout; |
| 113 | } else { |
| 114 | if (!ignoreinput) { |
| 115 | if (NULL == (fin = fopen(streamfn, "r"))) { |
| 116 | perror("fopen()"); |
| 117 | return 1; |
| 118 | } |
| 119 | if (snprintf(tmpfn, sizeof(tmpfn), "msrtoolXXXXXX") >= sizeof(tmpfn)) { |
| 120 | perror("snprintf"); |
| 121 | return 1; |
| 122 | } |
| 123 | if (-1 == (fdout = mkstemp(tmpfn))) { |
| 124 | perror("mkstemp"); |
| 125 | return 1; |
| 126 | } |
| 127 | if (NULL == (fout = fdopen(fdout, "w"))) { |
| 128 | perror("fdopen"); |
| 129 | return 1; |
| 130 | } |
| 131 | } else { |
| 132 | if (NULL == (fout = fopen(streamfn, "w"))) { |
| 133 | perror("fopen"); |
| 134 | return 1; |
| 135 | } |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | if (!found_system()) |
| 140 | goto done; |
| 141 | if (!sys->open(cpu, SYS_RDONLY)) |
| 142 | goto done; |
| 143 | if (ignoreinput) { |
| 144 | for (tn = 0; tn < targets_found; tn++) |
| 145 | if (dumpmsrdefsvals(fout, targets[tn], cpu)) { |
| 146 | ret = 1; |
| 147 | break; |
| 148 | } |
| 149 | } else { |
| 150 | for (linenum = 1; NULL != fgets(line, sizeof(line), fin); ++linenum) { |
| 151 | start = (0 == strncmp("0x", line, 2)) ? 2 : 0; |
| 152 | if (1 == sscanf(line + start, "%8x", &addr)) { |
| 153 | if (!sys->rdmsr(cpu, addr, &m)) |
| 154 | goto done; |
| 155 | fprintf(fout, "0x%08x 0x%08x%08x\n", addr, m.hi, m.lo); |
| 156 | continue; |
| 157 | } |
no test coverage detected