(root)/
gawk-5.2.2/
test/
makepmafile.c
       1  /*
       2   * makepmafile.c -- Create a small sparse file.
       3   */
       4  
       5  /*
       6   * Copyright (C) 2022, 2023,
       7   * the Free Software Foundation, Inc.
       8   *
       9   * This file is part of GAWK, the GNU implementation of the
      10   * AWK Programming Language.
      11   *
      12   * GAWK is free software; you can redistribute it and/or modify
      13   * it under the terms of the GNU General Public License as published by
      14   * the Free Software Foundation; either version 3 of the License, or
      15   * (at your option) any later version.
      16   *
      17   * GAWK is distributed in the hope that it will be useful,
      18   * but WITHOUT ANY WARRANTY; without even the implied warranty of
      19   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      20   * GNU General Public License for more details.
      21   *
      22   * You should have received a copy of the GNU General Public License
      23   * along with this program; if not, write to the Free Software
      24   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
      25   */
      26  
      27  #include <stdio.h>
      28  #include <errno.h>
      29  #include <string.h>
      30  #include <unistd.h>
      31  #include <stdlib.h>
      32  #include <sys/types.h>
      33  #include <sys/stat.h>
      34  #include <fcntl.h>
      35  
      36  int
      37  main(int argc, char **argv)
      38  {
      39  	size_t four_meg = 1024 * 1024 * 4;
      40  	char c = 0;
      41  	int fd = creat("test.pma", 0600);
      42  
      43  	if (fd < 0) {
      44  		fprintf(stderr, "%s: could not create test.pma: %s\n",
      45  				argv[0], strerror(errno));
      46  		exit(EXIT_FAILURE);
      47  	}
      48  
      49  	if (lseek(fd, four_meg - 1, SEEK_SET) < 0) {
      50  		fprintf(stderr, "%s: lseek failed: %s\n",
      51  				argv[0], strerror(errno));
      52  		exit(EXIT_FAILURE);
      53  	}
      54  
      55  	if (write(fd, &c, 1) < 0) {
      56  		fprintf(stderr, "%s: write failed: %s\n",
      57  				argv[0], strerror(errno));
      58  		exit(EXIT_FAILURE);
      59  	}
      60  
      61  	(void) close(fd);
      62  	return EXIT_SUCCESS;
      63  }