DragonFly users List (threaded) for 2008-06
DragonFly BSD
DragonFly users List (threaded) for 2008-06
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

lseek(2) problems


From: VOROSKOI Andras <voroskoi@xxxxxxxxx>
Date: Mon, 2 Jun 2008 01:36:32 +0200
Mail-followup-to: DragonFly users <users@lists.dragonflybsd.org>

Hi,

Today I've tried to send in Matt's gnulib patch to upstream with more of
less luck.
As for now http://www.haible.de/bruno/gnu/testdir-stdioext.tar.gz
compiles fine, but one of the test fails.

http://article.gmane.org/gmane.comp.lib.gnulib.bugs/13713
According to Bruno it's a bug in out lseek implementation and
http://www.opengroup.org/onlinepubs/000095399/functions/lseek.html
contains the following:

The POSIX.1-1990 standard did not specifically prohibit lseek() from
returning a negative offset. Therefore, an application was required to
clear errno prior to the call and check errno upon return to determine
whether a return value of ( off_t)-1 is a negative offset or an
indication of an error condition. The standard developers did not wish
to require this action on the part of a conforming application, and
chose to require that errno be set to [EINVAL] when the resulting file
offset would be negative for a regular file, block special file, or
directory.

You can download the testcase if you want, but I also attach a simple
testcase. Let me know what do you think about it.

-- 
voroskoi
#include <errno.h>
#include <stdio.h>
#include <unistd.h>

#define ASSERT(expr) \
  do                                                                         \
    {                                                                        \
      if (!(expr))                                                           \
        {                                                                    \
          fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
          fflush (stderr);                                                   \
          abort ();                                                          \
        }                                                                    \
    }                                                                        \
  while (0)

int main(void) {
	ASSERT (lseek (0, (off_t)-4, SEEK_CUR) == -1);
	ASSERT (errno == EINVAL);
	errno = 0;
	ASSERT (lseek (1, (off_t)-4, SEEK_CUR) == -1);
	ASSERT (errno == EINVAL);
	errno = 0;
}


[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]