Introduction
Introduction Statistics Contact Development Disclaimer Help
tfix path join '/' - stagit - static git page generator
git clone git://src.adamsgaard.dk/stagit
Log
Files
Refs
README
LICENSE
---
commit fc60d78d8917fb930227ecc53936c9216e6298c2
parent c13c4119501291e5c276d4d1217491b16a2a7ff9
Author: Hiltjo Posthuma <[email protected]>
Date: Sun, 1 May 2016 14:38:57 +0200
fix path join '/'
add joinpath() function to handle this.
Diffstat:
M stagit-index.c | 42 ++++++++++++++---------------…
M stagit.c | 39 ++++++++++++++---------------…
2 files changed, 37 insertions(+), 44 deletions(-)
---
diff --git a/stagit-index.c b/stagit-index.c
t@@ -140,13 +140,25 @@ err:
return ret;
}
+void
+joinpath(char *buf, size_t bufsiz, const char *path, const char *path2)
+{
+ int r;
+
+ r = snprintf(buf, bufsiz, "%s%s%s",
+ repodir, path[0] && path[strlen(path) - 1] != '/' ? "/" : "", …
+ if (r == -1 || (size_t)r >= bufsiz)
+ errx(1, "path truncated: '%s%s%s'",
+ path, path[0] && path[strlen(path) - 1] != '/' ? "/" :…
+}
+
int
main(int argc, char *argv[])
{
const git_error *e = NULL;
FILE *fp;
char path[PATH_MAX], repodirabs[PATH_MAX + 1];
- int i, r, ret = 0;
+ int i, ret = 0;
if (argc < 2) {
fprintf(stderr, "%s [repodir...]\n", argv[0]);
t@@ -176,20 +188,12 @@ main(int argc, char *argv[])
name = "";
/* read description or .git/description */
- description[0] = '\0';
- r = snprintf(path, sizeof(path), "%s%s%s",
- repodir, repodir[strlen(repodir)] == '/' ? "" : "/", "…
- if (r == -1 || (size_t)r >= sizeof(path))
- errx(1, "path truncated: '%s%s%s'",
- repodir, repodir[strlen(repodir)] == '/' ? "" …
+ joinpath(path, sizeof(path), repodir, "description");
if (!(fp = fopen(path, "r"))) {
- r = snprintf(path, sizeof(path), "%s%s%s",
- repodir, repodir[strlen(repodir)] == '/' ? "" …
- if (r == -1 || (size_t)r >= sizeof(path))
- errx(1, "path truncated: '%s%s%s'",
- repodir, repodir[strlen(repodir)] == '…
+ joinpath(path, sizeof(path), repodir, ".git/descriptio…
fp = fopen(path, "r");
}
+ description[0] = '\0';
if (fp) {
if (!fgets(description, sizeof(description), fp))
description[0] = '\0';
t@@ -197,20 +201,12 @@ main(int argc, char *argv[])
}
/* read owner or .git/owner */
- owner[0] = '\0';
- r = snprintf(path, sizeof(path), "%s%s%s",
- repodir, repodir[strlen(repodir)] == '/' ? "" : "/", "…
- if (r == -1 || (size_t)r >= sizeof(path))
- errx(1, "path truncated: '%s%s%s'",
- repodir, repodir[strlen(repodir)] == '/' ? "" …
+ joinpath(path, sizeof(path), repodir, "owner");
if (!(fp = fopen(path, "r"))) {
- r = snprintf(path, sizeof(path), "%s%s%s",
- repodir, repodir[strlen(repodir)] == '/' ? "" …
- if (r == -1 || (size_t)r >= sizeof(path))
- errx(1, "path truncated: '%s%s%s'",
- repodir, repodir[strlen(repodir)] == '…
+ joinpath(path, sizeof(path), repodir, ".git/owner");
fp = fopen(path, "r");
}
+ owner[0] = '\0';
if (fp) {
if (!fgets(owner, sizeof(owner), fp))
owner[0] = '\0';
diff --git a/stagit.c b/stagit.c
t@@ -970,6 +970,18 @@ err:
return 0;
}
+void
+joinpath(char *buf, size_t bufsiz, const char *path, const char *path2)
+{
+ int r;
+
+ r = snprintf(buf, bufsiz, "%s%s%s",
+ repodir, path[0] && path[strlen(path) - 1] != '/' ? "/" : "", …
+ if (r == -1 || (size_t)r >= bufsiz)
+ errx(1, "path truncated: '%s%s%s'",
+ path, path[0] && path[strlen(path) - 1] != '/' ? "/" :…
+}
+
int
main(int argc, char *argv[])
{
t@@ -978,13 +990,14 @@ main(int argc, char *argv[])
const git_error *e = NULL;
FILE *fp, *fpread;
char path[PATH_MAX], repodirabs[PATH_MAX + 1], *p;
- int r, status;
+ int status;
if (argc != 2) {
fprintf(stderr, "%s <repodir>\n", argv[0]);
return 1;
}
repodir = argv[1];
+
if (!realpath(repodir, repodirabs))
err(1, "realpath");
t@@ -1017,17 +1030,9 @@ main(int argc, char *argv[])
*p = '\0';
/* read description or .git/description */
- r = snprintf(path, sizeof(path), "%s%s%s",
- repodir, repodir[strlen(repodir)] == '/' ? "" : "/", "descript…
- if (r == -1 || (size_t)r >= sizeof(path))
- errx(1, "path truncated: '%s%s%s'",
- repodir, repodir[strlen(repodir)] == '/' ? "" : "/", "…
+ joinpath(path, sizeof(path), repodir, "description");
if (!(fpread = fopen(path, "r"))) {
- r = snprintf(path, sizeof(path), "%s%s%s",
- repodir, repodir[strlen(repodir)] == '/' ? "" : "/", "…
- if (r == -1 || (size_t)r >= sizeof(path))
- errx(1, "path truncated: '%s%s%s'",
- repodir, repodir[strlen(repodir)] == '/' ? "" …
+ joinpath(path, sizeof(path), repodir, ".git/description");
fpread = fopen(path, "r");
}
if (fpread) {
t@@ -1037,17 +1042,9 @@ main(int argc, char *argv[])
}
/* read url or .git/url */
- r = snprintf(path, sizeof(path), "%s%s%s",
- repodir, repodir[strlen(repodir)] == '/' ? "" : "/", "url");
- if (r == -1 || (size_t)r >= sizeof(path))
- errx(1, "path truncated: '%s%s%s'",
- repodir, repodir[strlen(repodir)] == '/' ? "" : "/", "…
+ joinpath(path, sizeof(path), repodir, "url");
if (!(fpread = fopen(path, "r"))) {
- r = snprintf(path, sizeof(path), "%s%s%s",
- repodir, repodir[strlen(repodir)] == '/' ? "" : "/", "…
- if (r == -1 || (size_t)r >= sizeof(path))
- errx(1, "path truncated: '%s%s%s'",
- repodir, repodir[strlen(repodir)] == '/' ? "" …
+ joinpath(path, sizeof(path), repodir, ".git/url");
fpread = fopen(path, "r");
}
if (fpread) {
You are viewing proxied material from mx1.adamsgaard.dk. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.