{* * @(#) set_flen.pas - Program for setting file length. * (c) 1994 Ivan Maidanski http://ivmai.chat.ru * Freeware program source. All rights reserved. ** * Language: Turbo Pascal * Tested with: Turbo Pascal v7.0 * Last modified: 1994-08-11 16:00:00 GMT+04:00 *} program Set_FLen; {$I-} {$M 2048,0,0} var F: File; var Len: LongInt; var Table: array[1..1024] of Byte; procedure Hello; begin WriteLn('Program for setting specified file length.'); WriteLn('Usage: SET_FLEN.EXE FileName FileSize'); Halt(1) end; procedure PrintErr(S: String); begin WriteLn(#13'Error: ',S,'!'); WriteLn; Halt(2) end; procedure TestErr; begin case IOResult of 0: ; 2: PrintErr('File not found'); 3: PrintErr('Path not found'); 4: PrintErr('Too many open files'); 5: PrintErr('File access denied'); 10: PrintErr('Invalid environment'); 11: PrintErr('Invalid format'); 150: PrintErr('Disk is write protected'); 152: PrintErr('Drive not ready'); 154: PrintErr('CRC error in data'); 156: PrintErr('Disk seek error'); 157: PrintErr('Unknown media type'); 158: PrintErr('Sector not found'); 162: PrintErr('Hardware failure'); else PrintErr('') end end; procedure Init; var Code: Integer; begin if ParamCount<>2 then Hello; Val(ParamStr(2),Len,Code); if (Code<>0) or (Len<0) then Hello; Assign(F,ParamStr(1)); Reset(F,1); TestErr end; procedure WriteZeros; begin FillChar(Table,SizeOf(Table),0); while Len-FilePos(F)>SizeOf(Table) do begin BlockWrite(F,Table,SizeOf(Table)); TestErr end; BlockWrite(F,Table,Len-FilePos(F)); TestErr end; procedure Run; var Pos: LongInt; begin Pos:=FileSize(F); Seek(F,Len); Truncate(F); TestErr; Seek(F,Pos); if Pos