Paul Eggert <[email protected]> writes:
>> is there a reason why savewd and
>> mkancesdirs don't use openat + mkdirat instead of using chdir in a child
>> process? Do these functions just predate the *at interfaces
>
> Yes, precisely. Some day it will be time to give up on those old
> platforms, I suppose. We haven't done that yet because there hasn't
> been motivation to get rid of them, or rewrite them.
I see. With this trivial test it seems that chdir is faster than open on
GNU/Linux:
$ cat main.c
#define _GNU_SOURCE 1
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
int
main (void)
{
for (int i = 0; i < 100000; ++i)
{
#ifdef DO_OPEN
int fd = open ("/", O_DIRECTORY | O_PATH);
if (fd < 0 || close (fd) < 0)
abort ();
#else
if (chdir ("/") < 0)
abort ();
#endif
}
return 0;
}
$ gcc main.c
$ perf stat --repeat 10 ./a.out 2>&1 | grep -F 'seconds time'
$ perf stat --repeat 10 ./a.out 2>&1 | grep -F 'seconds time'
0.08036 +- 0.00194 seconds time elapsed ( +- 2.41% )
$ gcc -DDO_OPEN main.c
$ perf stat --repeat 10 ./a.out 2>&1 | grep -F 'seconds time'
0.13929 +- 0.00102 seconds time elapsed ( +- 0.73% )
Collin