home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / bcfamily / source / setfilei.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-12  |  1.4 KB  |  56 lines

  1. //
  2. //      *******************************************************************
  3. //        JdeBP C++ Library Routines          General Public Licence v1.00
  4. //            Copyright (c) 1991,1992     Jonathan de Boyne Pollard
  5. //      *******************************************************************
  6. //
  7. // Part of FamAPI.LIB
  8. //
  9.  
  10. #include "famapi.h"
  11. #include "dosdos.h"
  12.  
  13. //
  14. //    Query file's information
  15. //
  16. USHORT _APICALL
  17. DosSetFileInfo    ( unsigned short FileHandle,
  18.                   unsigned short InfoLevel,
  19.                   DOSFILESTATUS far *PtrFileStatus,
  20.                   unsigned short InfoBufferLength )
  21. {
  22.     USHORT err ;
  23.  
  24.     if (InfoLevel != 1) return ERROR_INVALID_FUNCTION ;
  25.  
  26.     if (InfoBufferLength < sizeof(DOSFILESTATUS))
  27.         return ERROR_BUFFER_OVERFLOW ;
  28.  
  29.     long oldpos, newend ;
  30.     USHORT done ;
  31.  
  32.     err = DosChgFilePtr(FileHandle, 0L, 1, &oldpos) ;        // SEEK_CUR
  33.  
  34.     if (err) return err ;
  35.  
  36.     DosChgFilePtr(FileHandle,
  37.                     PtrFileStatus->cbFile, 0, &newend) ;    // SEEK_SET
  38.     DosDosWrite(FileHandle, 0, 0, &done) ;                    // Truncate
  39.     DosChgFilePtr(FileHandle, oldpos, 0, &oldpos) ;            // SEEK_SET
  40.  
  41.     //
  42.     //    Do the file time AFTER the Truncation because on FAT filesystems
  43.     //    a truncate updates the timestamp !
  44.     //
  45.     err = DosDosSetFileTime (FileHandle,
  46.                             *(USHORT far *)&PtrFileStatus->fdateLastWrite,
  47.                             *(USHORT far *)&PtrFileStatus->ftimeLastWrite ) ;
  48.  
  49.     if (err) return err ;
  50.  
  51.     //
  52.     // We cannot set file attributes under DOS by file handle.
  53.     //
  54.     return NO_ERROR ;
  55. }
  56.