home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / MISC / SQDEV200.ZIP / SRC / SETFSIZE.C < prev    next >
C/C++ Source or Header  |  1994-05-23  |  3KB  |  87 lines

  1. /***************************************************************************
  2.  *                                                                         *
  3.  *  Squish Developers Kit Source, Version 2.00                             *
  4.  *  Copyright 1989-1994 by SCI Communications.  All rights reserved.       *
  5.  *                                                                         *
  6.  *  USE OF THIS FILE IS SUBJECT TO THE RESTRICTIONS CONTAINED IN THE       *
  7.  *  SQUISH DEVELOPERS KIT LICENSING AGREEMENT IN SQDEV.PRN.  IF YOU DO NOT *
  8.  *  FIND THE TEXT OF THIS AGREEMENT IN THE AFOREMENTIONED FILE, OR IF YOU  *
  9.  *  DO NOT HAVE THIS FILE, YOU SHOULD IMMEDIATELY CONTACT THE AUTHOR AT    *
  10.  *  ONE OF THE ADDRESSES LISTED BELOW.  IN NO EVENT SHOULD YOU PROCEED TO  *
  11.  *  USE THIS FILE WITHOUT HAVING ACCEPTED THE TERMS OF THE SQUISH          *
  12.  *  DEVELOPERS KIT LICENSING AGREEMENT, OR SUCH OTHER AGREEMENT AS YOU ARE *
  13.  *  ABLE TO REACH WITH THE AUTHOR.                                         *
  14.  *                                                                         *
  15.  *  You can contact the author at one of the address listed below:         *
  16.  *                                                                         *
  17.  *  Scott Dudley       FidoNet     1:249/106                               *
  18.  *  777 Downing St.    Internet    sjd@f106.n249.z1.fidonet.org            *
  19.  *  Kingston, Ont.     CompuServe  >INTERNET:sjd@f106.n249.z1.fidonet.org  *
  20.  *  Canada  K7M 5N3    BBS         1-613-634-3058, V.32bis                 *
  21.  *                                                                         *
  22.  ***************************************************************************/
  23.  
  24. /* name=Function to dynamically change the size of a file
  25. */
  26.  
  27. #include <dos.h>
  28. #include "prog.h"
  29.  
  30. #if defined(__MSDOS__)
  31.  
  32.   #include <stdio.h>
  33.   #include <stdlib.h>
  34.   #include <io.h>
  35.   #include <fcntl.h>
  36.  
  37.   int _fast setfsize(int fd, long size)
  38.   {
  39.     union REGS r;
  40.     long pos=tell(fd);
  41.  
  42.     lseek(fd, size, SEEK_SET);
  43.  
  44.   #ifdef __386__
  45.     r.h.ah=0x40;
  46.     r.x.ebx=fd;
  47.     r.x.ecx=0;
  48.     r.x.edx=0;
  49.  
  50.     int386(0x21, &r, &r);
  51.   #else
  52.     r.h.ah=0x40;
  53.     r.x.bx=fd;
  54.     r.x.cx=0;
  55.     r.x.dx=0;
  56.  
  57.     int86(0x21, &r, &r);
  58.   #endif
  59.  
  60.     lseek(fd, pos, SEEK_SET);
  61.  
  62.     return 0;
  63.   }
  64. #elif defined(OS_2)
  65.  
  66.   #define INCL_DOSFILEMGR
  67.   #include <os2.h>
  68.  
  69.   int _fast setfsize(int fd, long size)
  70.   {
  71.     return ((int)DosNewSize((HFILE)fd, (ULONG)size));
  72.   }
  73.  
  74. #elif defined(NT)
  75.  
  76.   #include "pwin.h"
  77.  
  78.   int _fast setfsize(int fd, long size)
  79.   {
  80.     SetFilePointer((HANDLE)fd, size, NULL, FILE_BEGIN);
  81.     return (!SetEndOfFile((HANDLE)fd));
  82.   }
  83. #else
  84.   #error Unknown OS
  85. #endif
  86.  
  87.