From patchwork Mon Jan 15 15:25:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Storm, Christian" X-Patchwork-Id: 860943 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:400c:c0c::239; helo=mail-wr0-x239.google.com; envelope-from=swupdate+bncbdd6bwv65qpbbder6pjakgqefbledwq@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="U4vCWktV"; dkim-atps=neutral Received: from mail-wr0-x239.google.com (mail-wr0-x239.google.com [IPv6:2a00:1450:400c:c0c::239]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zKy0x32cNz9sP1 for ; Tue, 16 Jan 2018 02:28:15 +1100 (AEDT) Received: by mail-wr0-x239.google.com with SMTP id h38sf2375705wrh.11 for ; Mon, 15 Jan 2018 07:28:15 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1516030092; cv=pass; d=google.com; s=arc-20160816; b=t2hcr9i/yLlejpg77vKIns9rLiY3Qdv4e3M+mBPxENqDvhoak6x4amBGfXBLYYvr6i 80KeZoH4SimNIlp8ZGNuUYqOIUMh58RHj9dz3OJQ6W/+uvwFmb7mQc3n2O41UeJl32UY tnMiKsanz3xXyH+XeVIcEIws3pzbJiTDVi5a7C/nef4tQibgG6+SWugM1yqQyAFUsnvP KuT8Rrqw+O3QOJDNquIXE5Hj0M+5m+5rA1dpmLbiL3eOubvWFzXcdp5AwmEaMSI61NJO AVcqlYVfor4Q/vEk2ohQ0YnC7QNfQJ6uY0oCn5DHBLcDpq3SfuMj0G2HOCtKYD8wH4VF 1MDQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from :arc-authentication-results:arc-message-signature:sender :dkim-signature:arc-authentication-results; bh=tBn9a0noh5J9m+vOG6UB9ZPeAiTRWpfsmY9NM6LTG5A=; b=FeGpxRf0b8jmehVEZ+yDMCsLVLS7ixz+a6covWgqx8ohwdLOApVkJqrf2W7IawAs5G 3CkvydokUY5Nx/SSlAo4GFSGoUq+1oxj8hbyIy6X8Vl3AVDcRemI/EpqOKZh7hQcnJeP 6ox3DLMkmAjjgBnxhNYqD8dDweRUXZO8HhLl53ppjZi0F44w003EplJqVu1gor9agV16 swXpL3z9mCsAAyEPZyfJuDDUN77/9sR18Bo+mt1BANkj8gkHopvCyzSmxjw7NfNbSzsV KKp3K0+yODMDtAUxIioGX9eS04nx+dCjDrjisBUcTnT6Oa7D/dv+ucVyyWurqbVhHuK2 l13A== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.28 as permitted sender) smtp.mailfrom=christian.storm@siemens.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-subscribe:list-unsubscribe; bh=tBn9a0noh5J9m+vOG6UB9ZPeAiTRWpfsmY9NM6LTG5A=; b=U4vCWktVtCOHTYZV0xZns33fn6gYVvbdMiIjtO2AN3DTHNtyalwSDnSEXayR/J09OI XCd0W28WT5NPHfIL7NAgWsMH0B1MRMmCR87xHyZmDYjT8UwnsVZk8vzuI1nVLGgDKGwE lIJivvyB2uA26VCPmj/us4MdfKCRDenZQmIGdefNN7Tq55MVDWEVOjhEVlSd7V4CCazq GeUR00p/tsXqRNhu1fY85Th0iw4mqKSMWfW1gxAgMUiPh9x67h1GYGagLZocCvTmttjQ BLhLK/4PV8s7gHhB3mqPraJbsGhlvk17JSN+6dx7+QRsZKraHkhA7uvlveIidBbu4eEW Ir+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=tBn9a0noh5J9m+vOG6UB9ZPeAiTRWpfsmY9NM6LTG5A=; b=TLOQQMOmCMvGo2fCNTEhW5NSCeMYIFYIlil0MoiFhClzhK73jj/DLubAvOkoSJ2J2B a5+VRcwOsAhqwVr+lQe+zKiqGYptvq8VO8p4Au3rc6sLNLeYBH0bmqAq7vOfKrQOAFWA hmyCRu8E7ibco9s+eL1Qx2Dv3kr7rX5XFw5F2GoJf4s/dNSxz0knz6JJtg1f4PwPaqzY a42ofamcBm/RepFN/JuwzoqexncxWD6vmWEBUf2GubcyJa+zYm4TyFjjemtY9MAa3sAG 36HMJQ3+iaaiOCCuayhfyS2QJYN9EC/7XXXQ584NY/BqGig8oC09SJFFZ/xBW33qJEOA pSCQ== Sender: swupdate@googlegroups.com X-Gm-Message-State: AKwxytca+hxexHsiCWImqiOzrnMKTdJmbgmHJpdGcTJ+uW36hs8ppzqd 1taNXmO4tzzE1SEhOeKjva4= X-Google-Smtp-Source: ACJfBosy1g3EfJRxOpZkWhP82t28Q3bCAH9urSb6Mqm5pMWmgH9t2cCZLs7N99xFxdkXpCSUK502MQ== X-Received: by 10.28.229.194 with SMTP id c185mr141059wmh.3.1516030092773; Mon, 15 Jan 2018 07:28:12 -0800 (PST) X-BeenThere: swupdate@googlegroups.com Received: by 10.80.183.65 with SMTP id g59ls3413612ede.4.gmail; Mon, 15 Jan 2018 07:28:11 -0800 (PST) X-Received: by 10.80.201.193 with SMTP id c1mr3370692edi.9.1516030091965; Mon, 15 Jan 2018 07:28:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516030091; cv=none; d=google.com; s=arc-20160816; b=pmw8sJSIA1Dq/FgAoVHjt07Dva8L81evJK5z6Doh6WDBlWe34fYl6uzfe9dxprcpB4 hv2a524hcIWTf4kpWhGElcsCqSDUuXCJjy0YU8mu4cTWfPsg6xNnYqgh6yfYOSFbbHGf 18eMtX/7kCUZL/1tcWdc0gKZwYwiVtDIhXnY1HEO3faRMyO5kfJSRFNeA/+vC2cZUmw0 Q0PVDCjAtL9PG2kJMXkmAi9Fnme+OuG4vOoqf92BueTV3GGrKRyt3vNKpyndQSMN2Rko DpWXuni28wAsK0zjqKvRBH/PYwPVgmqOe8PIdbVZD3QolkCXKNpqSiySndHC8Ur9tCnX Pi4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:arc-authentication-results; bh=KRa/Zx0r+xwUB0LXZaMqylkRr84wQoB3yChQjw29Qr4=; b=gvnJhNyxDLbcGtXICUMyp7tg9koIccuyNzSPK+TRbHY72D7A3N3UB8C91tngSZeGBq 6pgljCONazCfeYz2KRl80ixjMNsrDjWaBGSfbskvJFznLHzSJrpS/3mmJyfFuOsC5xxQ QXE+vOcxhbtPn9Fen949a31OgrGM8YFrPIQhe7wK0usIIrToT0eleITFtZNwoYc+p9RJ VhLB9iXYHwCt4MEI4pRnXXb4kBxtCjeVw6Lss6tyZPjnDC9enA4X766a0DFiO8ILozEQ 35sO/q0Igg0lrS9aNBnFl7JRGAARs0SpEnNZgUa6fnhJS2j601OKEuUz24//S9PWKvhm 9Jtw== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.28 as permitted sender) smtp.mailfrom=christian.storm@siemens.com Received: from goliath.siemens.de (goliath.siemens.de. [192.35.17.28]) by gmr-mx.google.com with ESMTPS id a23si32558edd.1.2018.01.15.07.28.11 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Jan 2018 07:28:11 -0800 (PST) Received-SPF: pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.28 as permitted sender) client-ip=192.35.17.28; Received: from mail1.siemens.de (mail1.siemens.de [139.23.33.14]) by goliath.siemens.de (8.15.2/8.15.2) with ESMTPS id w0FFSBsp015903 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 15 Jan 2018 16:28:11 +0100 Received: from MD1KR9XC.ww002.siemens.net ([139.25.69.251]) by mail1.siemens.de (8.15.2/8.15.2) with ESMTP id w0FFSBDg005811; Mon, 15 Jan 2018 16:28:11 +0100 From: Christian Storm To: swupdate@googlegroups.com Cc: Christian Storm Subject: [swupdate] [PATCH] compat.h: introduce compatibility header Date: Mon, 15 Jan 2018 16:25:34 +0100 Message-Id: <20180115152534.14790-1-christian.storm@siemens.com> X-Mailer: git-send-email 2.15.1 MIME-Version: 1.0 X-Original-Sender: christian.storm@siemens.com X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.28 as permitted sender) smtp.mailfrom=christian.storm@siemens.com Precedence: list Mailing-list: list swupdate@googlegroups.com; contact swupdate+owners@googlegroups.com List-ID: X-Spam-Checked-In-Group: swupdate@googlegroups.com X-Google-Group-Id: 605343134186 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , Introduce a compat.h housing compatibility definitions and macros along the lines of commit 7b49b8d having introduced a compatibility mechanism for Lua. Fist use case (and motivation) is the support for musl (https://www.musl-libc.org/) which doesn't bother to provide char *strndupa(const char *s, size_t n) Reported-by: Jörg Krause Signed-off-by: Christian Storm Reviewed-by: Stefano Babic --- include/compat.h | 24 ++++++++++++++++++++++++ include/util.h | 1 + ipc/network_ipc.c | 1 + 3 files changed, 26 insertions(+) create mode 100644 include/compat.h diff --git a/include/compat.h b/include/compat.h new file mode 100644 index 0000000..29d7af1 --- /dev/null +++ b/include/compat.h @@ -0,0 +1,24 @@ +/* + * Author: Christian Storm + * Copyright (C) 2018, Siemens AG + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#pragma once + +#ifndef strndupa +/* + * Define char *strndupa(const char *s, size_t n) + * for, e.g., musl (https://www.musl-libc.org/) + * which does not bother to implement this function. + */ +#define strndupa(s, n) \ + (__extension__({ \ + const char *__in = (s); \ + size_t __len = strnlen(__in, (n)) + 1; \ + char *__out = (char *)alloca(__len); \ + __out[__len - 1] = '\0'; \ + (char *)memcpy(__out, __in, __len - 1); \ + })) +#endif diff --git a/include/util.h b/include/util.h index 920701f..777626b 100644 --- a/include/util.h +++ b/include/util.h @@ -25,6 +25,7 @@ #include #include "swupdate.h" #include "swupdate_status.h" +#include "compat.h" #define NOTIFY_BUF_SIZE 2048 #define ENOMEM_ASPRINTF -1 diff --git a/ipc/network_ipc.c b/ipc/network_ipc.c index 3d4c730..6c5107e 100644 --- a/ipc/network_ipc.c +++ b/ipc/network_ipc.c @@ -34,6 +34,7 @@ #include #include "network_ipc.h" +#include "compat.h" #ifdef CONFIG_SOCKET_CTRL_PATH static char* SOCKET_CTRL_PATH = (char*)CONFIG_SOCKET_CTRL_PATH;