diff options
author | Bernd Schubert <bernd.schubert@fastmail.fm> | 2010-05-24 16:07:34 +0200 |
---|---|---|
committer | Bernd Schubert <bernd.schubert@fastmail.fm> | 2010-05-24 16:07:34 +0200 |
commit | ec98d2566ecfbe44194600015ad1570c4d837c48 (patch) | |
tree | cad69e4899cf8c3efe5a1e6a118604f65f3d7f63 | |
parent | 29811238af5b7a35bf31c9177131a6e457c8aaf6 (diff) | |
download | unionfs-fuse-ec98d2566ecfbe44194600015ad1570c4d837c48.tar.gz |
build_path: Improve debug information - print line of the call function
-rw-r--r-- | src/string.c | 13 | ||||
-rw-r--r-- | src/string.h | 4 |
2 files changed, 9 insertions, 8 deletions
diff --git a/src/string.c b/src/string.c index dddf57c..548d3a8 100644 --- a/src/string.c +++ b/src/string.c @@ -53,17 +53,18 @@ char *whiteout_tag(const char *fname) { * * path already MUST have been allocated! */ -int build_path(char *path, int max_len, char *callfunc, ...) { - +int build_path(char *path, int max_len, const char *callfunc, int line, ...) { va_list ap; // argument pointer int len = 0; char *str_ptr = path; (void)str_ptr; // please the compile to avoid warning in non-debug mode + (void)line; + (void)callfunc; path[0] = '\0'; // that way can easily strcat even the first element - va_start(ap, callfunc); + va_start(ap, line); while (1) { char *str = va_arg (ap, char *); // the next path element if (!str) break; @@ -111,7 +112,7 @@ int build_path(char *path, int max_len, char *callfunc, ...) { // +1 for final \0 not counted by strlen if (len + 1 > max_len) { - usyslog (LOG_WARNING, "%s: Path too long \n", callfunc); + usyslog (LOG_WARNING, "%s():%d Path too long \n", callfunc, line); errno = ENAMETOOLONG; return -errno; } @@ -120,12 +121,12 @@ int build_path(char *path, int max_len, char *callfunc, ...) { } if (len == 0) { - usyslog(LOG_ERR, "from: %s : No argument given?\n", callfunc); + usyslog(LOG_ERR, "from: %s():%d : No argument given?\n", callfunc, line); errno = EIO; return -errno; } - DBG("from: %s path: %s\n", callfunc, str_ptr); + DBG("from: %s():%d path: %s\n", callfunc, line, str_ptr); return 0; } diff --git a/src/string.h b/src/string.h index 7c04016..9ce9cf5 100644 --- a/src/string.h +++ b/src/string.h @@ -10,7 +10,7 @@ #include <string.h> char *whiteout_tag(const char *fname); -int build_path(char *dest, int max_len, ...); +int build_path(char *dest, int max_len, const char *callfunc, int line, ...); char *u_dirname(const char *path); unsigned int string_hash(void *s); @@ -19,7 +19,7 @@ unsigned int string_hash(void *s); * a maximum string length. Since there is no way in C to determine the given number of arguments, we * simply add NULL here. */ -#define BUILD_PATH(dest, ...) build_path(dest, PATHLEN_MAX, __func__, __VA_ARGS__, NULL) +#define BUILD_PATH(dest, ...) build_path(dest, PATHLEN_MAX, __func__, __LINE__, __VA_ARGS__, NULL) /** * Test if two strings are eqal. |