delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2014/03/27/21:30:06

X-Recipient: archive-cygwin AT delorie DOT com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:to:from:subject:date:message-id:mime-version
:content-type:content-transfer-encoding; q=dns; s=default; b=Zlj
rJ+Hbv6VQtrCwdYT5eX2o8fMfRUAMfjmj6Hqdq8S5pl4J9QAG35IrvfrjLiod3F+
fsgEUE+cC2NaKSysK57+vJ5mFmggQdaJ6tZ6AF6r26kNV/vgBDww5NVJALhP4cdS
iSZK+MNeWWTUCtIN6kFYsChSSkoRm44ZfOA3UPog=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:to:from:subject:date:message-id:mime-version
:content-type:content-transfer-encoding; s=default; bh=2i3WFtsXW
cxaZp/Fqo/YL0q0SJo=; b=tuhNm7uoUhK/dvJwZJ4ZmvdBRaAjXQb/0JdrUAgOK
h6mMow7pgEQomdsOagk7bWCxjCDcviQnF0YknbsJDrt84uJNBGlu7G4IWd8tRjD5
Y60OM3WQyzDp4lDTuChqLrUzllsXiDyHiXRUN4xQM2DNp4a1TqQZ22zWlWc8F+y7
Zk=
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Authentication-Results: sourceware.org; auth=none
X-Virus-Found: No
X-Spam-SWARE-Status: No, score=-1.5 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RP_MATCHES_RCVD,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2
X-HELO: plane.gmane.org
To: cygwin AT cygwin DOT com
From: Roy <roytam AT gmail DOT com>
Subject: open(O_RDWR) and lseek() fail
Date: Fri, 28 Mar 2014 09:29:29 +0800
Lines: 47
Message-ID: <op.xderrfffdyj81a@monster.itedn32a.localdomain>
Mime-Version: 1.0
User-Agent: Opera Mail/11.64 (Win32)
X-IsSubscribed: yes

Hello list,

I wonder why lseek(SEEK_CUR) on open(O_RDWR) fails with errno=22, the code  
works on Linux:

#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <fcntl.h>
int main(int argc, char** argv){
  int f,v1,v2;
  v1 = 1234;
  close(creat("1.bin", 0600));
  f = open("1.bin", O_RDWR);
  printf("wrote %d bytes.\n",write(f, (char *)&v1, sizeof(int)));
  printf("pos = %d\n",lseek(f, 0l, SEEK_CUR));
  printf("errno = %d\n",errno);
  printf("seek to beginning.\n");
  lseek(f, 0l, SEEK_SET);
  printf("errno = %d\n",errno);
  printf("read %d bytes.\n",read(f, (char *)&v2, sizeof(int)));
  printf("v2 = %d\n",v2);
  close(f);
}

On Linux it gives no error:
wrote 4 bytes.
pos = 4
errno = 0
seek to beginning.
errno = 0
read 4 bytes.
v2 = 1234

But not on cgywin(both 1.5 and 1.7 fails):
wrote 4 bytes.
pos = -1
errno = 22
seek to beginning.
errno = 22
read 0 bytes.
v2 = 2272412

Whats wrong with cygwin?

Regards,
Roy


--
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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019