public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* lseek() returning Invalid Argument
@ 2009-09-15 22:45 gballey
  2009-09-15 23:08 ` Eric Blake
  0 siblings, 1 reply; 3+ messages in thread
From: gballey @ 2009-09-15 22:45 UTC (permalink / raw)
  To: cygwin

I'm getting an Invalid argument error from lseek(), but I can eliminate 
the error by preceding the lseek() statement with a particular printf() 
statement.

Configuration:
cygwin1.dll v1005.25.0.0
gcc v3.4.4
Windows XP SP3

Below is a short test program that illustrates the problem. As 
presented, the 2nd perror() statement is executed and prints the Invalid 
argument message (errno is 0). Removing the // from the printf() 
statement will cause the error to magically disappear.

I've tried substituting variations of printf() and sprintf() statements, 
as well as replacing the statement with a sleep(1) call, but at this 
point the only way to avoid the error is with the printf() statement shown.

Anyone got an idea of what is going on here?

Thanks.

/* begin test.c */

#include <fcntl.h>
#include <stdio.h>

static int mmfile ;

main(argc,argv)
int argc;
char *argv[];
{

	if ((mmfile = open("test.img", O_RDWR | O_CREAT, 0666)) == -1)
	{
		perror("open() error - ") ;
		exit(1) ;
	}

//	printf("mmfile=%d, length=%ld, where_at=%d\n", mmfile, 0x10000L, 
SEEK_SET) ;

	if (lseek(mmfile, 0x10000L, SEEK_SET) == -1)
	{
		perror("lseek() error - ") ;
		close(mmfile) ;
		exit(1) ;
	}
	close(mmfile) ;
         printf("ended successfully\n") ;
	exit(0) ;
}
/* end test.c */


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: lseek() returning Invalid Argument
  2009-09-15 22:45 lseek() returning Invalid Argument gballey
@ 2009-09-15 23:08 ` Eric Blake
  2009-09-15 23:58   ` gballey
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Blake @ 2009-09-15 23:08 UTC (permalink / raw)
  To: cygwin

gballey <galley <at> ace-co.com> writes:

> Anyone got an idea of what is going on here?

Yep.


Oh, you wanted to know what your bug is?

> 
> Thanks.
> 
> /* begin test.c */
> 
> #include <fcntl.h>
> #include <stdio.h>

Oops - no #include <unistd.h>.  lseek takes 64-bit type arguments, but without 
a declaration from the correct header, the compiler assumes it takes int 
arguments.  Try compiling with -Wall.

-- 
Eric Blake




--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: lseek() returning Invalid Argument
  2009-09-15 23:08 ` Eric Blake
@ 2009-09-15 23:58   ` gballey
  0 siblings, 0 replies; 3+ messages in thread
From: gballey @ 2009-09-15 23:58 UTC (permalink / raw)
  To: cygwin

Eric Blake wrote:
> gballey <galley <at> ace-co.com> writes:
> 
>> Anyone got an idea of what is going on here?
> 
> Yep.
> 
> 
> Oh, you wanted to know what your bug is?
> 
>> Thanks.
>>
>> /* begin test.c */
>>
>> #include <fcntl.h>
>> #include <stdio.h>
> 
> Oops - no #include <unistd.h>.  lseek takes 64-bit type arguments, but without 
> a declaration from the correct header, the compiler assumes it takes int 
> arguments.  Try compiling with -Wall.
> 

Yep, adding the header fixed it. I'm porting some apps that originated 
in Xenix years back, and that header wasn't included. I'm more 
accustomed to coding in languages with stronger type checking, and 
incorrectly assumed that when the compiler didn't complain, the types 
were OK.

I appreciate your assistance.

-Gordon


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-09-15 23:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-15 22:45 lseek() returning Invalid Argument gballey
2009-09-15 23:08 ` Eric Blake
2009-09-15 23:58   ` gballey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).