CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2003
    Location
    PA
    Posts
    58

    filelength of file descriptor?

    Im seeing g++ does not have a filelength function like Borland? So I wrote my own. My function always seems to return 5 greater than the value I need...
    Code:
    long filelength(int fd)
    {
        long pos = lseek(fd, 0, SEEK_CUR);
        long end = lseek(fd, 0, SEEK_END);
        lseek(fd, pos, SEEK_SET);
        return (end);
    }

  2. #2
    Join Date
    Mar 2004
    Location
    Israel
    Posts
    638
    -- deleted -- wrong code.
    Last edited by Guysl; April 28th, 2004 at 01:15 PM.
    **** **** **** **** **/**

  3. #3
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150
    Try something like:
    Code:
    long filelength(int fd)
    {
        long pos = tell(fd);
        lseek(fd, 0, SEEK_END);
        long end = tell(fd);
        lseek(fd, pos, SEEK_SET);
        return (end);
    }
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured