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

Re: ZSH performance regression in 5.8.1.2-test



> On 26 April 2022 at 15:31 "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?

We could use some variant of the following as a configure test for safety.
(Not sure if the socket test is comprehensive enough, but we must be
really into edge cases at that point.)  If we get the equivalent of

lseek on pipe failed
lseek on UNIX domain socket failed
lseek on regular file succeeded

presumably we're safe to use lseek as a test, and if we don't we can
decide whether to fall back to fstat or just leave unoptimised.

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