Re: [PATCH 6/9] strbuf: reintroduce strbuf_parent_directory()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Stolee

On 01/11/2022 01:07, Derrick Stolee via GitGitGadget wrote:
+size_t strbuf_parent_directory(struct strbuf *buf)
+{
+	size_t len = buf->len;
+	size_t offset = offset_1st_component(buf->buf);
+	char *path_sep = find_last_dir_sep(buf->buf + offset);
+	strbuf_setlen(buf, path_sep ? path_sep - buf->buf : offset);
+	return len - buf->len;
+}
diff --git a/strbuf.h b/strbuf.h
index 76965a17d44..8a964a08c31 100644
--- a/strbuf.h
+++ b/strbuf.h
@@ -664,6 +664,13 @@ int launch_sequence_editor(const char *path, struct strbuf *buffer,
  int strbuf_edit_interactively(struct strbuf *buffer, const char *path,
  			      const char *const *env);
+/*
+ * Remove the deepest subdirectory in the provided path string. If path
+ * contains a trailing separator, then the path is considered a directory
+ * and nothing is modified.
+ */

I found the name and description a bit confusing, if I've understood correctly it isn't really removing the deepest subdirectory but removes the file name if there is one from the path. As such perhaps strbuf_strip_filename() might make it clearer that it is a no-op if the path ends with a slash. It returns the number of characters removed but that is undocumented.

Best Wishes

Phillip

+size_t strbuf_parent_directory(struct strbuf *buf);
+
  void strbuf_add_lines(struct strbuf *sb,
  		      const char *prefix,
  		      const char *buf,



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux