ronantakizawa/codereview-bench huggingface dataset:
Repository: neovim/neovim
File: src/nvim/tui/tui.c (C)

Code before:
#define STARTS_WITH(str, prefix) \
  (strlen(str) >= (sizeof(prefix) - 1) \
   && 0 == memcmp((str), (prefix), sizeof(prefix) - 1))
#define TMUX_WRAP(is_tmux, seq) \
  ((is_tmux) ? "\x1bPtmux;\x1b" seq "\x1b\\" : seq)
#define LINUXSET0C "\x1b[?0c"
#define LINUXSET1C "\x1b[?1c"

#define UNIBI_SET_NUM_VAR(var, num) \
  do { \
    (var) = unibi_var_from_num((num)); \
  } while (0)
#define UNIBI_SET_STR_VAR(var, str) \
  do { \
    (var) = unibi_var_from_str((str)); \
  } while (0)

typedef struct {
  int top, bot, left, right;
} Rect;

struct TUIData {
  Loop *loop;
  unibi_var_t params[9];
  char buf[OUTBUF_SIZE];
  char *buf_to_flush;  ///< Non-null to flush this instead of buf[]
  size_t bufpos;
  TermInput input;
  uv_loop_t write_loop;
  unibi_term *ut;
  char *term;  ///< value of $TERM
  union {
    uv_tty_t tty;
    uv_pipe_t pipe;
  } output_handle;
  bool out_isatty;
  SignalWatcher winch_handle;
  uv_timer_t startup_delay_timer;
  UGrid grid;
  kvec_t(Rect) invalid_regions;
  int row, col;
  int out_fd;
  int pending_resize_events;
  bool can_change_scroll_region;
  bool has_left_and_right_margin_mode;
  bool can_set_lr_margin;  // smglr
  bool can_scroll;
  bool can_erase_chars;
  bool immediate_wrap_after_last_column;
  bool bce;
  bool mouse_enabled;

Review comment (suggestion):
this took me a few seconds to comprehend
```suggestion
  char *buf_to_flush;  ///< If non-null, flush this instead of buf[].
```

Code after:
#define STARTS_WITH(str, prefix) \
  (strlen(str) >= (sizeof(prefix) - 1) \
   && 0 == memcmp((str), (prefix), sizeof(prefix) - 1))
#define TMUX_WRAP(is_tmux, seq) \
  ((is_tmux) ? "\x1bPtmux;\x1b" seq "\x1b\\" : seq)
#define LINUXSET0C "\x1b[?0c"
#define LINUXSET1C "\x1b[?1c"

#define UNIBI_SET_NUM_VAR(var, num) \
  do { \
    (var) = unibi_var_from_num((num)); \
  } while (0)
#define UNIBI_SET_STR_VAR(var, str) \
  do { \
    (var) = unibi_var_from_str((str)); \
  } while (0)

typedef struct {
  int top, bot, left, right;
} Rect;

struct TUIData {
  Loop *loop;
  unibi_var_t params[9];
  char buf[OUTBUF_SIZE];
  char *buf_to_flush;  ///< If non-null, flush this instead of buf[].
  size_t bufpos;
  TermInput input;
  uv_loop_t write_loop;
  unibi_term *ut;
  char *term;  ///< value of $TERM
  union {
    uv_tty_t tty;
    uv_pipe_t pipe;
  } output_handle;
  bool out_isatty;
  SignalWatcher winch_handle;
  uv_timer_t startup_delay_timer;
  UGrid grid;
  kvec_t(Rect) invalid_regions;
  int row, col;
  int out_fd;
  int pending_resize_events;
  bool can_change_scroll_region;
  bool has_left_and_right_margin_mode;
  bool can_set_lr_margin;  // smglr
  bool can_scroll;
  bool can_erase_chars;
  bool immediate_wrap_after_last_column;
  bool bce;
  bool mouse_enabled;
Repository: neovim/neovim
File: src/nvim/ex_cmds.c (C)

Code before:
        && channel_job_running((uint64_t)buf->b_p_channel)) {
      no_write_message_nobang(buf);
      error++;
    } else if (!bufIsChanged(buf) || bt_dontwrite(buf)) {
      continue;
    }
    // Check if there is a reason the buffer cannot be written:
    // 1. if the 'write' option is set
    // 2. if there is no file name (even after browsing)
    // 3. if the 'readonly' is set (even after a dialog)
    // 4. if overwriting is allowed (even after a dialog)
    if (not_writing()) {
      error++;
      break;
    }
    if (buf->b_ffname == NULL) {
      semsg(_("E141: No file name for buffer %" PRId64), (int64_t)buf->b_fnum);
      error++;
    } else if (check_readonly(&eap->forceit, buf)
               || check_overwrite(eap, buf, buf->b_fname, buf->b_ffname, false) == FAIL) {
      error++;
    } else {
      bufref_T bufref;
      set_bufref(&bufref, buf);
      if (handle_mkdir_p_arg(eap, buf->b_fname) == FAIL
        || buf_write_all(buf, eap->forceit) == FAIL) {
        error++;
      }
      // An autocommand may have deleted the buffer.
      if (!bufref_valid(&bufref)) {
        buf = firstbuf;
      }
    }
    eap->forceit = save_forceit;          // check_overwrite() may set it
  }
  if (exiting) {
    if (!error) {
      getout(0);                // exit Vim
    }
    not_exiting();
  }
}

