1 #define GIT__NO_HIDE_MALLOC
6 void *git__malloc(size_t n
)
10 return git_ptr_error(GIT_ENOMEM
);
14 void *git__calloc(size_t a
, size_t b
)
16 void *r
= calloc(a
, b
);
18 return git_ptr_error(GIT_ENOMEM
);
22 char *git__strdup(const char *s
)
26 return git_ptr_error(GIT_ENOMEM
);
30 int git__fmt(char *buf
, size_t buf_sz
, const char *fmt
, ...)
36 r
= vsnprintf(buf
, buf_sz
, fmt
, va
);
38 if (r
< 0 || r
>= buf_sz
)
43 int git__prefixcmp(const char *str
, const char *prefix
)
46 char p
= *(prefix
++), s
;
49 if ((s
= *(str
++)) != p
)
54 int git__suffixcmp(const char *str
, const char *suffix
)
56 size_t a
= strlen(str
);
57 size_t b
= strlen(suffix
);
60 return strcmp(str
+ (a
- b
), suffix
);
63 int git__dirname(char *dir
, size_t n
, char *path
)
70 if (!path
|| !*path
|| (s
= strrchr(path
, '/')) == NULL
) {
75 if (s
== path
) { /* "/[aaa]" */
80 if ((len
= s
- path
) >= n
)
83 memcpy(dir
, path
, len
);
89 int git__basename(char *base
, size_t n
, char *path
)
94 assert(base
&& n
> 1);
96 if (!path
|| !*path
) {
102 if ((s
= strrchr(path
, '/')) == NULL
) {
109 if (s
== path
&& len
== 1) { /* "/" */
118 memcpy(base
, s
+1, len
);