summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2004-11-30 14:24:40 +0000
committerJim Meyering <jim@meyering.net>2004-11-30 14:24:40 +0000
commitd70691fc4b7183f812e2e325b5196b5afe7854c8 (patch)
treec3a12b4897eb737fe8be19a2891f714480a4a598 /lib
parentf76c6fa030e96c2e3cff52d730adfd10410b2575 (diff)
downloadcoreutils-d70691fc4b7183f812e2e325b5196b5afe7854c8.tar.xz
(O_DIRECTORY): Define, if necessary.
(memchrcspn): Tiny wrapper around memchr. (rpl_chdir): Use memchrcspn rather than strcspn.
Diffstat (limited to 'lib')
-rw-r--r--lib/chdir.c23
1 files changed, 20 insertions, 3 deletions
diff --git a/lib/chdir.c b/lib/chdir.c
index b531b10ec..e8ce730d5 100644
--- a/lib/chdir.c
+++ b/lib/chdir.c
@@ -37,6 +37,10 @@
#include "mempcpy.h"
#include "openat.h"
+#ifndef O_DIRECTORY
+# define O_DIRECTORY 0
+#endif
+
#ifndef MIN
# define MIN(a, b) ((a) < (b) ? (a) : (b))
#endif
@@ -71,6 +75,20 @@ struct cd_buf
int fd;
};
+/* Like memchr, but return the number of bytes from MEM
+ to the first occurrence of C thereafter. Search only
+ LEN bytes. Return LEN if C is not found. */
+static inline size_t
+memchrcspn (char const *mem, int c, size_t len)
+{
+ char const *found = memchr (mem, c, len);
+ if (!found)
+ return len;
+
+ len = found - mem;
+ return len;
+}
+
static void
cdb_init (struct cd_buf *cdb)
{
@@ -247,9 +265,8 @@ rpl_chdir (char const *dir)
break;
}
- /* FIXME: if performance of strcspn is an issue,
- use a little wrapper around memchr. */
- len = strcspn (start, "/");
+ len = memchrcspn (start, '/', dir_end - start);
+ assert (len == strcspn (start, "/"));
d = start + len;
if (cdb_append (&cdb, start, len) != 0)
goto Fail;