From: Eric Bollengier Date: Wed, 6 Sep 2023 10:08:13 +0000 (+0200) Subject: BEE Backport lib files X-Git-Tag: Beta-15.0.0~107 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=29669b4092d68bbc326a0cbd48d91d756a70b38f;p=thirdparty%2Fbacula.git BEE Backport lib files --- diff --git a/bacula/src/lib/bcollector.c b/bacula/src/lib/bcollector.c index b2a3a85ba..5fa2e8dea 100644 --- a/bacula/src/lib/bcollector.c +++ b/bacula/src/lib/bcollector.c @@ -28,7 +28,6 @@ #include "bacula.h" #include "parse_conf.h" #include "jcr.h" -#define STATUS_FUNCTIONS #include "status.h" #include diff --git a/bacula/src/lib/bsys.c b/bacula/src/lib/bsys.c index 1211fb1c9..c70816451 100644 --- a/bacula/src/lib/bsys.c +++ b/bacula/src/lib/bsys.c @@ -1941,29 +1941,6 @@ int get_home_directories(const char *grpname, alist *dirs) return (dirs->size() > 0) ? 0 : -1; } -/* Implementation of strcasestr() for non-gnu platforms */ -char *bstrcasestr(const char *haystack, const char *needle) -{ - int needle_len; /* Length of needle. */ - int haystack_len; /* Known minimum length of haystack. */ - - if (!needle || needle[0] == '\0') { - return (char *)haystack; - } - needle_len = strlen (needle); - haystack_len = strlen (haystack); - - const char *p = haystack; - while (p && *p && haystack_len >= needle_len) { - if (strncasecmp(needle, p, needle_len) == 0) { - return (char *)p; - } - p++; - haystack_len--; - } - return NULL; -} - void b_uname(POOLMEM *&un) { if (un) { @@ -2093,6 +2070,29 @@ void get_path_and_fname(const char *name, char **path, char **fname) } } +/* Implementation of strcasestr() for non-gnu platforms */ +char *bstrcasestr(const char *haystack, const char *needle) +{ + int needle_len; /* Length of needle. */ + int haystack_len; /* Known minimum length of haystack. */ + + if (!needle || needle[0] == '\0') { + return (char *)haystack; + } + needle_len = strlen (needle); + haystack_len = strlen (haystack); + + const char *p = haystack; + while (p && *p && haystack_len >= needle_len) { + if (strncasecmp(needle, p, needle_len) == 0) { + return (char *)p; + } + p++; + haystack_len--; + } + return NULL; +} + #ifdef TEST_PROGRAM #include "unittests.h" @@ -2352,17 +2352,6 @@ int main(int argc, char **argv) i++; } - // Test bstrcasestr() - { - const char *p1 = "This is a test"; - ok(bstrcasestr(p1, "toto") == NULL, "Test with non existing string"); - ok(bstrcasestr(p1, NULL) == p1, "Test with NULL string"); - ok(bstrcasestr(p1, "") == p1, "Test with empty string"); - is(bstrcasestr(p1, "TEST"), "test", "Test with upper string at the end"); - is(bstrcasestr(p1, "this"), p1, "Test with lower string at the start"); - ok(bstrcasestr(p1, "xxxxxxxxxxxxxxxxxxxxxxxxx") == NULL, "Test with non existing string"); - is(bstrcasestr(p1, " iS"), " is a test", "Test with a middle string"); - } { char *fname = NULL; char *path = NULL; @@ -2388,6 +2377,18 @@ int main(int argc, char **argv) free(path); free(fname); } + + // Test bstrcasestr() + { + const char *p1 = "This is a test"; + ok(bstrcasestr(p1, "toto") == NULL, "Test with non existing string"); + ok(bstrcasestr(p1, NULL) == p1, "Test with NULL string"); + ok(bstrcasestr(p1, "") == p1, "Test with empty string"); + is(bstrcasestr(p1, "TEST"), "test", "Test with upper string at the end"); + is(bstrcasestr(p1, "this"), p1, "Test with lower string at the start"); + ok(bstrcasestr(p1, "xxxxxxxxxxxxxxxxxxxxxxxxx") == NULL, "Test with non existing string"); + is(bstrcasestr(p1, " iS"), " is a test", "Test with a middle string"); + } return report(); } #endif diff --git a/bacula/src/lib/htable.c b/bacula/src/lib/htable.c index 9931b587f..3f67fde25 100644 --- a/bacula/src/lib/htable.c +++ b/bacula/src/lib/htable.c @@ -225,7 +225,7 @@ void htable::grow_table() Dmsg1(100, "Grow called old size = %d\n", buckets); /* Setup a bigger table */ htable *big = (htable *)malloc(sizeof(htable)); - memcpy((void *)big, (void *)this, sizeof(htable)); /* start with original class data */ + memcpy((void*)big, (void*)this, sizeof(htable)); /* start with original class data */ big->loffset = loffset; big->mask = mask<<1 | 1; big->rshift = rshift - 1; diff --git a/bacula/src/lib/output.h b/bacula/src/lib/output.h index 289d8e659..dc83599e3 100644 --- a/bacula/src/lib/output.h +++ b/bacula/src/lib/output.h @@ -25,6 +25,9 @@ #include "bacula.h" +/* define some standard error code to use in OutputWriter::set_error() */ +#define OWE_NO_DATA 501 + enum _OutputType { OT_INT, /* Integer */ OT_SIZE, /* int64 size */ diff --git a/bacula/src/lib/status.h b/bacula/src/lib/status.h index 9c04390d0..1a0d9b023 100644 --- a/bacula/src/lib/status.h +++ b/bacula/src/lib/status.h @@ -37,9 +37,6 @@ extern void output_status(STATUS_PKT *sp); -#ifndef STATUS_FUNCTIONS -#define STATUS_FUNCTIONS - /* * Send to bsock (Director or Console) */ @@ -56,6 +53,9 @@ static void sendit(const char *msg, int len, STATUS_PKT *sp) } } +#ifndef STATUS_FUNCTIONS +#define STATUS_FUNCTIONS + /* common to SD/FD */ #ifdef USE_LIST_TERMINATED_JOBS static void list_terminated_jobs(STATUS_PKT *sp)