}
}
+/* Some implementations of dirname(3) return a pointer to a static
+ * internal buffer (OpenBSD). Others modify the contents of `path` (POSIX).
+ * This is a wrapper function that is compatible with both versions.
+ * The program will error out if dirname(3) failed, this can only happen
+ * with the OpenBSD version. */
+char *
+xdirname(const char *path)
+{
+ char *p, *b;
+
+ if (!(p = strdup(path)))
+ err(1, "strdup");
+ if (!(b = dirname(p)))
+ err(1, "basename");
+ if (!(b = strdup(b)))
+ err(1, "strdup");
+ free(p);
+
+ return b;
+}
+
/* Some implementations of basename(3) return a pointer to a static
* internal buffer (OpenBSD). Others modify the contents of `path` (POSIX).
* This is a wrapper function that is compatible with both versions.
git_oid id;
size_t i, m = 100; /* max */
- fputs("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n", fp);
- fputs("<feed xmlns=\"http://www.w3.org/2005/Atom\">\n<title>", fp);
+ fputs("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<feed xmlns=\"http://www.w3.org/2005/Atom\">\n<title>", fp);
xmlencode(fp, name, strlen(name));
fputs(", branch master</title>\n<subtitle>", fp);
{
char fpath[PATH_MAX];
char tmp[PATH_MAX] = "";
- char *p;
+ char *d, *p;
FILE *fp;
snprintf(fpath, sizeof(fpath), "file/%s.html", filename);
- if (mkdirp(dirname(fpath)))
+ d = xdirname(fpath);
+ if (mkdirp(d)) {
+ free(d);
return 1;
+ }
+ free(d);
p = fpath;
while (*p) {
return 0;
}
+const char *
+filemode(git_filemode_t m)
+{
+ static char mode[11];
+
+ memset(mode, '-', sizeof(mode) - 1);
+ mode[10] = '\0';
+
+ if (S_ISREG(m))
+ mode[0] = '-';
+ else if (S_ISBLK(m))
+ mode[0] = 'b';
+ else if (S_ISCHR(m))
+ mode[0] = 'c';
+ else if (S_ISDIR(m))
+ mode[0] = 'd';
+ else if (S_ISFIFO(m))
+ mode[0] = 'p';
+ else if (S_ISLNK(m))
+ mode[0] = 'l';
+ else if (S_ISSOCK(m))
+ mode[0] = 's';
+ else
+ mode[0] = '?';
+
+ if (m & S_IRUSR) mode[1] = 'r';
+ if (m & S_IWUSR) mode[2] = 'w';
+ if (m & S_IXUSR) mode[3] = 'x';
+ if (m & S_IRGRP) mode[4] = 'r';
+ if (m & S_IWGRP) mode[5] = 'w';
+ if (m & S_IXGRP) mode[6] = 'x';
+ if (m & S_IROTH) mode[7] = 'r';
+ if (m & S_IWOTH) mode[8] = 'w';
+ if (m & S_IXOTH) mode[9] = 'x';
+
+ if (m & S_ISUID) mode[3] = (mode[3] == 'x') ? 's' : 'S';
+ if (m & S_ISGID) mode[6] = (mode[6] == 'x') ? 's' : 'S';
+ if (m & S_ISVTX) mode[9] = (mode[9] == 'x') ? 't' : 'T';
+
+ return mode;
+}
+
int
writefilestree(FILE *fp, git_tree *tree, const char *path)
{
filesize = git_blob_rawsize((git_blob *)obj);
fputs("<tr><td>", fp);
- fprintf(fp, "%u", git_tree_entry_filemode_raw(entry));
+ fprintf(fp, "%s", filemode(git_tree_entry_filemode(entry)));
fprintf(fp, "</td><td><a href=\"%sfile/", relpath);
xmlencode(fp, filename, strlen(filename));
fputs(".html\">", fp);
git_object *obj = NULL;
git_commit *commit = NULL;
- fputs("<table id=\"files\"><thead>\n"
- "<tr><td>Mode</td><td>Name</td><td>Size</td></tr>\n"
- "</thead><tbody>\n", fp);
+ fputs("<table id=\"files\"><thead>\n<tr>"
+ "<td>Mode</td><td>Name</td><td class=\"num\">Size</td>"
+ "</tr>\n</thead><tbody>\n", fp);
if (git_revparse_single(&obj, repo, "HEAD"))
return -1;