<commit_before>#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>

/* Carefully cat stdin to stdout.
 *
 * This uses small writes and handles EAGAIN from write by waiting a
 * bit and trying again.
 *
 * This program is used in Travis to work around this bug:
 *
 *    https://github.com/travis-ci/travis-ci/issues/4704
 */

void
main (void)
{
  char buffer[1024], *ptr;
  int n, m;

  while (1)
    {
      n = read (0, buffer, sizeof(buffer));
      if (n == 0)
        break;

      if (n < 0)
        {
          perror("read");
          exit (1);
        }

      ptr = buffer;
      while (n > 0)
        {
          m = write (1, ptr, n);
          if (m == 0)
            {
              fprintf(stderr, "write: closed\n");
              exit (1);
            }

          if (m < 0)
            {
              int err = errno;
              perror("write");
              if (err != EAGAIN)
                exit (1);
              sleep(1);
            }
          else
            {
              n -= m;
              ptr += m;
            }
        }
    }

  exit (0);
}<commit_msg>tools: Fix main() return value of careful-cat<commit_after>#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>

/* Carefully cat stdin to stdout.
 *
 * This uses small writes and handles EAGAIN from write by waiting a
 * bit and trying again.
 *
 * This program is used in Travis to work around this bug:
 *
 *    https://github.com/travis-ci/travis-ci/issues/4704
 */

int
main (void)
{
  char buffer[1024], *ptr;
  int n, m;

  while (1)
    {
      n = read (0, buffer, sizeof(buffer));
      if (n == 0)
        break;

      if (n < 0)
        {
          perror("read");
          return 1;
        }

      ptr = buffer;
      while (n > 0)
        {
          m = write (1, ptr, n);
          if (m == 0)
            {
              fprintf(stderr, "write: closed\n");
              return 1;
            }

          if (m < 0)
            {
              int err = errno;
              perror("write");
              if (err != EAGAIN)
                return 1;
              sleep(1);
            }
          else
            {
              n -= m;
              ptr += m;
            }
        }
    }

  return 0;
}
{'fraction_non_alphanumeric': 0.12724879333040806, 'fraction_numerical': 0.018429135585783237, 'mean_word_length': 1.167300380228137, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 13, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6112458', 'n_tokens_mistral': 765, 'n_tokens_neox': 725, 'n_words': 216}