From 74cccbfa97fe4803bfc048779d98cef1e6bce3bb Mon Sep 17 00:00:00 2001 From: Yalu Zhang <yalu.zhang@iopsys.eu> Date: Mon, 20 Mar 2023 15:39:58 +0100 Subject: [PATCH] Remove the definition of _GNU_SOURCE from CFLAGS This causes compilation errors for libvoice-d2. The better solution is to define _GNU_SOURCE on demand. Replace strchrnul() with strchr(). --- Makefile | 2 +- libvoice/Makefile | 2 +- line.c | 9 +++++---- main.c | 3 +++ 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 39a7866..1662f3d 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ VOICEMNGR := voicemngr CFLAGS += -O2 -fcaller-saves -fsection-anchors CFLAGS += -Wall -Werror -CFLAGS += -Wextra -std=gnu99 -D_GNU_SOURCE +CFLAGS += -Wextra -std=gnu99 CFLAGS += -DBOS_OS_LINUXUSER -DBOS_CFG_TIME -DNTR_SUPPORT -DWITH_UBUS CFLAGS += -I./ -Ilibvoice/ diff --git a/libvoice/Makefile b/libvoice/Makefile index 6a6f4a4..c25aeb6 100644 --- a/libvoice/Makefile +++ b/libvoice/Makefile @@ -12,7 +12,7 @@ LIBVOICE := libvoice.so CFLAGS += -O2 -fcaller-saves -fsection-anchors CFLAGS += -Wall -Werror -CFLAGS += -Wextra -std=gnu99 -D_GNU_SOURCE +CFLAGS += -Wextra -std=gnu99 CFLAGS += -DBOS_OS_LINUXUSER -DBOS_CFG_TIME -DNTR_SUPPORT -DWITH_UBUS CFLAGS += -I./ diff --git a/line.c b/line.c index 5df9d2f..3c0fb01 100644 --- a/line.c +++ b/line.c @@ -120,11 +120,12 @@ static int line_signal_ring(int line, int pcm, enum VOICE_SIGNAL signal, const c // Parse the called ID string generated by Asterisk if(data && strlen(data) >= CLID_MIN_LEN && strlen(data) <= MAX_CALLER_ID_LEN && data[CLID_TIME_DELIM] == ',' && data[CLID_NUMB_REC + 1] != ',') { - char callIdTmp[strlen(data) + 1]; + char cid_tmp[strlen(data) + 1], *end; - strcpy(callIdTmp, data); // Copy into a temp buffer. - *strchrnul(callIdTmp + CLID_NUMB_REC, ',') = 0; // Find comma after digits and null it. - strcpy(line_req->caller_id, callIdTmp + CLID_NUMB_REC); // Extract the number. + strcpy(cid_tmp, data); + if ((end = strchr(cid_tmp + CLID_NUMB_REC, ',')) != NULL) + *end = '\0'; // Find comma after digits and null it + strcpy(line_req->caller_id, cid_tmp + CLID_NUMB_REC); // Extract the number } } diff --git a/main.c b/main.c index 5eccb1f..fdeab07 100644 --- a/main.c +++ b/main.c @@ -3,6 +3,9 @@ #include <unistd.h> #include <signal.h> #include <stdlib.h> +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif #include <string.h> #include <sys/types.h> #include <sys/stat.h> -- GitLab