-static int
-cdb_append (struct cd_buf *cdb, char const *s, size_t len)
-{
- char const *end = cdb->buffer + sizeof cdb->buffer;
-
- /* Insert a slash separator if there is a preceding byte
- and it's not a slash. */
- bool need_slash = (cdb->buffer < cdb->avail && cdb->avail[-1] != '/');
- size_t n_free;
-
- if (sizeof cdb->buffer < len + 1)
- {
- /* This single component is too long. */
- errno = ENAMETOOLONG;
- return -1;
- }
-
- /* See if there's enough room for the `/', the new component and
- a trailing NUL. */
- n_free = end - cdb->avail;
- if (n_free < need_slash + len + 1)
- {
- if (cdb_flush (cdb) != 0)
- return -1;
- need_slash = false;
- }
-
- if (need_slash)
- *(cdb->avail)++ = '/';
-
- cdb->avail = mempcpy (cdb->avail, s, len);
- return 0;
-}
-
-/* This is a wrapper around chdir that works even on PATH_MAX-limited
- systems. It handles an arbitrarily long directory name by extracting
- and processing manageable portions of the name. On systems without
- the openat syscall, this means changing the working directory to
- more and more `distant' points along the long directory name and
- then restoring the working directory.
- If any of those attempts to change or restore the working directory
- fails, this function exits nonzero.
-
- Note that this function may still fail with errno == ENAMETOOLONG,
- but only if the specified directory name contains a component that
- is long enough to provoke such a failure all by itself (e.g. if the
- component is longer than PATH_MAX on systems that define PATH_MAX). */
+/* This is a function much like chdir, but without the PATH_MAX limitation
+ on the length of the directory name. A significant difference is that
+ it must be able to modify (albeit only temporarily) the directory
+ name. It handles an arbitrarily long directory name by operating
+ on manageable portions of the name. On systems without the openat
+ syscall, this means changing the working directory to more and more
+ `distant' points along the long directory name and then restoring
+ the working directory. If any of those attempts to save or restore
+ the working directory fails, this function exits nonzero.
+
+ Note that this function may still fail with errno == ENAMETOOLONG, but
+ only if the specified directory name contains a component that is long
+ enough to provoke such a failure all by itself (e.g. if the component
+ has length PATH_MAX or greater on systems that define PATH_MAX). */