* which is what it's designed for.
*/
#include "cache.h"
-#include <pwd.h>
-static char pathname[PATH_MAX];
static char bad_path[] = "/bad-path/";
+static char *get_pathname(void)
+{
+ static char pathname_array[4][PATH_MAX];
+ static int index;
+ return pathname_array[3 & ++index];
+}
+
static char *cleanup_path(char *path)
{
/* Clean it up */
{
va_list args;
unsigned len;
+ char *pathname = get_pathname();
va_start(args, fmt);
len = vsnprintf(pathname, PATH_MAX, fmt, args);
char *git_path(const char *fmt, ...)
{
const char *git_dir = get_git_dir();
+ char *pathname = get_pathname();
va_list args;
unsigned len;
pch += n;
}
- safe_strncpy(pch, template, len);
+ strlcpy(pch, template, len);
return mkstemp(path);
}
-char *safe_strncpy(char *dest, const char *src, size_t n)
-{
- strncpy(dest, src, n);
- dest[n - 1] = '\0';
-
- return dest;
-}
-
int validate_symref(const char *path)
{
struct stat st;
: 0));
if (S_ISDIR(mode))
mode |= S_ISGID;
- if (chmod(path, mode) < 0)
+ if ((mode & st.st_mode) != mode && chmod(path, mode) < 0)
return -2;
return 0;
}