/// Check the 'write' option.
///
/// @return  true and give a message when it's not st.
static bool not_writing(void)
{
  if (p_write) {
    return false;
  }

Review comment (bug):
```suggestion
          || buf_write_all(buf, eap->forceit) == FAIL) {
```

Code after:
        && buf->terminal
        && channel_job_running((uint64_t)buf->b_p_channel)) {
      no_write_message_nobang(buf);
      error++;
    } else if (!bufIsChanged(buf) || bt_dontwrite(buf)) {
      continue;
    }
    // Check if there is a reason the buffer cannot be written:
    // 1. if the 'write' option is set
    // 2. if there is no file name (even after browsing)
    // 3. if the 'readonly' is set (even after a dialog)
    // 4. if overwriting is allowed (even after a dialog)
    if (not_writing()) {
      error++;
      break;
    }
    if (buf->b_ffname == NULL) {
      semsg(_("E141: No file name for buffer %" PRId64), (int64_t)buf->b_fnum);
      error++;
    } else if (check_readonly(&eap->forceit, buf)
               || check_overwrite(eap, buf, buf->b_fname, buf->b_ffname, false) == FAIL) {
      error++;
    } else {
      bufref_T bufref;
      set_bufref(&bufref, buf);
      if (handle_mkdir_p_arg(eap, buf->b_fname) == FAIL
          || buf_write_all(buf, eap->forceit) == FAIL) {
        error++;
      }
      // An autocommand may have deleted the buffer.
      if (!bufref_valid(&bufref)) {
        buf = firstbuf;
      }
    }
    eap->forceit = save_forceit;          // check_overwrite() may set it
  }
  if (exiting) {
    if (!error) {
      getout(0);                // exit Vim
    }
    not_exiting();
  }
}

