473,795 Members | 2,630 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

illegal seek

this code gives an "illegal seek error" on close() call
what is this error and when does it come?

main()
{
int fd,num;
char buf[150];
fd = open ("123.c",O_RDWR );
if(fd!=-1)
{

printf("a file with fd=%d is opened\n",fd);
num=read(fd,buf ,150);
printf("num=%d\ nREAD:%s",num,b uf);
perror("READ");
close(fd);
perror("CLOSE") ;
}
}
Jun 27 '08
22 7278
Joachim Schmitz wrote:
>
.... snip ...
>
close() sets errno if (and only if) it fails, which it indicates
by returning -1.
The following is a legal definition of close:

int close(int parm) {
if (-1 == parm) parm++;
return parm;
}

which doesn't meet your description. The point is that close is
undefined in standard C. In this newsgroup the discussion stops
there.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home .att.net>
Try the download section.

** Posted from http://www.teranews.com **
Jun 27 '08 #11
CBFalconer said:
Richard Tobin wrote:
>CBFalconer <cb********@mai neline.netwrote :
>>Who knows. There are no such functions as 'open', 'read', 'close'
in standard C.

As it turns out, it's nothing to do with those functions.

Since it is not written in C,
It sure looks like C to me.
who knows what is wrong with it.
comp.unix.progr ammer knows what's wrong with it.

--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Jun 27 '08 #12
On 14 May 2008 12:10:58 GMT, ri*****@cogsci. ed.ac.uk (Richard Tobin)
wrote in comp.lang.c:
In article <79************ *************** *******@a70g200 0hsh.googlegrou ps.com>,
Szabolcs Borsanyi <bo******@thphy s.uni-heidelberg.dewr ote:
By the way, the read/open/close functions are not standard library
functions.
So nothing is known about them. I don't quite remember the posix
specifications,
but I am not sure if errno can put to a positive value on success.

The use of those functions is irrelevant to the perror() problem.
The following program exhibits the same behavious on Linux:

#include <stdio.h>

int main(void)
{
perror("one");
perror("two");
return 0;
}

When I run it here it prints

one: Success
two: Illegal seek
In that case, the problem is system-specific, and he should take it up
with the Linux developers. It is a QOI issue, at best, since the
standard allows perror() to modify errno so long as it uses the
original value to produce output before modifying it.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
Jun 27 '08 #13
On 14 May 2008 at 16:39, CBFalconer wrote:
The following is a legal definition of close:

int close(int parm) {
if (-1 == parm) parm++;
return parm;
}
Wrong. It fails to meet the specification for close():

"The close() function shall deallocate the file descriptor indicated
by fildes. To deallocate means to make the file descriptor available for
return by subsequent calls to open() or other functions that allocate
file descriptors. All outstanding record locks owned by the process on
the file associated with the file descriptor shall be removed (that is,
unlocked)."

Jun 27 '08 #14
Antoninus Twink wrote:
On 14 May 2008 at 16:39, CBFalconer wrote:
>The following is a legal definition of close:

int close(int parm) {
if (-1 == parm) parm++;
return parm;
}

Wrong. It fails to meet the specification for close():

"The close() function shall deallocate the file descriptor indicated
by fildes. To deallocate means to make the file descriptor available
for return by subsequent calls to open() or other functions that
allocate file descriptors. All outstanding record locks owned by the
process on the file associated with the file descriptor shall be
removed (that is, unlocked)."
Guess you missed his point: close() is not in the C-Standard, hence there is
no specification.
Chuck simply ignores that close() exists in POSIX and is available to the
vast majority of implementations . He also ignored the fact that the OP did
use close() and that the most likely reason is that this is because it is
provided by his implementation.

Bye, Jojo
Jun 27 '08 #15
Joachim Schmitz wrote:
Antoninus Twink wrote:
>CBFalconer wrote:
>>The following is a legal definition of close:

int close(int parm) {
if (-1 == parm) parm++;
return parm;
}

Wrong. It fails to meet the specification for close():
.... snip posix? definition ...
>
Guess you missed his point: close() is not in the C-Standard,
hence there is no specification. Chuck simply ignores that
close() exists in POSIX and is available to the vast majority
of implementations . He also ignored the fact that the OP did
use close() and that the most likely reason is that this is
because it is provided by his implementation.
Of course the Twink-troll also snipped my explanation, which
follows below:
>>which doesn't meet your description. The point is that
close is undefined in standard C. In this newsgroup the
discussion stops there.
which is part of the trolls standard mechanism, aiming to disturb
the normal operation of the newsgroup. I see no reason to ever use
open, close and read, when fopen, fclose and fread are available
everywhere, and portable.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home .att.net>
Try the download section.
** Posted from http://www.teranews.com **
Jun 27 '08 #16
On May 16, 7:39*am, "Joachim Schmitz" <nospam.j...@sc hmitz-digital.de>
wrote:
Antoninus Twink wrote:
On 14 May 2008 at 16:39, CBFalconer wrote:
The following is a legal definition of close:
* *int close(int parm) {
* * * if (-1 == parm) parm++;
* * * return parm;
* *}
Wrong. It fails to meet the specification for close():
"The close() function shall deallocate the file descriptor indicated
by fildes. To deallocate means to make the file descriptor available
for return by subsequent calls to open() or other functions that
allocate file descriptors. All outstanding record locks owned by the
process on the file associated with the file descriptor shall be
removed (that is, unlocked)."

