Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tag: v1.5.3-rc5
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 49 lines (41 sloc) 0.862 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
#include "cache.h"

int has_symlink_leading_path(const char *name, char *last_symlink)
{
char path[PATH_MAX];
const char *sp, *ep;
char *dp;

sp = name;
dp = path;

if (last_symlink && *last_symlink) {
size_t last_len = strlen(last_symlink);
size_t len = strlen(name);
if (last_len < len &&
!strncmp(name, last_symlink, last_len) &&
name[last_len] == '/')
return 1;
*last_symlink = '\0';
}

while (1) {
size_t len;
struct stat st;

ep = strchr(sp, '/');
if (!ep)
break;
len = ep - sp;
if (PATH_MAX <= dp + len - path + 2)
return 0; /* new name is longer than that??? */
memcpy(dp, sp, len);
dp[len] = 0;

if (lstat(path, &st))
return 0;
if (S_ISLNK(st.st_mode)) {
if (last_symlink)
strcpy(last_symlink, path);
return 1;
}

dp[len++] = '/';
dp = dp + len;
sp = ep + 1;
}
return 0;
}
Something went wrong with that request. Please try again.