/// Check the 'write' option.
///
/// @return  true and give a message when it's not st.
static bool not_writing(void)
{
  if (p_write) {
    return false;
Repository: neovim/neovim
File: src/nvim/ex_cmds.c (C)

Code before:
{
  if (eap->cmdidx == CMD_saveas) {
    // :saveas does not take a range, uses all lines.
    eap->line1 = 1;
    eap->line2 = curbuf->b_ml.ml_line_count;
  }

  if (eap->usefilter) {  // input lines to shell command
    do_bang(1, eap, false, true, false);
  } else {
    do_write(eap);
  }
}

#ifdef UNIX
static int check_writable(const char *fname)
{
  if (os_nodetype(fname) == NODE_OTHER) {
    semsg(_("E503: \"%s\" is not a file or writable device"), fname);
    return FAIL;
  }
  return OK;
}
#endif

static int handle_mkdir_p_arg(exarg_T *eap, char *fname) {
  if (eap->mkdir_p && os_file_mkdir(fname, 0755) < 0) {
    return FAIL;
  }

  return OK;
}

/// Write current buffer to file "eap->arg".
/// If "eap->append" is true, append to the file.
///
/// If "*eap->arg == NUL" write to current file.
///
/// @return  FAIL for failure, OK otherwise.
int do_write(exarg_T *eap)
{
  bool other;
  char *fname = NULL;            // init to shut up gcc
  int retval = FAIL;
  char *free_fname = NULL;
  buf_T *alt_buf = NULL;

  if (not_writing()) {          // check 'write' option
    return FAIL;
  }


Review comment (suggestion):
```suggestion
static int handle_mkdir_p_arg(exarg_T *eap, char *fname)
{
```

Code after:
{
  if (eap->cmdidx == CMD_saveas) {
    // :saveas does not take a range, uses all lines.
    eap->line1 = 1;
    eap->line2 = curbuf->b_ml.ml_line_count;
  }

  if (eap->usefilter) {  // input lines to shell command
    do_bang(1, eap, false, true, false);
  } else {
    do_write(eap);
  }
}

#ifdef UNIX
static int check_writable(const char *fname)
{
  if (os_nodetype(fname) == NODE_OTHER) {
    semsg(_("E503: \"%s\" is not a file or writable device"), fname);
    return FAIL;
  }
  return OK;
}
#endif

static int handle_mkdir_p_arg(exarg_T *eap, char *fname)
{
  if (eap->mkdir_p && os_file_mkdir(fname, 0755) < 0) {
    return FAIL;
  }

  return OK;
}

/// Write current buffer to file "eap->arg".
/// If "eap->append" is true, append to the file.
///
/// If "*eap->arg == NUL" write to current file.
///
/// @return  FAIL for failure, OK otherwise.
int do_write(exarg_T *eap)
{
  bool other;
  char *fname = NULL;            // init to shut up gcc
  int retval = FAIL;
  char *free_fname = NULL;
  buf_T *alt_buf = NULL;

  if (not_writing()) {          // check 'write' option
    return FAIL;
  }
Repository: neovim/neovim
File: test/functional/plugin/lsp/completion_spec.lua (Lua)

Code before:
      vim.o.completeopt = 'menuone,noselect'
    end)
    create_server('dummy', completion_list)
    feed('Sif true <C-X><C-O>')
    retry(nil, nil, function()
      eq(
        1,
        exec_lua(function()
          return vim.fn.pumvisible()
        end)
      )
    end)
    feed('<C-n><C-y>')
    eq(
      { false, { 'if true then', '\t', 'end' } },
      exec_lua(function()
        return {
          vim.snippet.active({ direction = 1 }),
          vim.api.nvim_buf_get_lines(0, 0, -1, true),
        }
      end)
    )
  end)
end)

describe('vim.lsp.completion: omnifunc', function()
  before_each(function()
    clear()
    exec_lua(create_server_definition)
    exec_lua(function()
      -- enable buffer and omnifunc autocompletion
      -- omnifunc will be the lsp omnifunc
      vim.o.complete = '.,o'
      vim.o.autocomplete = true
    end)
  end)

  it('merges with other completions', function()
    local completion_list = {
      isIncomplete = false,
      items = {
        { label = 'hallo' },
      },
    }
    create_server('dummy', completion_list)

    feed('ihello<cr><esc>ih')

    retry(nil, nil, function()
      local matches = vim.tbl_map(function(m)
        return m.word

Review comment (suggestion):
```suggestion
describe("vim.lsp.completion: omnifunc + 'autocomplete'", function()
```

Code after:
        },
      },
    }
    exec_lua(function()
      vim.o.completeopt = 'menuone,noselect'
    end)
    create_server('dummy', completion_list)
    feed('Sif true <C-X><C-O>')
    retry(nil, nil, function()
      eq(
        1,
        exec_lua(function()
          return vim.fn.pumvisible()
        end)
      )
    end)
    feed('<C-n><C-y>')
    eq(
      { false, { 'if true then', '\t', 'end' } },
      exec_lua(function()
        return {
          vim.snippet.active({ direction = 1 }),
          vim.api.nvim_buf_get_lines(0, 0, -1, true),
        }
      end)
    )
  end)
end)

