Skip to content

Commit

Permalink
Merge pull request #11 from jdhore/master
Browse files Browse the repository at this point in the history
Fix a macro variable name
  • Loading branch information
ggreer committed Jan 15, 2012
2 parents 5c4c9ff + b1f0a4e commit 7601fbb
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 8 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Expand Up @@ -14,7 +14,7 @@ PKG_CHECK_MODULES([PCRE], [libpcre])
CFLAGS="$CFLAGS $PCRE_CFLAGS -Wall -Wextra -std=c89 -D_GNU_SOURCE -g"
LDFLAGS="$LDFLAGS"

AC_CHECK_DECL([PCRE_CONFIG_JIT], [AC_DEFINE([USE_PRCE_JIT], [], [Use PCRE JIT])], [], [#include <pcre.h>])
AC_CHECK_DECL([PCRE_CONFIG_JIT], [AC_DEFINE([USE_PCRE_JIT], [], [Use PCRE JIT])], [], [#include <pcre.h>])

AC_CONFIG_FILES([Makefile])
AC_CONFIG_HEADERS([src/config.h])
Expand Down
14 changes: 7 additions & 7 deletions src/main.c
Expand Up @@ -57,9 +57,9 @@ int search_dir(const pcre *re, const pcre_extra *re_extra, const char* path, con
dir = dir_list[i];
path_length = (size_t)(strlen(path) + strlen(dir->d_name) + 2); /* 2 for slash and null char */
dir_full_path = malloc(path_length);
dir_full_path = strncpy(dir_full_path, path, path_length);
dir_full_path = strncat(dir_full_path, "/", path_length);
dir_full_path = strncat(dir_full_path, dir->d_name, path_length);
ag_strlcpy(dir_full_path, path, path_length);
ag_strlcat(dir_full_path, "/", path_length);
ag_strlcat(dir_full_path, dir->d_name, path_length);
load_ignore_patterns(dir_full_path);
free(dir);
dir = NULL;
Expand Down Expand Up @@ -100,9 +100,9 @@ int search_dir(const pcre *re, const pcre_extra *re_extra, const char* path, con
/* TODO: this is copy-pasted from about 30 lines above */
path_length = (size_t)(strlen(path) + strlen(dir->d_name) + 2); /* 2 for slash and null char */
dir_full_path = malloc(path_length);
dir_full_path = strncpy(dir_full_path, path, path_length);
dir_full_path = strncat(dir_full_path, "/", path_length);
dir_full_path = strncat(dir_full_path, dir->d_name, path_length);
ag_strlcpy(dir_full_path, path, path_length);
ag_strlcat(dir_full_path, "/", path_length);
ag_strlcat(dir_full_path, dir->d_name, path_length);

log_debug("dir %s type %i", dir_full_path, dir->d_type);
/* TODO: scan files in current dir before going deeper */
Expand Down Expand Up @@ -286,7 +286,7 @@ int main(int argc, char **argv) {
exit(1);
}

#ifdef USE_PRCE_JIT
#ifdef USE_PCRE_JIT
int has_jit = 0;
pcre_config(PCRE_CONFIG_JIT, &has_jit);
if (has_jit) {
Expand Down
37 changes: 37 additions & 0 deletions src/util.c
Expand Up @@ -67,3 +67,40 @@ int is_binary(const void* buf, const int buf_len) {

return(0);
}

/*
* These functions are taken from Linux. Renamed so there's no
* possible function name conflicts.
*/
size_t ag_strlcat(char *dest, const char *src, size_t count)
{
size_t dsize = strlen(dest);
size_t len = strlen(src);
size_t res = dsize + len;

dest += dsize;
count -= dsize;

if (len >= count)
len = count - 1;

memcpy(dest, src, len);

dest[len] = 0;

return res;
}

size_t ag_strlcpy(char *dest, const char *src, size_t size)
{
size_t ret = strlen(src);

if (size)
{
size_t len = (ret >= size) ? size - 1 : ret;
memcpy(dest, src, len);
dest[len] = '\0';
}

return ret;
}
2 changes: 2 additions & 0 deletions src/util.h
Expand Up @@ -4,5 +4,7 @@
char* ag_strnstr(const char *s, const char *find, size_t slen);
char* ag_strncasestr(const char *s, const char *find, size_t slen);
int is_binary(const void* buf, const int buf_len);
size_t ag_strlcat(char *dest, const char *src, size_t size);
size_t ag_strlcpy(char *dest, const char *src, size_t size);

#endif

0 comments on commit 7601fbb

Please sign in to comment.