Guess you missed his point: close() is not in the C-Standard, hence there is
no specification.
Chuck simply ignores that close() exists in POSIX and is available to the
vast majority of implementations .
but not all. Since when was Posix on-topic to comp.lang.c
He also ignored the fact that the OP did
use close() and that the most likely reason is that this is because it is
provided by his implementation.
I'm pretty sure I've created a function called close() that
didn't match the Posix spec. (I'll not argue it was a
really good idea)

--
Nick Keighley
Jun 27 '08 #17
On 16 May 2008 at 18:00, Walter Roberson wrote:
In every extension I can currently think of that supports
the operations listed, open(), close() and read() are unnecessary
for any of the listed operations: those operations work on file
descriptors, and one can determine a FILE's file descriptor using
the fileno() extension upon a file that one has fopen()'d.
Are you saying that to create a file with 640 permissions you would use
fopen+fileno+fc ntl rather than just open()?

Jun 27 '08 #18
In article <sl************ *******@nospam. invalid>,
Antoninus Twink <no****@nospam. invalidwrote:
>On 16 May 2008 at 18:00, Walter Roberson wrote:
>In every extension I can currently think of that supports
the operations listed, open(), close() and read() are unnecessary
for any of the listed operations: those operations work on file
descriptors, and one can determine a FILE's file descriptor using
the fileno() extension upon a file that one has fopen()'d.
>Are you saying that to create a file with 640 permissions you would use
fopen+fileno+f cntl rather than just open()?
fopen() followed by the fchmod() extension would do fine in situations
where race conditions were not an issue. (Your listed operation
was "work with" permissions, not the more difficult task of
handling files securely.)
--
"Pray do not take the pains / To set me right. /
In vain my faults ye quote; / I wrote as others wrote /
On Sunium's hight." -- Walter Savage Landor
Jun 27 '08 #19
Walter Roberson wrote:
In article <sl************ *******@nospam. invalid>,
Antoninus Twink <no****@nospam. invalidwrote:
>On 16 May 2008 at 10:25, CBFalconer wrote:
>>I see no reason to ever use open, close and read, when fopen, fclose
and fread are available everywhere, and portable.
>Here are the first few that spring to mind:
>* to be able to work with file permissions and ownership
* getting file information with fstat (e.g. the size of a file)
* locking files with fcntl or flock
* getting file change notifications with fcntl
* to be able to send ioctls to devices

Those all involve extensions beyond the perview of C itself, and
are best discussed in a newsgroup that deals with the scope of the
extensions required (e.g., POSIX is going to have different behaviours
than Linux or MS Windows.)

In every extension I can currently think of that supports
the operations listed, open(), close() and read() are unnecessary
for any of the listed operations: those operations work on file
descriptors, and one can determine a FILE's file descriptor using
the fileno() extension upon a file that one has fopen()'d.
And if there are OS's that support file descriptors but do not
offer fileno() but still offer the listed operations, then such
OSs would certainly not be operating in any standardized way, which
would make it even more important to discuss the details in
an appropriate newsgroup rather than here.

You snipped one part of the answer of Mr Twink:

You have no interest in any program more
complicated than a solution to one of the exercises in K&R. You have an
arrogant disdain for people who dirty their hands with real-world
programming, when they might come across good reasons to use open, close
and read.

Why would you need to use fileno each time when you just
use open/close etc and be done with it?

You gave no valid reason.
--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
Jun 27 '08 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4218
by: Waitman Gobble | last post by:
Hello, I am new to Python. I am having trouble with zipfile.py. On a Linux machine with python 2.4.2 I have trouble opening a zipfile. Python is complaining about the bit where it does a seek(-22,2). Looks to me like zipfile.py is trying to come back 22 bytes from the end of file. # python
0
314
by: Felix Finch | last post by:
I have a perl test program which has about 80 test cases, each of which creates its own schema so I can remove them with DROP SCHEMA xxx CASCADE. Normally each test case creates and drops the same schema, but it can run a mode to preserve each schema and all the disk files for each test. I recently changed my cleanup code to run psql with all -c commands on one command line rather than a separate psql -c for each one ... psql -c 'DROP...
59
7524
by: Rico | last post by:
Hello, I have an application that I'm converting to Access 2003 and SQL Server 2005 Express. The application uses extensive use of DAO and the SEEK method on indexes. I'm having an issue when the recordset opens a table. When I write Set rst = db.OpenRecordset("MyTable",dbOpenTable, dbReadOnly) I get an error. I believe it's invalid operation or invalid parameter, I'm
4
6916
by: Vlad | last post by:
I am having problems using the file.create method within a function that is called when looping through an array of filepaths. If I call my function with a hardcoded file path --C:\Temp.txt the function creates the file as expected. When I loop through my array I get the error - "ArgumentException was unhandled - Illegal characters in path" The value "C:\Temp.txt" is the first value in the array - as it works
0
9672
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9519
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10001
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7540
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6780
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5437
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3727
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.