File descriptor file position

This is a discussion on File descriptor file position within the Linux Programming forums, part of the Platform Specific Boards category; How do I get the current file position from a file descriptor? I don't see anything like ftell(), for file ...

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    96

    File descriptor file position

    How do I get the current file position from a file descriptor?

    I don't see anything like ftell(), for file descriptors.....

    Thanks!

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Use lseek(fd, 0, SEEK_CUR). lseek returns the position after the seek, so you get it by simply seeking 0 bytes from the current position.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Registered User
    Join Date
    Aug 2005
    Posts
    96
    Why didn't I think of that, must have not read the man page thoroughly....

    Thanks CornedBee.

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Actually, when I had the same problem a few months ago, I actually had to go into the libc source to find the implementation of ftell().
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 05:27 PM
  2. Need Help Fixing My C Program. Deals with File I/O
    By Matus in forum C Programming
    Replies: 7
    Last Post: 04-29-2008, 08:51 PM
  3. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05:02 AM
  4. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 04:30 PM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 02:58 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21