Blame gl/tests/test-binary-io.c

Packit aea12f
/* Test of binary mode I/O.
Packit Service 991b93
   Copyright (C) 2005, 2007-2020 Free Software Foundation, Inc.
Packit aea12f
Packit aea12f
   This program is free software: you can redistribute it and/or modify
Packit aea12f
   it under the terms of the GNU General Public License as published by
Packit aea12f
   the Free Software Foundation; either version 3 of the License, or
Packit aea12f
   (at your option) any later version.
Packit aea12f
Packit aea12f
   This program is distributed in the hope that it will be useful,
Packit aea12f
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit aea12f
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit aea12f
   GNU General Public License for more details.
Packit aea12f
Packit aea12f
   You should have received a copy of the GNU General Public License
Packit aea12f
   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
Packit aea12f
Packit aea12f
/* Written by Bruno Haible <bruno@clisp.org>, 2005.  */
Packit aea12f
Packit aea12f
#include <config.h>
Packit aea12f
Packit aea12f
#include "binary-io.h"
Packit aea12f
Packit aea12f
#include <sys/types.h>
Packit aea12f
#include <sys/stat.h>
Packit aea12f
#include <fcntl.h>
Packit aea12f
#include <stdio.h>
Packit aea12f
#include <stdlib.h>
Packit aea12f
#include <unistd.h>
Packit aea12f
Packit aea12f
#include "macros.h"
Packit aea12f
Packit aea12f
int
Packit aea12f
main (int argc, char *argv[])
Packit aea12f
{
Packit aea12f
  /* Test the O_BINARY macro.  */
Packit aea12f
  {
Packit aea12f
    int fd =
Packit aea12f
      open ("t-bin-out0.tmp", O_CREAT | O_TRUNC | O_RDWR | O_BINARY, 0600);
Packit aea12f
    if (write (fd, "Hello\n", 6) < 0)
Packit aea12f
      exit (1);
Packit aea12f
    close (fd);
Packit aea12f
  }
Packit aea12f
  {
Packit aea12f
    struct stat statbuf;
Packit aea12f
    if (stat ("t-bin-out0.tmp", &statbuf) < 0)
Packit aea12f
      exit (1);
Packit aea12f
    ASSERT (statbuf.st_size == 6);
Packit aea12f
  }
Packit aea12f
Packit aea12f
  switch (argv[1][0])
Packit aea12f
    {
Packit aea12f
    case '1':
Packit aea12f
      /* Test the set_binary_mode() function.  */
Packit aea12f
      set_binary_mode (1, O_BINARY);
Packit aea12f
      fputs ("Hello\n", stdout);
Packit aea12f
      break;
Packit aea12f
Packit aea12f
    default:
Packit aea12f
      break;
Packit aea12f
    }
Packit aea12f
Packit aea12f
  return 0;
Packit aea12f
}