Microsoft KB Archive/47737

= INFO: filelength Includes EOF Character in Return Value =

Article ID: 47737

Article Last Modified on 12/12/2003

-

APPLIES TO

 The C Run-Time (CRT), when used with:  Microsoft Visual C++ 1.0 Professional Edition

 Microsoft Visual C++ 1.5 Professional Edition

 Microsoft Visual C++ 1.0 Professional Edition

 Microsoft Visual C++ 2.0 Professional Edition</li></ul>

 Microsoft Visual C++ 2.1</li></ul>

 Microsoft Visual C++ 4.0 Standard Edition</li></ul>

 Microsoft Visual C++ 5.0 Standard Edition</li></ul>

 Microsoft Visual C++ 6.0 Service Pack 5</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q47737

<div class="notice_section">

<div class="summary_section">

SUMMARY
The return value of the filelength function is the full length of the file in bytes, including any EOF characters. This return value will be the same as the file size indicated by the MS-DOS, OS/2, or Windows NT command prompt DIR command. The C Run-time included with Visual C++ version 4.0 provides not only the _filelength (filelength) function but also the Microsoft specific _filelengthi64 function. _filelengthi64 differs from filelength in its return type, a 64-bit int (__int64). For more information on _filelength or _filelengthi64, consult the Visual C++ Books Online.

The sample code below demonstrates the use of _filelength.

Sample Code
/* Compile options needed: none */ /* CHSIZE.C: This program uses _filelength to report the size * of a file before and after modifying it with _chsize. */


 * 1) include <io.h>
 * 2) include <fcntl.h>
 * 3) include <sys\types.h>
 * 4) include <sys\stat.h>
 * 5) include <stdio.h>

void main( void ) {  int fh, result; unsigned int nbytes = BUFSIZ;

/* Open a file */ if( (fh = _open( &quot;data&quot;, _O_RDWR | _O_CREAT, _S_IREAD                  | _S_IWRITE ))  != -1 ) {     printf( &quot;File length before: %ld\n&quot;, _filelength( fh ) ); if( ( result = _chsize( fh, 329678 ) ) == 0 ) printf( &quot;Size successfully changed\n&quot; ); else printf( &quot;Problem in changing the size\n&quot; ); printf( &quot;File length after: %ld\n&quot;, _filelength( fh ) ); _close( fh ); } }

Keywords: kbinfo kbcrt kbcode KB47737

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.