describe("vim.lsp.completion: omnifunc + 'autocomplete'", function()
  before_each(function()
    clear()
    exec_lua(create_server_definition)
    exec_lua(function()
      -- enable buffer and omnifunc autocompletion
      -- omnifunc will be the lsp omnifunc
      vim.o.complete = '.,o'
      vim.o.autocomplete = true
    end)

    local completion_list = {
      isIncomplete = false,
      items = {
        { label = 'hello' },
        { label = 'hallo' },
      },
    }
    create_server('dummy', completion_list, { delay = 50 })
  end)

  local function assert_matches(expected)
Repository: neovim/neovim
File: test/functional/legacy/prompt_buffer_spec.lua (Lua)

Code before:
      other buffer             |
      % line1                  |
      line^2                    |
      {1:~                        }|*6
                               |
    ]])
    -- works on prompt
    api.nvim_win_set_cursor(0, { prompt_pos[1], 0 })
    screen:expect([[
      other buffer             |
      ^% line1                  |
      line2                    |
      {1:~                        }|*6
                               |
    ]])
    feed('a')
    feed('<esc>')
    screen:expect([[
      other buffer             |
      %^ line1                  |
      line2                    |
      {1:~                        }|*6
                               |
    ]])

    -- i_<Left> i_<C-Left> i_<Home> i_<End> keys on pormpt-line doesn't put cursor
    -- at end of text
    feed('a<Left><C-Left>')
    screen:expect([[
      other buffer             |
      % ^line1                  |
      line2                    |
      {1:~                        }|*6
      {5:-- INSERT --}             |
    ]])

    feed('<End>')
    screen:expect([[
      other buffer             |
      % line1^                  |
      line2                    |
      {1:~                        }|*6
      {5:-- INSERT --}             |
    ]])

    feed('<Home>')
    screen:expect([[
      other buffer             |
      % ^line1                  |
      line2                    |
      {1:~                        }|*6

Review comment (suggestion):
```suggestion
    -- i_<Left> i_<C-Left> i_<Home> i_<End> keys on prompt-line doesn't put cursor
```

Code after:
      other buffer             |
      %^ line1                  |
      line2                    |
      {1:~                        }|*6
                               |
    ]])
    -- works on prompt
    api.nvim_win_set_cursor(0, { prompt_pos[1], 0 })
    screen:expect([[
      other buffer             |
      ^% line1                  |
      line2                    |
      {1:~                        }|*6
                               |
    ]])
    feed('a')
    feed('<esc>')
    screen:expect([[
      other buffer             |
      %^ line1                  |
      line2                    |
      {1:~                        }|*6
                               |
    ]])

    -- i_<Left> i_<C-Left> i_<Home> i_<End> keys on prompt-line doesn't put cursor
    -- at end of text
    feed('a<Left><C-Left>')
    screen:expect([[
      other buffer             |
      % ^line1                  |
      line2                    |
      {1:~                        }|*6
      {5:-- INSERT --}             |
    ]])

    feed('<End>')
    screen:expect([[
      other buffer             |
      % line1^                  |
      line2                    |
      {1:~                        }|*6
      {5:-- INSERT --}             |
    ]])

    feed('<Home>')
    screen:expect([[
      other buffer             |
      % ^line1                  |
      line2                    |
      {1:~                        }|*6
Repository: neovim/neovim
File: runtime/plugin/nvim/net.lua (Lua)

Code before:
  if vim.fn.executable('curl') ~= 1 then
    vim.api.nvim_echo({
      { 'Warning: `curl` not found; remote URL loading disabled.', 'WarningMsg' },
    }, true, {})
    return true
  end

  local bufnr = args.buf
  local url = vim.api.nvim_buf_get_name(bufnr)
  local view = vim.fn.winsaveview()

  vim.api.nvim_echo({ { 'Fetching ' .. url .. ' …', 'MoreMsg' } }, true, {})

  vim.net.request(
    url,
    { retry = 3 },
    vim.schedule_wrap(function(err, content)
      if err then
        vim.notify('Failed to fetch ' .. url .. ': ' .. tostring(err), vim.log.levels.ERROR)
        vim.fn.winrestview(view)
        return
      end

      local lines = vim.split(content.body, '\n', { plain = true })
      vim.api.nvim_buf_set_lines(bufnr, 0, -1, true, lines)
      vim.api.nvim_exec_autocmds('BufRead', { group = 'filetypedetect', buffer = bufnr })

      vim.fn.winrestview(view)
      vim.api.nvim_echo({ { 'Loaded ' .. url, 'Normal' } }, true, {})
    end)
  )
end

vim.api.nvim_create_autocmd('BufReadCmd', {
  group = vim.api.nvim_create_augroup('nvim.net.remotefile', {}),
  pattern = { 'http://*', 'https://*' },
  desc = 'Edit remote files (:edit https://example.com)',
  callback = on_remote_read,
})


Review comment (suggestion):
`vim.cmd('filetype detect')` could be used here too, not sure what's best

Code after:
  if vim.fn.executable('curl') ~= 1 then
    vim.api.nvim_echo({
      { 'Warning: `curl` not found; remote URL loading disabled.', 'WarningMsg' },
    }, true, {})
    return true
  end

  local bufnr = args.buf
  local url = vim.api.nvim_buf_get_name(bufnr)
  local view = vim.fn.winsaveview()

  vim.api.nvim_echo({ { 'Fetching ' .. url .. ' …', 'MoreMsg' } }, true, {})

  vim.net.request(
    url,
    { retry = 3 },
    vim.schedule_wrap(function(err, content)
      if err then
        vim.notify('Failed to fetch ' .. url .. ': ' .. tostring(err), vim.log.levels.ERROR)
        vim.fn.winrestview(view)
        return
      end

      local lines = vim.split(content.body, '\n', { plain = true })
      vim.api.nvim_buf_set_lines(bufnr, 0, -1, true, lines)
      vim.api.nvim_exec_autocmds('BufRead', { group = 'filetypedetect', buffer = bufnr })
      vim.bo[bufnr].modified = false

      vim.fn.winrestview(view)
      vim.api.nvim_echo({ { 'Loaded ' .. url, 'Normal' } }, true, {})
    end)
  )
end

vim.api.nvim_create_autocmd('BufReadCmd', {
  group = vim.api.nvim_create_augroup('nvim.net.remotefile', {}),
  pattern = { 'http://*', 'https://*' },
  desc = 'Edit remote files (:edit https://example.com)',
  callback = on_remote_read,
})
Repository: neovim/neovim
File: test/functional/ui/messages2_spec.lua (Lua)

Code before:
    ]])
    feed('<CR>')
    screen:expect([[
      ^                                                     |
      {1:~                                                    }|*12
                                                           |
    ]])
  end)

  it('FileType is fired after default options are set', function()
    n.exec([[
      let g:optionset = 0
      au FileType pager set nowrap
      au OptionSet * let g:optionset += 1
      echom 'foo'->repeat(&columns)
      messages
    ]])
    screen:expect([[
                                                           |
      {1:~                                                    }|*9
      {3:─────────────────────────────────────────────────────}|
      ^foofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofo|
      {1:                                                     }|
                                                           |
    ]])
    t.eq(n.eval('g:optionset'), 4) -- still fires for 'filetype'
  end)
