Commit 420cbdc2 by Vicent Martí

Merge pull request #379 from kiryl/STRLEN

Drop STRLEN() macros
parents a7e34e3c 85b91652
......@@ -225,7 +225,7 @@ int commit_parse_buffer(git_commit *commit, const void *data, size_t len)
if (git__prefixcmp(buffer, "encoding ") == 0) {
const char *encoding_end;
buffer += STRLEN("encoding ");
buffer += strlen("encoding ");
encoding_end = buffer;
while (encoding_end < buffer_end && *encoding_end != '\n')
......
......@@ -264,7 +264,7 @@ static char *interiorize_section(const char *orig)
len = dot - orig;
memcpy(section, orig, len);
section += len;
len = STRLEN(" \"");
len = strlen(" \"");
memcpy(section, " \"", len);
section += len;
len = last_dot - dot - 1;
......
......@@ -176,11 +176,11 @@ static void index_path(char *path, git_indexer *idx)
ptr = strrchr(path, '/') + 1;
memcpy(ptr, prefix, STRLEN(prefix));
ptr += STRLEN(prefix);
memcpy(ptr, prefix, strlen(prefix));
ptr += strlen(prefix);
git_oid_fmt(ptr, &idx->hash);
ptr += GIT_OID_HEXSZ;
memcpy(ptr, suffix, STRLEN(suffix));
memcpy(ptr, suffix, strlen(suffix));
}
int git_indexer_write(git_indexer *idx)
......@@ -199,7 +199,7 @@ int git_indexer_write(git_indexer *idx)
namelen = strlen(idx->pack->pack_name);
memcpy(filename, idx->pack->pack_name, namelen);
memcpy(filename + namelen - STRLEN("pack"), "idx\0", STRLEN("idx\0"));
memcpy(filename + namelen - strlen("pack"), "idx", strlen("idx") + 1);
error = git_filebuf_open(&idx->file, filename, GIT_FILEBUF_HASH_CONTENTS);
......
......@@ -237,7 +237,7 @@ static int packfile_load__cb(void *_data, char *path)
for (i = 0; i < backend->packs.length; ++i) {
struct git_pack_file *p = git_vector_get(&backend->packs, i);
if (memcmp(p->pack_name, path, strlen(path) - STRLEN(".idx")) == 0)
if (memcmp(p->pack_name, path, strlen(path) - strlen(".idx")) == 0)
return GIT_SUCCESS;
}
......
......@@ -196,7 +196,7 @@ static int pack_index_open(struct git_pack_file *p)
return GIT_SUCCESS;
idx_name = git__strdup(p->pack_name);
strcpy(idx_name + strlen(idx_name) - STRLEN(".pack"), ".idx");
strcpy(idx_name + strlen(idx_name) - strlen(".pack"), ".idx");
error = pack_index_check(idx_name, p);
free(idx_name);
......@@ -614,7 +614,7 @@ int git_packfile_check(struct git_pack_file **pack_out, const char *path)
* Make sure a corresponding .pack file exists and that
* the index looks sane.
*/
path_len -= STRLEN(".idx");
path_len -= strlen(".idx");
if (path_len < 1) {
free(p);
return git__throw(GIT_ENOTFOUND, "Failed to check packfile. Wrong path name");
......
......@@ -267,7 +267,7 @@ int git_pkt_send_flush(int s)
{
char flush[] = "0000";
return gitno_send(s, flush, STRLEN(flush), 0);
return gitno_send(s, flush, strlen(flush), 0);
}
static int send_want_with_caps(git_remote_head *head, git_transport_caps *caps, int fd)
......@@ -279,7 +279,7 @@ static int send_want_with_caps(git_remote_head *head, git_transport_caps *caps,
if (caps->ofs_delta)
strcpy(capstr, GIT_CAP_OFS_DELTA);
len = STRLEN("XXXXwant ") + GIT_OID_HEXSZ + 1 /* NUL */ + strlen(capstr) + 1 /* LF */;
len = strlen("XXXXwant ") + GIT_OID_HEXSZ + 1 /* NUL */ + strlen(capstr) + 1 /* LF */;
cmd = git__malloc(len + 1);
if (cmd == NULL)
return GIT_ENOMEM;
......@@ -302,10 +302,10 @@ int git_pkt_send_wants(git_headarray *refs, git_transport_caps *caps, int fd)
{
unsigned int i = 0;
int error = GIT_SUCCESS;
char buf[STRLEN(WANT_PREFIX) + GIT_OID_HEXSZ + 2];
char buf[sizeof(WANT_PREFIX) + GIT_OID_HEXSZ + 1];
git_remote_head *head;
memcpy(buf, WANT_PREFIX, STRLEN(WANT_PREFIX));
memcpy(buf, WANT_PREFIX, strlen(WANT_PREFIX));
buf[sizeof(buf) - 2] = '\n';
buf[sizeof(buf) - 1] = '\0';
......@@ -332,8 +332,8 @@ int git_pkt_send_wants(git_headarray *refs, git_transport_caps *caps, int fd)
if (head->local)
continue;
git_oid_fmt(buf + STRLEN(WANT_PREFIX), &head->oid);
error = gitno_send(fd, buf, STRLEN(buf), 0);
git_oid_fmt(buf + strlen(WANT_PREFIX), &head->oid);
error = gitno_send(fd, buf, strlen(buf), 0);
return git__rethrow(error, "Failed to send want pkt");
}
......@@ -350,13 +350,13 @@ int git_pkt_send_have(git_oid *oid, int fd)
{
char buf[] = "0032have 0000000000000000000000000000000000000000\n";
git_oid_fmt(buf + STRLEN(HAVE_PREFIX), oid);
return gitno_send(fd, buf, STRLEN(buf), 0);
git_oid_fmt(buf + strlen(HAVE_PREFIX), oid);
return gitno_send(fd, buf, strlen(buf), 0);
}
int git_pkt_send_done(int fd)
{
char buf[] = "0009done\n";
return gitno_send(fd, buf, STRLEN(buf), 0);
return gitno_send(fd, buf, strlen(buf), 0);
}
......@@ -93,7 +93,7 @@ int git_remote_get(git_remote **out, git_config *cfg, const char *name)
}
/* "fetch" is the longest var name we're interested in */
buf_len = STRLEN("remote.") + STRLEN(".fetch") + strlen(name) + 1;
buf_len = strlen("remote.") + strlen(".fetch") + strlen(name) + 1;
buf = git__malloc(buf_len);
if (buf == NULL) {
error = GIT_ENOMEM;
......
......@@ -449,12 +449,12 @@ static int read_gitfile(char *path_out, const char *file_path, const char *base_
for (;data[end_offset] == '\r' || data[end_offset] == '\n'; --end_offset);
data[end_offset + 1] = '\0';
if (STRLEN(GIT_FILE_CONTENT_PREFIX) == end_offset + 1) {
if (strlen(GIT_FILE_CONTENT_PREFIX) == end_offset + 1) {
git_futils_freebuffer(&file);
return git__throw(GIT_ENOTFOUND, "No path in git file `%s`", file_path);
}
data = data + STRLEN(GIT_FILE_CONTENT_PREFIX);
data = data + strlen(GIT_FILE_CONTENT_PREFIX);
error = git_path_prettify_dir(path_out, data, base_path);
git_futils_freebuffer(&file);
......
......@@ -183,7 +183,7 @@ static commit_object *commit_lookup(git_revwalk *walk, const git_oid *oid)
static int commit_quick_parse(git_revwalk *walk, commit_object *commit, git_rawobj *raw)
{
const int parent_len = STRLEN("parent ") + GIT_OID_HEXSZ + 1;
const int parent_len = strlen("parent ") + GIT_OID_HEXSZ + 1;
unsigned char *buffer = raw->data;
unsigned char *buffer_end = buffer + raw->len;
......@@ -192,10 +192,10 @@ static int commit_quick_parse(git_revwalk *walk, commit_object *commit, git_rawo
int i, parents = 0;
long commit_time;
buffer += STRLEN("tree ") + GIT_OID_HEXSZ + 1;
buffer += strlen("tree ") + GIT_OID_HEXSZ + 1;
parents_start = buffer;
while (buffer + parent_len < buffer_end && memcmp(buffer, "parent ", STRLEN("parent ")) == 0) {
while (buffer + parent_len < buffer_end && memcmp(buffer, "parent ", strlen("parent ")) == 0) {
parents++;
buffer += parent_len;
}
......@@ -208,7 +208,7 @@ static int commit_quick_parse(git_revwalk *walk, commit_object *commit, git_rawo
for (i = 0; i < parents; ++i) {
git_oid oid;
if (git_oid_fromstr(&oid, (char *)buffer + STRLEN("parent ")) < GIT_SUCCESS)
if (git_oid_fromstr(&oid, (char *)buffer + strlen("parent ")) < GIT_SUCCESS)
return git__throw(GIT_EOBJCORRUPTED, "Failed to parse commit. Parent object is corrupted");
commit->parents[i] = commit_lookup(walk, &oid);
......
......@@ -388,7 +388,7 @@ typedef struct {
const char *pattern;
} tag_filter_data;
#define GIT_REFS_TAGS_DIR_LEN STRLEN(GIT_REFS_TAGS_DIR)
#define GIT_REFS_TAGS_DIR_LEN strlen(GIT_REFS_TAGS_DIR)
static int tag_list_cb(const char *tag_name, void *payload)
{
......
......@@ -73,7 +73,7 @@ static int gen_proto(char **out, int *outlen, const char *cmd, const char *url)
if (cmd == NULL)
cmd = default_command;
len = 4 + strlen(cmd) + 1 + strlen(repo) + 1 + STRLEN(host) + (delim - url) + 2;
len = 4 + strlen(cmd) + 1 + strlen(repo) + 1 + strlen(host) + (delim - url) + 2;
*out = git__malloc(len);
if (*out == NULL)
......@@ -148,7 +148,7 @@ static int do_connect(transport_git *t, const char *url)
int error, connected = 0;
if (!git__prefixcmp(url, prefix))
url += STRLEN(prefix);
url += strlen(prefix);
error = extract_host_and_port(&host, &port, url);
s = gitno_connect(host, port);
......@@ -242,7 +242,7 @@ static int detect_caps(transport_git *t)
if(!git__prefixcmp(ptr, GIT_CAP_OFS_DELTA)) {
caps->common = caps->ofs_delta = 1;
ptr += STRLEN(GIT_CAP_OFS_DELTA);
ptr += strlen(GIT_CAP_OFS_DELTA);
continue;
}
......@@ -474,9 +474,9 @@ static int store_pack(char **out, gitno_buffer *buf, git_repository *repo)
strcpy(path, repo->path_repository);
off += strlen(repo->path_repository);
strcat(path, suff);
//memcpy(path + off, suff, GIT_PATH_MAX - off - STRLEN(suff) - 1);
//memcpy(path + off, suff, GIT_PATH_MAX - off - strlen(suff) - 1);
if (memcmp(buf->data, "PACK", STRLEN("PACK"))) {
if (memcmp(buf->data, "PACK", strlen("PACK"))) {
return git__throw(GIT_ERROR, "The pack doesn't start with the signature");
}
......
......@@ -31,7 +31,7 @@ static int local_connect(git_transport *transport, int GIT_UNUSED(direction))
/* The repo layer doesn't want the prefix */
if (!git__prefixcmp(transport->url, file_prefix))
path = transport->url + STRLEN(file_prefix);
path = transport->url + strlen(file_prefix);
else
path = transport->url;
......@@ -92,7 +92,7 @@ static int add_ref(const char *name, git_repository *repo, git_vector *vec)
/* And if it's a tag, peel it, and add it to the list */
head = git__malloc(sizeof(git_remote_head));
peel_len = strlen(name) + STRLEN(peeled);
peel_len = strlen(name) + strlen(peeled);
head->name = git__malloc(peel_len + 1);
ret = p_snprintf(head->name, peel_len + 1, "%s%s", name, peeled);
if (ret >= peel_len + 1) {
......
......@@ -93,8 +93,6 @@ extern char *git__strtok(char **end, const char *sep);
extern void git__strntolower(char *str, int len);
extern void git__strtolower(char *str);
#define STRLEN(str) (sizeof(str) - 1)
extern int git__fnmatch(const char *pattern, const char *name, int flags);
/*
......
......@@ -300,7 +300,7 @@ BEGIN_TEST(config16, "add a variable in a new section")
/* As the section wasn't removed, owerwrite the file */
must_pass(git_filebuf_open(&buf, CONFIG_BASE "/config10", 0));
must_pass(git_filebuf_write(&buf, "[empty]\n", STRLEN("[empty]\n")));
must_pass(git_filebuf_write(&buf, "[empty]\n", strlen("[empty]\n")));
must_pass(git_filebuf_commit(&buf));
END_TEST
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment