eal: add getline() function for Windows
PATCH 1/1 eal: add getline() function for Windows
Existing DPDK code uses getline(), which is a POSIX function and is not available in the Windows APIs.
Instead of rewriting it or coming up with some other replacement, this patch makes use of the implementation provided by NetBSD to make it possible to compile code dependent on getline on Windows.
--- lib/eal/windows/getline.c | 61 +++++++++++++++++++++++++++++++ lib/eal/windows/include/getline.h | 28 ++++++++++++++ lib/eal/windows/meson.build | 1 + license/exceptions.txt | 2 + 4 files changed, 92 insertions(+) create mode 100644 lib/eal/windows/getline.c create mode 100644 lib/eal/windows/include/getline.h
lib/eal/windows/getline.c new file +61 -0
@@ -0,0 +1,61 @@ +/* SPDX-License-Identifier: BSD-2-Clause +* Copyright (c) 2011 The NetBSD Foundation, Inc. +* All rights reserved. +* +* This code is derived from software contributed to The NetBSD Foundation +* by Christos Zoulas. +*/ + +#include <malloc.h> + +#include "getline.h" + +ssize_t +getdelim (char **buf,size_t *bufsiz,int delimiter,FILE *fp) +{ +char *ptr, *eptr; + +if (*buf ==NULL || *bufsiz ==0 ) { + *bufsiz =BUFSIZ ; + *buf =malloc (*bufsiz); +if (buf ==NULL ) +return -1 ; + } + +for (ptr = *buf, eptr = *buf + *bufsiz;;) { +int c =fgetc (fp); +if (c ==-1 ) { +if (feof (fp)) { +ssize_t diff = (ssize_t )(ptr - *buf); +if (diff !=0 ) { + *ptr ='\0' ; +return diff; + } + } +return -1 ; + } + *ptr++ = c; +if (c == delimiter) { + *ptr ='\0' ; +return ptr - *buf; + } +if (ptr +2 >= eptr) { +char *nbuf; +size_t nbufsiz = *bufsiz *2 ; +ssize_t d = ptr - *buf; + nbuf =realloc (*buf, nbufsiz); +if (nbuf ==NULL ) +return -1 ; + *buf = nbuf; + *bufsiz = nbufsiz; + eptr = nbuf + nbufsiz; + ptr = nbuf + d; + } + } +} + +ssize_t +getline (char **buf,size_t *bufsiz,FILE *fp) +{ +return getdelim (buf, bufsiz,'\n' , fp); +}
lib/eal/windows/include/getline.h new file +28 -0
@@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: BSD-2-Clause +* Copyright (c) 2011 The NetBSD Foundation, Inc. +* All rights reserved. +* +* This code is derived from software contributed to The NetBSD Foundation +* by Christos Zoulas. +*/ + +/** +* @file +* getline compat. +* +* This module provides getline() and getdelim(). +*/ + +#pragma once + +#include <stdio.h> + +#ifndef ssize_t +#define ssize_t ptrdiff_t +#endif + +ssize_t +getdelim (char **buf,size_t *bufsiz,int delimiter,FILE *fp); + +ssize_t +getline (char **buf,size_t *bufsiz,FILE *fp);
lib/eal/windows/meson.build +1 -0
@@ -17,6 +17,7 @@ sources += files( 'eal_mp.c', 'eal_thread.c', 'eal_timer.c', + 'getline.c', 'getopt.c', 'rte_thread.c', )
license/exceptions.txt +2 -0
@@ -16,4 +16,6 @@ MIT | 10/23/2019 | 02/10/2020 | lib/eal/windows/inc BSD-2-Clause | 10/23/2019 | 12/18/2019 | lib/eal/windows/include/getopt.h ISC AND BSD-2-Clause | 10/23/2019 | 12/18/2019 | lib/eal/windows/getopt.c MIT | 10/19/2022 | 10/18/2022 | drivers/net/gve/base/* +BSD-2-Clause | XX/XX/XXXX | XX/XX/XXXX | lib/eal/windows/include/getline.h +BSD-2-Clause | XX/XX/XXXX | XX/XX/XXXX | lib/eal/windows/getline.c ---------------------------------------------------------------------------------------------------
Signature · 1 line
2.49.0.vfs.0.0
Quoted 8 lines · On Mon, 5 May 2025 13:40:07 -0700 Andre Muezerie…
Existing DPDK code uses
getline(), which is a POSIX function and is not available in the Windows APIs.Instead of rewriting it or coming up with some other replacement, this patch makes use of the implementation provided by NetBSD to make it possible to compile code dependent on getline on Windows.
Signed-off-by Andre Muezerie <[email protected]>
Not sure, are BSD-2 and BSD-3 compatible?
Getting license exception approved requires going through the governing board which can take up to 6 months.
Quoted 10 lines · Stephen Hemminger
Quoted 7 lines · On Mon, 5 May 2025 13:40:07 -0700 Andre Muezerie…
Existing DPDK code uses
getline(), which is a POSIX function and is not available in the Windows APIs.Instead of rewriting it or coming up with some other replacement, this patch makes use of the implementation provided by NetBSD to make it possible to compile code dependent on getline on Windows.
Quoted 5 lines
Quoted 1 line
Signed-off-by Andre Muezerie <[email protected]>Not sure, are BSD-2 and BSD-3 compatible?
Getting license exception approved requires going through the governing board which can take up to 6 months.
Hi Stephen, I would appreciate some guidance here.
My understanding is that in general, BSD-2 licensed code can be used in BSD-3 licensed projects, as long as the BSD-2 license is retained in the original
(BSD-2) files.
I do see that BSD-2 was listed in the exception table (for getopt function). It's not clear to me why it needed to be listed as an exception, but if that was needed, it indicates that the same should be done for getline(). Is that not the case?
21/05/2025 02:35, Andre Muezerie:
Quoted 19 lines · Stephen Hemminger
Quoted 10 lines
Quoted 7 lines · On Mon, 5 May 2025 13:40:07 -0700 Andre Muezerie…
Existing DPDK code uses
getline(), which is a POSIX function and is not available in the Windows APIs.Instead of rewriting it or coming up with some other replacement, this patch makes use of the implementation provided by NetBSD to make it possible to compile code dependent on getline on Windows.
Quoted 5 lines
Quoted 1 line
Signed-off-by Andre Muezerie <[email protected]>Not sure, are BSD-2 and BSD-3 compatible?
Getting license exception approved requires going through the governing board which can take up to 6 months.Hi Stephen, I would appreciate some guidance here.
Quoted 8 lines
My understanding is that in general, BSD-2 licensed code can be used in BSD-3 licensed projects, as long as the BSD-2 license is retained in the original
(BSD-2) files.I do see that BSD-2 was listed in the exception table (for getopt function). It's not clear to me why it needed to be listed as an exception, but if that was needed, it indicates that the same should be done for
getline(). Is that not the case?
No matter the compatibility agreed or not in courts, if the licence is different we note it as an exception, so it is crystal clear for users of DPDK.
We don't want to have any surprise and we avoid exceptions, that's why the Governing Board has to accept it.
Quoted 29 lines · Thomas Monjalon
21/05/2025 02:35, Andre Muezerie:
Quoted 19 lines · Stephen Hemminger
Quoted 10 lines
Quoted 7 lines · On Mon, 5 May 2025 13:40:07 -0700 Andre Muezerie…
Existing DPDK code uses
getline(), which is a POSIX function and is not available in the Windows APIs.Instead of rewriting it or coming up with some other replacement, this patch makes use of the implementation provided by NetBSD to make it possible to compile code dependent on getline on Windows.
Quoted 5 lines
Quoted 1 line
Signed-off-by Andre Muezerie <[email protected]>Not sure, are BSD-2 and BSD-3 compatible?
Getting license exception approved requires going through the governing board which can take up to 6 months.Hi Stephen, I would appreciate some guidance here.
Quoted 8 lines
My understanding is that in general, BSD-2 licensed code can be used in BSD-3 licensed projects, as long as the BSD-2 license is retained in the original
(BSD-2) files.I do see that BSD-2 was listed in the exception table (for getopt function). It's not clear to me why it needed to be listed as an exception, but if that was needed, it indicates that the same should be done for
getline(). Is that not the case?
Quoted 6 lines
No matter the compatibility agreed or not in courts, if the licence is different we note it as an exception, so it is crystal clear for users of DPDK.
We don't want to have any surprise and we avoid exceptions, that's why the Governing Board has to accept it.
Thanks for clarifying, Thomas.
I sent an email to the Governing Board requesting the exception.
05/05/2025 22:40, Andre Muezerie:
Quoted 8 lines
Existing DPDK code uses
getline(), which is a POSIX function and is not available in the Windows APIs.Instead of rewriting it or coming up with some other replacement, this patch makes use of the implementation provided by NetBSD to make it possible to compile code dependent on getline on Windows.
Signed-off-by Andre Muezerie <[email protected]>
It has been approved by the techboard on May 28,
and the govboard on May 30,
so the patch is applied, thanks.
Quoted 8 lines · Thomas Monjalon
05/05/2025 22:40, Andre Muezerie:
Quoted 7 lines
Existing DPDK code uses
getline(), which is a POSIX function and is not available in the Windows APIs.Instead of rewriting it or coming up with some other replacement, this patch makes use of the implementation provided by NetBSD to make it possible to compile code dependent on getline on Windows.
Quoted 6 lines
Quoted 1 line
Signed-off-by Andre Muezerie <[email protected]>It has been approved by the techboard on May 28,
and the govboard on May 30,
so the patch is applied, thanks.
That's great news! Thanks.