Checking errno is actually wrong because it's only updated if
popen() fails (ie. NULL). One solution is to check if the first
line is empty.
Fixes: c95d258d1bc ("aco: fix printing ASM on GFX6-7 if clrxdisasm is not found")
Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5591>
sprintf(command, "clrxdisasm --gpuType=%s -r %s", gpu_type, path);
p = popen(command, "r");
- if (!p || errno == ENOENT) {
- out << "clrxdisasm not found\n";
- } else {
- while (fgets(line, sizeof(line), p))
+ if (p) {
+ if (!fgets(line, sizeof(line), p)) {
+ out << "clrxdisasm not found\n";
+ pclose(p);
+ goto fail;
+ }
+
+ do {
out << line;
+ } while (fgets(line, sizeof(line), p));
+
pclose(p);
}