data/full_repos/permissive/143278/ivltests/pr2800985a.v
 line:23: before: ";"
1: b'%Error: data/full_repos/permissive/143278/ivltests/pr2800985a.v:31: Unsupported or unknown PLI call: $ferror\n      errno = $ferror(vfd, result);\n              ^~~~~~~\n%Error: data/full_repos/permissive/143278/ivltests/pr2800985a.v:43: Unsupported or unknown PLI call: $ferror\n      errno = $ferror(vfd, result);\n              ^~~~~~~\n%Error: data/full_repos/permissive/143278/ivltests/pr2800985a.v:52: Unsupported or unknown PLI call: $ferror\n    errno = $ferror(1, result);\n            ^~~~~~~\n%Error: data/full_repos/permissive/143278/ivltests/pr2800985a.v:62: Unsupported or unknown PLI call: $ferror\n    errno = $ferror(bfd, result);\n            ^~~~~~~\n%Error: data/full_repos/permissive/143278/ivltests/pr2800985a.v:88: Unsupported or unknown PLI call: $ferror\n    errno = $ferror(bfd, result);\n            ^~~~~~~\n%Error: data/full_repos/permissive/143278/ivltests/pr2800985a.v:98: Unsupported or unknown PLI call: $ferror\n    errno = $ferror(bfd, result);\n            ^~~~~~~\n%Error: data/full_repos/permissive/143278/ivltests/pr2800985a.v:103: Unsupported or unknown PLI call: $ferror\n    errno = $ferror(bfd, result);\n            ^~~~~~~\n%Error: data/full_repos/permissive/143278/ivltests/pr2800985a.v:113: Unsupported or unknown PLI call: $ferror\n    errno = $ferror(bfd, result);\n            ^~~~~~~\n%Error: data/full_repos/permissive/143278/ivltests/pr2800985a.v:118: Unsupported or unknown PLI call: $ferror\n    errno = $ferror(bfd, result);\n            ^~~~~~~\n%Error: data/full_repos/permissive/143278/ivltests/pr2800985a.v:127: syntax error, unexpected \')\'\n    $fwrite(bfd);\n               ^\n%Error: data/full_repos/permissive/143278/ivltests/pr2800985a.v:128: Unsupported or unknown PLI call: $ferror\n    errno = $ferror(bfd, result);\n            ^~~~~~~\n%Error: data/full_repos/permissive/143278/ivltests/pr2800985a.v:132: syntax error, unexpected \')\'\n    $fwrite(bfd);\n               ^\n%Error: data/full_repos/permissive/143278/ivltests/pr2800985a.v:133: Unsupported or unknown PLI call: $ferror\n    errno = $ferror(bfd, result);\n            ^~~~~~~\n%Error: data/full_repos/permissive/143278/ivltests/pr2800985a.v:142: Unsupported or unknown PLI call: $fstrobe\n    $fstrobe(bfd);\n    ^~~~~~~~\n%Error: data/full_repos/permissive/143278/ivltests/pr2800985a.v:143: Unsupported or unknown PLI call: $ferror\n    errno = $ferror(bfd, result);\n            ^~~~~~~\n%Error: data/full_repos/permissive/143278/ivltests/pr2800985a.v:147: Unsupported or unknown PLI call: $fstrobe\n    $fstrobe(bfd);\n    ^~~~~~~~\n%Error: data/full_repos/permissive/143278/ivltests/pr2800985a.v:148: Unsupported or unknown PLI call: $ferror\n    errno = $ferror(bfd, result);\n            ^~~~~~~\n%Error: data/full_repos/permissive/143278/ivltests/pr2800985a.v:159: Unsupported or unknown PLI call: $ferror\n    errno = $ferror(bfd, result);\n            ^~~~~~~\n%Error: data/full_repos/permissive/143278/ivltests/pr2800985a.v:165: Unsupported or unknown PLI call: $ferror\n    errno = $ferror(bfd, result);\n            ^~~~~~~\n%Error: data/full_repos/permissive/143278/ivltests/pr2800985a.v:177: Unsupported or unknown PLI call: $ferror\n    errno = $ferror(bfd, result);\n            ^~~~~~~\n%Error: data/full_repos/permissive/143278/ivltests/pr2800985a.v:183: Unsupported or unknown PLI call: $ferror\n    errno = $ferror(bfd, result);\n            ^~~~~~~\n%Error: data/full_repos/permissive/143278/ivltests/pr2800985a.v:189: Unsupported or unknown PLI call: $ferror\n    errno = $ferror(vfd, result);\n            ^~~~~~~\n%Error: data/full_repos/permissive/143278/ivltests/pr2800985a.v:205: Unsupported or unknown PLI call: $ferror\n    errno = $ferror(bfd, result);\n            ^~~~~~~\n%Error: data/full_repos/permissive/143278/ivltests/pr2800985a.v:211: Unsupported or unknown PLI call: $ferror\n    errno = $ferror(bfd, result);\n            ^~~~~~~\n%Error: data/full_repos/permissive/143278/ivltests/pr2800985a.v:222: Unsupported or unknown PLI call: $ferror\n    errno = $ferror(bfd, result);\n            ^~~~~~~\n%Error: data/full_repos/permissive/143278/ivltests/pr2800985a.v:228: Unsupported or unknown PLI call: $ferror\n    errno = $ferror(bfd, result);\n            ^~~~~~~\n%Error: data/full_repos/permissive/143278/ivltests/pr2800985a.v:239: Unsupported or unknown PLI call: $ferror\n    errno = $ferror(bfd, result);\n            ^~~~~~~\n%Error: data/full_repos/permissive/143278/ivltests/pr2800985a.v:245: Unsupported or unknown PLI call: $ferror\n    errno = $ferror(bfd, result);\n            ^~~~~~~\n%Error: data/full_repos/permissive/143278/ivltests/pr2800985a.v:256: Unsupported or unknown PLI call: $ferror\n    errno = $ferror(bfd, result);\n            ^~~~~~~\n%Error: data/full_repos/permissive/143278/ivltests/pr2800985a.v:262: Unsupported or unknown PLI call: $ferror\n    errno = $ferror(bfd, result);\n            ^~~~~~~\n%Error: data/full_repos/permissive/143278/ivltests/pr2800985a.v:273: Unsupported or unknown PLI call: $ferror\n    errno = $ferror(bfd, result);\n            ^~~~~~~\n%Error: data/full_repos/permissive/143278/ivltests/pr2800985a.v:279: Unsupported or unknown PLI call: $ferror\n    errno = $ferror(bfd, result);\n            ^~~~~~~\n%Error: data/full_repos/permissive/143278/ivltests/pr2800985a.v:285: Unsupported or unknown PLI call: $ferror\n    errno = $ferror(vfd, result);\n            ^~~~~~~\n%Error: data/full_repos/permissive/143278/ivltests/pr2800985a.v:296: Unsupported or unknown PLI call: $ferror\n    errno = $ferror(bfd, result);\n            ^~~~~~~\n%Error: data/full_repos/permissive/143278/ivltests/pr2800985a.v:302: Unsupported or unknown PLI call: $ferror\n    errno = $ferror(bfd, result);\n            ^~~~~~~\n%Error: data/full_repos/permissive/143278/ivltests/pr2800985a.v:312: Unsupported or unknown PLI call: $ferror\n    errno = $ferror(bfd, result);\n            ^~~~~~~\n%Error: data/full_repos/permissive/143278/ivltests/pr2800985a.v:317: Unsupported or unknown PLI call: $ferror\n    errno = $ferror(bfd, result);\n            ^~~~~~~\n%Error: data/full_repos/permissive/143278/ivltests/pr2800985a.v:328: Unsupported or unknown PLI call: $ferror\n    errno = $ferror(bfd, result);\n            ^~~~~~~\n%Error: data/full_repos/permissive/143278/ivltests/pr2800985a.v:334: Unsupported or unknown PLI call: $ferror\n    errno = $ferror(bfd, result);\n            ^~~~~~~\n%Error: data/full_repos/permissive/143278/ivltests/pr2800985a.v:367: Unsupported or unknown PLI call: $fstrobe\n    $fstrobe(vfd, "FAILED");\n    ^~~~~~~~\n%Error: data/full_repos/permissive/143278/ivltests/pr2800985a.v:371: Unsupported or unknown PLI call: $ferror\n      errno = $ferror(vfd, result);\n              ^~~~~~~\n%Error: data/full_repos/permissive/143278/ivltests/pr2800985a.v:377: Unsupported or unknown PLI call: $ferror\n      errno = $ferror(vfd, result);\n              ^~~~~~~\n%Error: Exiting due to 42 error(s)\n        ... See the manual and https://verilator.org for more assistance.\n'
module top;
  parameter work_file = "work/pr2800985.txt";
  reg pass;
  integer errno, bfd, vfd, mcd, res;
  reg [639:0] result, str;


  task check_error;
    begin

      if (errno == 0) begin
        $display("  FAILED: expected an error!");
        pass = 1'b0;
      end
      clear_error;
    end
  endtask

  task clear_error;
    begin

      res = $ftell(vfd);
      errno = $ferror(vfd, result);
      if (errno != 0) begin
        $display("Failed to clear error state (%0s)", result);
        $finish;
      end
    end
  endtask

  initial begin
    pass = 1'b1;
    vfd = $fopen(work_file, "w+");
    if (vfd == 0) begin
      errno = $ferror(vfd, result);
      $display("Failed to open required file %s (%0s).", work_file, result);
      $finish;
    end


    $display("Check a valid MCD.");
    errno = $ferror(1, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;


    $display("Opening a file that does not exist.");
    bfd = $fopen("FileDoesNotExist", "r");
    $display("  $fopen returned: %h", bfd);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;



    $display("Opening a directory we should not be able to write.");
    bfd = $fopen("/", "w");
    $display("  $fopen returned: %h", bfd);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;


    $display("Checking $fclose with fd 0 and -1.");
    bfd = 0;
    $fclose(bfd);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;
    bfd = -1;
    $fclose(bfd);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;


    $display("Checking $fdisplay with fd 0 and -1.");
    bfd = 0;
    $fdisplay(bfd);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;
    bfd = -1;
    $fdisplay(bfd);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;


    $display("Checking $fwrite with fd 0 and -1.");
    bfd = 0;
    $fwrite(bfd);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;
    bfd = -1;
    $fwrite(bfd);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;


    $display("Checking $fstrobe with fd 0 and -1.");
    bfd = 0;
    $fstrobe(bfd);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;
    bfd = -1;
    $fstrobe(bfd);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;


    $display("Checking $fgetc with fd 0 and -1.");
    bfd = 0;
    res = $fgetc(bfd);
    $display("  $fgetc returned: %0d", res);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;
    bfd = -1;
    res = $fgetc(bfd);
    $display("  $fgetc returned: %0d", res);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;



    $display("Checking $ungetc with fd 0 and -1 and char = EOF.");
    bfd = 0;
    res = $ungetc(0, bfd);
    $display("  $ungetc returned: %0d", res);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;
    bfd = -1;
    res = $ungetc(0, bfd);
    $display("  $ungetc returned: %0d", res);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;

    res = $ungetc(-1, vfd);
    $display("  $ungetc returned: %0d", res);
    errno = $ferror(vfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    if (res != -1 || errno != 0) begin
      $display("  Failed expected result (-1, 0), got (%0d, %0d).", res, errno);

      if (res != -1) pass = 1'b0;
      clear_error;
    end


    $display("Checking $fgets with fd 0 and -1.");
    bfd = 0;
    res = $fgets(str, bfd);
    $display("  $fgets returned: %0d, '%0s'", res, str);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;
    bfd = -1;
    res = $fgets(str, bfd);
    $display("  $fgets returned: %0d, '%0s'", res, str);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;


    $display("Checking $fscanf with fd 0 and -1.");
    bfd = 0;
    res = $fscanf(bfd, "%s", str);
    $display("  $fscanf returned: %0d, '%0s'", res, str);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;
    bfd = -1;
    res = $fscanf(bfd, "%s", str);
    $display("  $fscanf returned: %0d, '%0s'", res, str);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;


    $display("Checking $fread with fd 0 and -1.");
    bfd = 0;
    res = $fread(str, bfd);
    $display("  $fread returned: %0d, '%0s'", res, str);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;
    bfd = -1;
    res = $fread(str, bfd);
    $display("  $fread returned: %0d, '%0s'", res, str);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;


    $display("Checking $ftell with fd 0 and -1.");
    bfd = 0;
    res = $ftell(bfd);
    $display("  $ftell returned: %0d", res);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;
    bfd = -1;
    res = $ftell(bfd);
    $display("  $ftell returned: %0d", res);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;


    $display("Checking $fseek.");
    bfd = 0;
    res = $fseek(bfd, 0, 0);
    $display("  $fseek returned: %0d", res);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;
    bfd = -1;
    res = $fseek(bfd, 0, 0);
    $display("  $fseek returned: %0d", res);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;

    res = $fseek(vfd, 0, 4);
    $display("  $fseek returned: %0d", res);
    errno = $ferror(vfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;


    $display("Checking $rewind with fd 0 and -1.");
    bfd = 0;
    res = $rewind(bfd);
    $display("  $rewind returned: %0d", res);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;
    bfd = -1;
    res = $rewind(bfd);
    $display("  $rewind returned: %0d", res);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;


    $display("Checking $fflush with fd 0 and -1.");
    bfd = 0;
    $fflush(bfd);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;
    bfd = -1;
    $fflush(bfd);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;


    $display("Checking $feof with fd 0 and -1.");
    bfd = 0;
    res = $feof(bfd);
    $display("  $feof returned: %0d", res);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;
    bfd = -1;
    res = $feof(bfd);
    $display("  $feof returned: %0d", res);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;


`ifdef __ICARUS__
    $display("Checking $fputc with fd 0 and -1.");
    bfd = 0;
    res = $fputc(0, bfd);
    $display("  $fputc returned: %0d", res);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;
    bfd = -1;
    res = $fputc(0, bfd);
    $display("  $fputc returned: %0d", res);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;
`endif


    $display("Checking $fstrobe after $fclose.");
    res = $rewind(vfd);
    if (res != 0) begin
      $display("Failed to rewind file");
      $finish;
    end
    $fwrite(vfd, "test-");
    $fstrobe(vfd, "FAILED");
    $fclose(vfd);
    vfd = $fopen(work_file, "r");
    if (vfd == 0) begin
      errno = $ferror(vfd, result);
      $display("Failed to open required file %s (%0s).", work_file, result);
      $finish;
    end
    res = $fgets(str, vfd);
    if (res == 0) begin
      errno = $ferror(vfd, result);
      $display("Failed to read back result (%0s)", result);
      str = "failed";
    end
    if (str !== "test-") begin
      $display("$fstrobe was not skipped, expected 'test-', got '%0s'", str);
      pass = 1'b0;
    end
    $fclose(vfd);

    if (pass) $display("PASSED");
  end
endmodule
module top;

  parameter work_file = "work/pr2800985.txt";
  reg pass;
  integer errno, bfd, vfd, mcd, res;
  reg [639:0] result, str;


  task check_error;
    begin

      if (errno == 0) begin
        $display("  FAILED: expected an error!");
        pass = 1'b0;
      end
      clear_error;
    end
  endtask

  task clear_error;
    begin

      res = $ftell(vfd);
      errno = $ferror(vfd, result);
      if (errno != 0) begin
        $display("Failed to clear error state (%0s)", result);
        $finish;
      end
    end
  endtask

  initial begin
    pass = 1'b1;
    vfd = $fopen(work_file, "w+");
    if (vfd == 0) begin
      errno = $ferror(vfd, result);
      $display("Failed to open required file %s (%0s).", work_file, result);
      $finish;
    end


    $display("Check a valid MCD.");
    errno = $ferror(1, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;


    $display("Opening a file that does not exist.");
    bfd = $fopen("FileDoesNotExist", "r");
    $display("  $fopen returned: %h", bfd);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;



    $display("Opening a directory we should not be able to write.");
    bfd = $fopen("/", "w");
    $display("  $fopen returned: %h", bfd);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;


    $display("Checking $fclose with fd 0 and -1.");
    bfd = 0;
    $fclose(bfd);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;
    bfd = -1;
    $fclose(bfd);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;


    $display("Checking $fdisplay with fd 0 and -1.");
    bfd = 0;
    $fdisplay(bfd);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;
    bfd = -1;
    $fdisplay(bfd);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;


    $display("Checking $fwrite with fd 0 and -1.");
    bfd = 0;
    $fwrite(bfd);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;
    bfd = -1;
    $fwrite(bfd);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;


    $display("Checking $fstrobe with fd 0 and -1.");
    bfd = 0;
    $fstrobe(bfd);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;
    bfd = -1;
    $fstrobe(bfd);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;


    $display("Checking $fgetc with fd 0 and -1.");
    bfd = 0;
    res = $fgetc(bfd);
    $display("  $fgetc returned: %0d", res);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;
    bfd = -1;
    res = $fgetc(bfd);
    $display("  $fgetc returned: %0d", res);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;



    $display("Checking $ungetc with fd 0 and -1 and char = EOF.");
    bfd = 0;
    res = $ungetc(0, bfd);
    $display("  $ungetc returned: %0d", res);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;
    bfd = -1;
    res = $ungetc(0, bfd);
    $display("  $ungetc returned: %0d", res);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;

    res = $ungetc(-1, vfd);
    $display("  $ungetc returned: %0d", res);
    errno = $ferror(vfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    if (res != -1 || errno != 0) begin
      $display("  Failed expected result (-1, 0), got (%0d, %0d).", res, errno);

      if (res != -1) pass = 1'b0;
      clear_error;
    end


    $display("Checking $fgets with fd 0 and -1.");
    bfd = 0;
    res = $fgets(str, bfd);
    $display("  $fgets returned: %0d, '%0s'", res, str);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;
    bfd = -1;
    res = $fgets(str, bfd);
    $display("  $fgets returned: %0d, '%0s'", res, str);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;


    $display("Checking $fscanf with fd 0 and -1.");
    bfd = 0;
    res = $fscanf(bfd, "%s", str);
    $display("  $fscanf returned: %0d, '%0s'", res, str);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;
    bfd = -1;
    res = $fscanf(bfd, "%s", str);
    $display("  $fscanf returned: %0d, '%0s'", res, str);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;


    $display("Checking $fread with fd 0 and -1.");
    bfd = 0;
    res = $fread(str, bfd);
    $display("  $fread returned: %0d, '%0s'", res, str);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;
    bfd = -1;
    res = $fread(str, bfd);
    $display("  $fread returned: %0d, '%0s'", res, str);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;


    $display("Checking $ftell with fd 0 and -1.");
    bfd = 0;
    res = $ftell(bfd);
    $display("  $ftell returned: %0d", res);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;
    bfd = -1;
    res = $ftell(bfd);
    $display("  $ftell returned: %0d", res);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;


    $display("Checking $fseek.");
    bfd = 0;
    res = $fseek(bfd, 0, 0);
    $display("  $fseek returned: %0d", res);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;
    bfd = -1;
    res = $fseek(bfd, 0, 0);
    $display("  $fseek returned: %0d", res);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;

    res = $fseek(vfd, 0, 4);
    $display("  $fseek returned: %0d", res);
    errno = $ferror(vfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;


    $display("Checking $rewind with fd 0 and -1.");
    bfd = 0;
    res = $rewind(bfd);
    $display("  $rewind returned: %0d", res);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;
    bfd = -1;
    res = $rewind(bfd);
    $display("  $rewind returned: %0d", res);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;


    $display("Checking $fflush with fd 0 and -1.");
    bfd = 0;
    $fflush(bfd);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;
    bfd = -1;
    $fflush(bfd);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;


    $display("Checking $feof with fd 0 and -1.");
    bfd = 0;
    res = $feof(bfd);
    $display("  $feof returned: %0d", res);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;
    bfd = -1;
    res = $feof(bfd);
    $display("  $feof returned: %0d", res);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;


`ifdef __ICARUS__
    $display("Checking $fputc with fd 0 and -1.");
    bfd = 0;
    res = $fputc(0, bfd);
    $display("  $fputc returned: %0d", res);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;
    bfd = -1;
    res = $fputc(0, bfd);
    $display("  $fputc returned: %0d", res);
    errno = $ferror(bfd, result);
    $display("  $ferror returned: %0d, '%0s'", errno, result);
    check_error;
`endif


    $display("Checking $fstrobe after $fclose.");
    res = $rewind(vfd);
    if (res != 0) begin
      $display("Failed to rewind file");
      $finish;
    end
    $fwrite(vfd, "test-");
    $fstrobe(vfd, "FAILED");
    $fclose(vfd);
    vfd = $fopen(work_file, "r");
    if (vfd == 0) begin
      errno = $ferror(vfd, result);
      $display("Failed to open required file %s (%0s).", work_file, result);
      $finish;
    end
    res = $fgets(str, vfd);
    if (res == 0) begin
      errno = $ferror(vfd, result);
      $display("Failed to read back result (%0s)", result);
      str = "failed";
    end
    if (str !== "test-") begin
      $display("$fstrobe was not skipped, expected 'test-', got '%0s'", str);
      pass = 1'b0;
    end
    $fclose(vfd);

    if (pass) $display("PASSED");
  end
endmodule