end)


Review comment (suggestion):
```suggestion
    t.eq(4, n.eval('g:optionset')) -- still fires for 'filetype'
```

Code after:
    ]])
    feed('<CR>')
    screen:expect([[
      ^                                                     |
      {1:~                                                    }|*12
                                                           |
    ]])
  end)

  it('FileType is fired after default options are set', function()
    n.exec([[
      let g:set = {}
      au FileType pager set nowrap
      au OptionSet * let g:set[expand('<amatch>')] = g:set->get(expand('<amatch>'), 0) + 1
      echom 'foo'->repeat(&columns)
      messages
    ]])
    screen:expect([[
                                                           |
      {1:~                                                    }|*9
      {3:─────────────────────────────────────────────────────}|
      ^foofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofo|
      {1:                                                     }|
                                                           |
    ]])
    t.eq({ filetype = 4 }, n.eval('g:set')) -- still fires for 'filetype'
  end)
end)
Repository: neovim/neovim
File: src/tee/tee.c (C)

Code before:
int
myfread(char *buf, int elsize /*ignored*/, int max, FILE *fp)
{
	int	c;
	int	n = 0;

	while ((n < max) && ((c = getchar()) != EOF))
	{
		*(buf++) = c;
		n++;
		if (c == '\n' || c == '\r')
			break;
	}
	return n;
}


