X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=abspath.c;h=f04ac18e33063f7e2cb9ab9eab9a6b86cb089b5a;hb=87afe9a5ed759668e35513c44eacd2fd393ba658;hp=37287f86c18f8b532feb38b5c70541c8cb3d3a44;hpb=d0b46502de2893a121427b94321a2bfc8cffde27;p=git.git diff --git a/abspath.c b/abspath.c index 37287f86c..f04ac18e3 100644 --- a/abspath.c +++ b/abspath.c @@ -139,3 +139,31 @@ const char *absolute_path(const char *path) } return buf; } + +/* + * Unlike prefix_path, this should be used if the named file does + * not have to interact with index entry; i.e. name of a random file + * on the filesystem. + */ +const char *prefix_filename(const char *pfx, int pfx_len, const char *arg) +{ + static char path[PATH_MAX]; +#ifndef WIN32 + if (!pfx_len || is_absolute_path(arg)) + return arg; + memcpy(path, pfx, pfx_len); + strcpy(path + pfx_len, arg); +#else + char *p; + /* don't add prefix to absolute paths, but still replace '\' by '/' */ + if (is_absolute_path(arg)) + pfx_len = 0; + else if (pfx_len) + memcpy(path, pfx, pfx_len); + strcpy(path + pfx_len, arg); + for (p = path + pfx_len; *p; p++) + if (*p == '\\') + *p = '/'; +#endif + return path; +}