From: Johannes Schindelin <Johannes.Schindelin@gmx.de>
To: git@vger.kernel.org, gitster@pobox.com
Subject: [PATCH 1/3] Add is_absolute_path() and make_absolute_path() functions
Date: Sun, 22 Jul 2007 19:55:54 +0100 (BST) [thread overview]
Message-ID: <Pine.LNX.4.64.0707221955280.14781@racer.site> (raw)
This patch adds convenience functions to work with absolute paths.
The function is_absolute_path() should help the efforts to integrate
the MinGW fork.
Note that make_absolute_path() returns a pointer to a static buffer.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
I am in the middle of so many things, otherwise I would have
tried to find all places that can use these functions. But
maybe a helpful soul out there wants to do that?
cache.h | 5 +++++
path.c | 18 ++++++++++++++++++
2 files changed, 23 insertions(+), 0 deletions(-)
diff --git a/cache.h b/cache.h
index 53801b8..98af530 100644
--- a/cache.h
+++ b/cache.h
@@ -358,6 +358,11 @@ int git_config_perm(const char *var, const char *value);
int adjust_shared_perm(const char *path);
int safe_create_leading_directories(char *path);
char *enter_repo(char *path, int strict);
+static inline int is_absolute_path(const char *path)
+{
+ return path[0] == '/';
+}
+const char *make_absolute_path(const char *path);
/* Read and unpack a sha1 file into memory, write memory to a sha1 file */
extern int sha1_object_info(const unsigned char *, unsigned long *);
diff --git a/path.c b/path.c
index c4ce962..b5b1959 100644
--- a/path.c
+++ b/path.c
@@ -292,3 +292,21 @@ int adjust_shared_perm(const char *path)
return -2;
return 0;
}
+
+const char *make_absolute_path(const char *path)
+{
+ static char buf[PATH_MAX];
+ const int size = sizeof(buf);
+ int len;
+
+ if (is_absolute_path(path))
+ return path;
+
+ if (!getcwd(buf, size))
+ die ("Could not get current working directory");
+ len = strlen(buf);
+ if (snprintf(buf + len, size - len, "/%s", path) > size - 1)
+ die ("Could not make absolute path from '%s'", path);
+ return buf;
+}
+
--
1.5.3.rc2.29.gc4640f
reply other threads:[~2007-07-22 18:56 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Pine.LNX.4.64.0707221955280.14781@racer.site \
--to=johannes.schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).