int
main(int argc, char *argv[])
{
	int	append = 0;
	size_t	numfiles;
	int	maxfiles;
	FILE	**filepointers;
	int	i;
	char	buf[BUFSIZ];
	int	n;
	int	optind = 1;

	for (i = 1; i < argc; i++)
	{
		if (argv[i][0] != '-')
			break;
		if (!strcmp(argv[i], "-a"))
			append++;
		else
			usage();
		optind++;
	}

	numfiles = argc - optind;

	if (numfiles == 0)
	{
		fprintf(stderr, "doesn't make much sense using tee without any file name arguments...\n");
		usage();
		exit(2);
	}

	maxfiles = sysconf(_SC_OPEN_MAX);	/* or fill in 10 or so */
	if (maxfiles < 0)

Review comment (performance):
How big is BUFSIZ? Does changing this to something big, improve the performance?


```suggestion
	char	buf[65536];
```

Code after:
  int n;
  int optnr = 1;

  for (i = 1; i < argc; i++) {
    if (argv[i][0] != '-') {
      break;
    }
    if (!strcmp(argv[i], "-a")) {
      append++;
    } else {
      usage();
      exit(2);
    }
    optnr++;
  }

  numfiles = argc - optnr;

  if (numfiles == 0) {
    usage();
    exit(2);
  }

  maxfiles = sysconf(_SC_OPEN_MAX);       // or fill in 10 or so
  if (maxfiles < 0) {
    maxfiles = 10;
  }
  if (numfiles + 3 > maxfiles) {  // +3 accounts for stdin, out, err
    fprintf(stderr, "There is a limit of max %d files.\n", maxfiles - 3);
    exit(1);
  }
  filepointers = calloc(numfiles, sizeof(FILE *));  // NOLINT
  if (filepointers == NULL) {
    fprintf(stderr, "Error allocating memory for %ld files\n", (long)numfiles);
    exit(1);
  }
  for (i = 0; i < numfiles; i++) {
    filepointers[i] = fopen(argv[i + optnr], append ? "ab" : "wb");
    if (filepointers[i] == NULL) {
      fprintf(stderr, "Can't open \"%s\"\n", argv[i + optnr]);
      exit(1);
    }
  }
#ifdef _WIN32
  setmode(fileno(stdin),  O_BINARY);
  fflush(stdout);  // needed for _fsetmode(stdout)
  setmode(fileno(stdout),  O_BINARY);
  setvbuf(stdout, NULL, _IONBF, 0);  // unbuffered for immediate output
#endif

  while ((n = fread(buf, 1, sizeof(buf), stdin)) > 0) {
Repository: neovim/neovim
File: src/tee/tee.c (C)

Code before:
	fprintf(stderr,
"tee usage:\n\
\ttee [-a] file ... file_n\n\
\n\
\t-a\tappend to files instead of truncating\n\
\nTee reads its input, and writes to each of the specified files,\n\
as well as to the standard output.\n\
\n\
This version supplied with Vim 4.2 to make ':make' possible.\n\
For a more complete and stable version, consider getting\n\
[a port of] the GNU shellutils package.\n\
");
}

/*
 * fread only returns when count is read or at EOF.
 * We could use fgets, but I want to be able to handle binary blubber.
 */

int
myfread(char *buf, int elsize /*ignored*/, int max, FILE *fp)
{
	int	c;
	int	n = 0;

	while ((n < max) && ((c = getchar()) != EOF))
	{
		*(buf++) = c;
		n++;
		if (c == '\n' || c == '\r')
			break;
	}
	return n;
}


int
main(int argc, char *argv[])
{
	int	append = 0;
	size_t	numfiles;
	int	maxfiles;
	FILE	**filepointers;
	int	i;
	char	buf[BUFSIZ];
	int	n;
	int	optind = 1;

	for (i = 1; i < argc; i++)
	{
		if (argv[i][0] != '-')

Review comment (performance):
from chatgpt:

- getchar() reads one byte at a time using fully buffered stdio calls.
    - On Linux, this may still get internally buffered at a reasonable chunk size, so it’s not disastrous.
     - On Windows, especially when stdin is a pipe, each getchar() often results in a real system call (ReadFile of size 1) — that’s excruciatingly slow for large inputs.

suggested fix:

> Change myfread() to a real buffered read:

```c
int myfread(char *buf, int elsize, int max, FILE *fp)
{
    return fread(buf, elsize, max, fp);
}
```

and call it like this:

```c
while ((n = myfread(buf, 1, sizeof(buf), stdin)) > 0)
{
    fwrite(buf, 1, n, stdout);
    for (i = 0; i < numfiles; i++)
        if (filepointers[i]) fwrite(buf, 1, n, filepointers[i]);
}
```

Code after:
          "Usage:\n"
          "\ttee [-a] file ... file_n\n"
          "\n"
          "\t-a\tappend to files instead of truncating\n"
          "\n"
          "Tee reads its input, and writes to each of the specified files,\n"
          "as well as to the standard output.\n"
          "\n"
          "Shipped with Nvim 0.12+ for use with :make, :grep, :!, etc.\n");
}

int main(int argc, char *argv[])
{
  int append = 0;
  size_t numfiles;
  int maxfiles;
  FILE **filepointers;
  int i;
  char buf[65536];
  int n;
  int optnr = 1;

  for (i = 1; i < argc; i++) {
    if (argv[i][0] != '-') {
      break;
    }
    if (!strcmp(argv[i], "-a")) {
      append++;
    } else {
      usage();
      exit(2);
    }
    optnr++;
  }

  numfiles = argc - optnr;

  if (numfiles == 0) {
    usage();
    exit(2);
  }

  maxfiles = sysconf(_SC_OPEN_MAX);       // or fill in 10 or so
  if (maxfiles < 0) {
    maxfiles = 10;
  }
  if (numfiles + 3 > maxfiles) {  // +3 accounts for stdin, out, err
    fprintf(stderr, "There is a limit of max %d files.\n", maxfiles - 3);
    exit(1);
  }
  filepointers = calloc(numfiles, sizeof(FILE *));  // NOLINT