Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: ZSH performance regression in 5.8.1.2-test



> On 27 April 2022 at 01:38 Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> On Tue, Apr 26, 2022 at 7:37 AM Jun. T <takimoto-j@xxxxxxxxxxxxxxxxx> wrote:
> >
> > But at least on my Mac the following seems to work also:
> >
> >     if (lseek(SHIN, 0, SEEK_CUR) == 0)
> >           rsize = SHINBUFSIZE;
> >
> > # Have you found a case in which lseek(SHIN, 0, SEEK_CUR) fails
> > # when it shouldn't fail, or does not fail when it should fail?
> 
> I was pretty sure I'd found a case (on Ubuntu 20.04) where it
> succeeded on a pipe when there was already data written to the pipe
> before the seek was attempted.  That was only/exactly for (0,
> SEEK_CUR).

A simple test for this still caused the seek on the type to fail
here, but I could be missing the  key elements.  Should still
be a safe test with only a few bytes in the pipe, I would think.

pws


#include <stdio.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/socket.h>

int main(int argc, char **argv)
{
    int pipefd[2], fd;
    if (pipe(pipefd) < 0)
    {
	printf("creating pipe failed\n");
    }
    else
    {
	char stuff[9] = "abcdefgh";
	write(pipefd[1], stuff, 8);
	if (lseek(pipefd[0], 0, SEEK_CUR) == (off_t)-1)
	{
	    printf("lseek on pipe failed\n");
	}
	else
	{
	    printf("lseek on pipe succeeded\n");
	}
    }
    close(pipefd[0]);
    close(pipefd[1]);

    fd = socket(AF_UNIX, SOCK_STREAM, 0);
    if (fd < 0)
    {
	printf("creating UNIX domain socket failed\n");
    }
    else if (lseek(fd, 0, SEEK_CUR) == (off_t)-1)
    {
	printf("lseek on UNIX domain socket failed\n");
    }
    else
    {
	printf("lseek on UNIX domain socket succeeded\n");
    }
    close(fd);

    fd = open("seekfiletest.tmp", O_CREAT);
    if (fd < 0)
    {
	printf("creating file failed\n");
    }
    else if (lseek(fd, 0, SEEK_CUR) == (off_t)-1)
    {
	printf("lseek on regular file failed\n");
    }
    else
    {
	printf("lseek on regular file succeeded\n");
    }
    close(fd);

    return 0;
}




Messages sorted by: Reverse Date, Date, Thread, Author