home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / utils.zip / bigfile.c < prev    next >
C/C++ Source or Header  |  2009-12-17  |  1KB  |  42 lines

  1. /*
  2.    bigfile.c - Make a big file that doesn't actually take up any disk space.
  3.    To build on 64-bit Linux: "make bigfile"
  4.    To build on 32-bit Linux: 
  5.    make bigfile "CFLAGS=-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"
  6.    To build on Solaris:  "make bigfile CFLAGS=-xarch=generic64"
  7.    F. da Cruz, Columbia University, 24 Dec 2005
  8. */
  9. #include <stdio.h>
  10. #include <sys/types.h>
  11. main() {
  12.     FILE * fp;
  13.     off_t offset;
  14.     offset = 3000000000LL;        /* > 2^31 */
  15.     offset = 4300000000LL;        /* > 2^32 */
  16.     if ((int)(sizeof(off_t)) < 8) {
  17.     printf("sizeof off_t is %d - can't make big files\n",
  18.            (int)(sizeof(off_t))
  19.            );
  20.     }
  21.     printf("sizeof off_t: %d\n", (int)(sizeof(off_t)));
  22.     /* Create the file */
  23.     if (!(fp = fopen("BIGFILE","w"))) {
  24.     perror("fopen BIGFILE\n");
  25.     exit(1);
  26.     }
  27.     /* Seek to a spot at the desired offset */
  28.     /* (This gets EINVAL errors on old Linux versions like RH6.1 */
  29.     /* even though off_t is 64 bits). */
  30.     if (fseeko(fp,offset,SEEK_SET) < 0) {
  31.     perror("fseeko");
  32.     exit(1);
  33.     }
  34.     /* Write one byte at the far end */
  35.     if (fputc('x',fp) == EOF) {
  36.     perror("fputc");
  37.     exit(1);
  38.     }
  39.     fclose(fp);
  40.     exit(0);
  41. }
  42.