Merge pull request #379 from kiryl/STRLEN Drop STRLEN() macros
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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323
diff --git a/src/commit.c b/src/commit.c
index 00e18b8..dc9e536 100644
--- a/src/commit.c
+++ b/src/commit.c
@@ -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')
diff --git a/src/config_file.c b/src/config_file.c
index 840817c..520a806 100644
--- a/src/config_file.c
+++ b/src/config_file.c
@@ -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;
diff --git a/src/indexer.c b/src/indexer.c
index bef62a2..3934250 100644
--- a/src/indexer.c
+++ b/src/indexer.c
@@ -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);
diff --git a/src/odb_pack.c b/src/odb_pack.c
index fc2408e..5b2be58 100644
--- a/src/odb_pack.c
+++ b/src/odb_pack.c
@@ -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;
}
diff --git a/src/pack.c b/src/pack.c
index 4b43e7c..d882516 100644
--- a/src/pack.c
+++ b/src/pack.c
@@ -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");
diff --git a/src/pkt.c b/src/pkt.c
index 516800b..4eac041 100644
--- a/src/pkt.c
+++ b/src/pkt.c
@@ -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);
}
diff --git a/src/remote.c b/src/remote.c
index d54d8c7..74c5afa 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -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;
diff --git a/src/repository.c b/src/repository.c
index c0e99bb..0e7d197 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -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);
diff --git a/src/revwalk.c b/src/revwalk.c
index f7a56cc..538928c 100644
--- a/src/revwalk.c
+++ b/src/revwalk.c
@@ -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);
diff --git a/src/tag.c b/src/tag.c
index 1a79d92..21bc3c7 100644
--- a/src/tag.c
+++ b/src/tag.c
@@ -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)
{
diff --git a/src/transport_git.c b/src/transport_git.c
index 88ad7a9..c6e1f33 100644
--- a/src/transport_git.c
+++ b/src/transport_git.c
@@ -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");
}
diff --git a/src/transport_local.c b/src/transport_local.c
index 3d72a1b..ab0922c 100644
--- a/src/transport_local.c
+++ b/src/transport_local.c
@@ -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) {
diff --git a/src/util.h b/src/util.h
index 4a33420..78f9f82 100644
--- a/src/util.h
+++ b/src/util.h
@@ -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);
/*
diff --git a/tests/t15-config.c b/tests/t15-config.c
index aa5ba28..05de25f 100644
--- a/tests/t15-config.c
+++ b/tests/t15-config.c
@@ -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