{"thread":{"id":"9148","subject":"[PATCH 1/3] Add is_absolute_path() and make_absolute_path() functions","startedAt":"2007-07-22T18:55:54Z","lastAt":"2007-07-22T18:55:54Z","messageCount":1,"participants":["Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"48162","messageId":"Pine.LNX.4.64.0707221955280.14781@racer.site","threadId":"9148","inReplyTo":null,"subject":"[PATCH 1/3] Add is_absolute_path() and make_absolute_path() functions","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-07-22T18:55:54Z","receivedAt":"2007-07-22T18:55:54Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\nThis patch adds convenience functions to work with absolute paths.\nThe function is_absolute_path() should help the efforts to integrate\nthe MinGW fork.\n\nNote that make_absolute_path() returns a pointer to a static buffer.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n\tI am in the middle of so many things, otherwise I would have\n\ttried to find all places that can use these functions.  But\n\tmaybe a helpful soul out there wants to do that?\n\n cache.h |    5 +++++\n path.c  |   18 ++++++++++++++++++\n 2 files changed, 23 insertions(+), 0 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex 53801b8..98af530 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -358,6 +358,11 @@ int git_config_perm(const char *var, const char *value);\n int adjust_shared_perm(const char *path);\n int safe_create_leading_directories(char *path);\n char *enter_repo(char *path, int strict);\n+static inline int is_absolute_path(const char *path)\n+{\n+\treturn path[0] == '/';\n+}\n+const char *make_absolute_path(const char *path);\n \n /* Read and unpack a sha1 file into memory, write memory to a sha1 file */\n extern int sha1_object_info(const unsigned char *, unsigned long *);\ndiff --git a/path.c b/path.c\nindex c4ce962..b5b1959 100644\n--- a/path.c\n+++ b/path.c\n@@ -292,3 +292,21 @@ int adjust_shared_perm(const char *path)\n \t\treturn -2;\n \treturn 0;\n }\n+\n+const char *make_absolute_path(const char *path)\n+{\n+\tstatic char buf[PATH_MAX];\n+\tconst int size = sizeof(buf);\n+\tint len;\n+\n+\tif (is_absolute_path(path))\n+\t\treturn path;\n+\n+\tif (!getcwd(buf, size))\n+\t\tdie (\"Could not get current working directory\");\n+\tlen = strlen(buf);\n+\tif (snprintf(buf + len, size - len, \"/%s\", path) > size - 1)\n+\t\tdie (\"Could not make absolute path from '%s'\", path);\n+\treturn buf;\n+}\n+\n-- \n1.5.3.rc2.29.gc4640f\n"}]}