LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-02-2013, 02:38 AM   #1
ofer4
Member
 
Registered: Apr 2012
Posts: 100

Rep: Reputation: Disabled
Iseek c or c++


hi

i forgot to mention that i execute this code in unix

how iseek function work?

for example, if i execute this code:

read(fd,BUFFER,1024)
ISEEK(fd,1024,SEEK_SET)
read(fd,BUFFER,1024)
ISEEK(fd,1024,SEEK_SET)
read(fd,BUFFER,1024)

which byte i will read in the second read func?

the start byte will be 1024? or the start byte will be 2048?


and also in the third read func: i will read the 2048 byte? or 3056 byte or the 1024 byte?



thanks alot

Last edited by ofer4; 02-02-2013 at 02:51 AM.
 
Old 02-02-2013, 06:21 AM   #2
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,600

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
Assuming ISEEK is a macro invoking lseek, using SEEK_SET sets the pointer to 1024 (0 offset), so byte 1024 will be the one read in both cases.
 
Old 02-02-2013, 06:38 AM   #3
ofer4
Member
 
Registered: Apr 2012
Posts: 100

Original Poster
Rep: Reputation: Disabled
ok thanks you!
 
Old 02-02-2013, 10:20 AM   #4
ofer4
Member
 
Registered: Apr 2012
Posts: 100

Original Poster
Rep: Reputation: Disabled
hi

there is something that i still dont sure about it:

the SEEK_SET flag is takes me to the absolute offset relativly from the start of of the file? or relatively from the last iseek? or relatively from the last read?

can someone give me detal explanation?

i will be happy for examples too

thanks alot!
 
Old 02-02-2013, 10:31 AM   #5
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,600

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
From the manpage on lseek:

Code:
SEEK_SET
       The offset is set to offset bytes.

SEEK_CUR
       The offset is set to its current location plus offset bytes.

SEEK_END
       The offset is set to the size of the file plus offset bytes.

The lseek() function allows the file offset to be set beyond the end of
the file (but this does not change the size of the file).  If  data  is
later written at this point, subsequent reads of the data in the gap (a
"hole") return null bytes ('\0') until data is  actually  written  into
the gap.
 
Old 02-02-2013, 12:17 PM   #6
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181
Quote:
Originally Posted by ofer4 View Post
the SEEK_SET flag is takes me to the absolute offset relativly from the start of of the file?
Yes.

Quote:
or relatively from the last iseek? or relatively from the last read?
No.

Quote:
Originally Posted by jpollard View Post
From the manpage on lseek:
Code:
SEEK_SET
       The offset is set to offset bytes.
You and I know what that means, but it could look ambiguous to anyone asking the question ofer4 asked.

What does the word offset refer to (just the one I marked in red, not the other)?

If you don't understand that use of offset is implicitly relative to the start of the file, then that man page quote doesn't really answer ofer4's question.

Quote:
Originally Posted by jpollard View Post
Assuming ISEEK is a macro invoking lseek
You lost me on where that assumption comes from. After a quick google search, I still have no idea what ISEEK is. But if it really is equivalent to lseek, then the rest of what has been said here makes sense.

Quote:
Originally Posted by ofer4 View Post
Iseek c or c++
...
how iseek function work?
...
ISEEK(fd,1024,SEEK_SET)
Iseek is written three different ways in the first post. So maybe it is just an error and should have been lseek.

In some fonts it might be easy to misread lseek as Iseek, then if you are careless about upper/lower case you might get iseek or ISEEK.

Last edited by johnsfine; 02-02-2013 at 12:28 PM.
 
Old 02-02-2013, 01:30 PM   #7
ofer4
Member
 
Registered: Apr 2012
Posts: 100

Original Poster
Rep: Reputation: Disabled
thanks alot you both!

also, i am sorry, i meant "lseek"

thanks alot johnsfine for the detailed explanation!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off




All times are GMT -5. The time now is 12:18 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration