From 3394baedd10b8181725491b0cc6c367c1b1010e4 Mon Sep 17 00:00:00 2001
From: Meco Man <920369182@qq.com>
Date: Mon, 18 Oct 2021 17:32:42 -0400
Subject: [libc] put getline into posix folder
---
components/libc/getline/README.md | 20 -------
components/libc/getline/SConscript | 13 -----
components/libc/getline/UNLICENSE | 24 ---------
components/libc/getline/posix_getline.c | 78 ---------------------------
components/libc/getline/posix_getline.h | 23 --------
components/libc/posix/getline/README.md | 20 +++++++
components/libc/posix/getline/SConscript | 13 +++++
components/libc/posix/getline/UNLICENSE | 24 +++++++++
components/libc/posix/getline/posix_getline.c | 78 +++++++++++++++++++++++++++
components/libc/posix/getline/posix_getline.h | 23 ++++++++
10 files changed, 158 insertions(+), 158 deletions(-)
delete mode 100644 components/libc/getline/README.md
delete mode 100644 components/libc/getline/SConscript
delete mode 100644 components/libc/getline/UNLICENSE
delete mode 100644 components/libc/getline/posix_getline.c
delete mode 100644 components/libc/getline/posix_getline.h
create mode 100644 components/libc/posix/getline/README.md
create mode 100644 components/libc/posix/getline/SConscript
create mode 100644 components/libc/posix/getline/UNLICENSE
create mode 100644 components/libc/posix/getline/posix_getline.c
create mode 100644 components/libc/posix/getline/posix_getline.h
(limited to 'components')
diff --git a/components/libc/getline/README.md b/components/libc/getline/README.md
deleted file mode 100644
index ef3c19deae..0000000000
--- a/components/libc/getline/README.md
+++ /dev/null
@@ -1,20 +0,0 @@
-# getline/getdelim for RT-Thread POSIX(IEEE Std 1003.1-2008)
-
-[](https://travis-ci.org/ivanrad/getline)
-
-https://github.com/ivanrad/getline
-
-Read a delimited record from stream.
-
-Yet another (hopefully portable C) implementation of getline/getdelim.
-These are ersatz functions, a drop-in replacement, to be used on those occasions when your C library does not already support them.
-
-For more details, see [Open Group Base Specification for getdelim/getline][opengroup-spec].
-
-
-
-## License
-
-This code is unlicensed -- free and released into the public domain. See `UNLICENSE` file for more information.
-
-[opengroup-spec]: http://pubs.opengroup.org/onlinepubs/9699919799/functions/getline.html
diff --git a/components/libc/getline/SConscript b/components/libc/getline/SConscript
deleted file mode 100644
index fa4c8618c1..0000000000
--- a/components/libc/getline/SConscript
+++ /dev/null
@@ -1,13 +0,0 @@
-# RT-Thread building script for component
-
-from building import *
-
-cwd = GetCurrentDir()
-src = Glob('*.c') + Glob('*.cpp')
-CPPPATH = [cwd]
-
-group = DefineGroup('libc', src,
- depend = ['RT_USING_LIBC', 'RT_USING_POSIX','RT_USING_POSIX_GETLINE'],
- CPPPATH = CPPPATH)
-
-Return('group')
diff --git a/components/libc/getline/UNLICENSE b/components/libc/getline/UNLICENSE
deleted file mode 100644
index 68a49daad8..0000000000
--- a/components/libc/getline/UNLICENSE
+++ /dev/null
@@ -1,24 +0,0 @@
-This is free and unencumbered software released into the public domain.
-
-Anyone is free to copy, modify, publish, use, compile, sell, or
-distribute this software, either in source code form or as a compiled
-binary, for any purpose, commercial or non-commercial, and by any
-means.
-
-In jurisdictions that recognize copyright laws, the author or authors
-of this software dedicate any and all copyright interest in the
-software to the public domain. We make this dedication for the benefit
-of the public at large and to the detriment of our heirs and
-successors. We intend this dedication to be an overt act of
-relinquishment in perpetuity of all present and future rights to this
-software under copyright law.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
-OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-
-For more information, please refer to
diff --git a/components/libc/getline/posix_getline.c b/components/libc/getline/posix_getline.c
deleted file mode 100644
index da80242ecc..0000000000
--- a/components/libc/getline/posix_getline.c
+++ /dev/null
@@ -1,78 +0,0 @@
-/* posix_getline.c
- * RT-Thread POSIX
- * getdelim(), getline() - read a delimited record from stream, ersatz implementation
- * This code is unlicensed -- free and released into the public domain.
- * https://man7.org/linux/man-pages/man3/getline.3.html
- * Authors:
- * https://github.com/ivanrad/getline
- *
- * Meco Man 2020-09-03 porting to RT-Thread
- */
-
-#include "posix_getline.h"
-#include
-#include
-#include
-
-ssize_t getdelim(char **lineptr, size_t *n, int delim, FILE *stream) {
- char *cur_pos, *new_lineptr;
- size_t new_lineptr_len;
- int c;
-
- if (lineptr == NULL || n == NULL || stream == NULL) {
- errno = EINVAL;
- return -1;
- }
-
- if (*lineptr == NULL) {
- *n = 128; /* init len */
- if ((*lineptr = (char *)malloc(*n)) == NULL) {
- errno = ENOMEM;
- return -1;
- }
- }
-
- cur_pos = *lineptr;
- for (;;) {
- c = getc(stream);
-
- if (ferror(stream) || (c == EOF && cur_pos == *lineptr))
- return -1;
-
- if (c == EOF)
- break;
-
- if ((*lineptr + *n - cur_pos) < 2) {
- if (LONG_MAX / 2 < *n) {
-#ifdef EOVERFLOW
- errno = EOVERFLOW;
-#else
- errno = ERANGE; /* no EOVERFLOW defined */
-#endif
- return -1;
- }
- new_lineptr_len = *n * 2;
-
- if ((new_lineptr = (char *)realloc(*lineptr, new_lineptr_len)) == NULL) {
- errno = ENOMEM;
- return -1;
- }
- cur_pos = new_lineptr + (cur_pos - *lineptr);
- *lineptr = new_lineptr;
- *n = new_lineptr_len;
- }
-
- *cur_pos++ = (char)c;
-
- if (c == delim)
- break;
- }
-
- *cur_pos = '\0';
- return (ssize_t)(cur_pos - *lineptr);
-}
-
-ssize_t getline(char **lineptr, size_t *n, FILE *stream) {
- return getdelim(lineptr, n, '\n', stream);
-}
-
diff --git a/components/libc/getline/posix_getline.h b/components/libc/getline/posix_getline.h
deleted file mode 100644
index 13a4487d7f..0000000000
--- a/components/libc/getline/posix_getline.h
+++ /dev/null
@@ -1,23 +0,0 @@
-/* posix_getline.h
- * RT-Thread POSIX
- * getdelim(), getline() - read a delimited record from stream, ersatz implementation
- * This code is unlicensed -- free and released into the public domain.
- * https://man7.org/linux/man-pages/man3/getline.3.html
- * Authors:
- * https://github.com/ivanrad/getline
- *
- * Meco Man 2020-09-03 porting to RT-Thread
- */
-
-
-#ifndef POSIX_GETLINE_H
-#define POSIX_GETLINE_H
-
-#include
-#include
-
-ssize_t getdelim(char **lineptr, size_t *n, int delim, FILE *stream);
-ssize_t getline(char **lineptr, size_t *n, FILE *stream);
-
-#endif /* POSIX_GETLINE_H */
-
diff --git a/components/libc/posix/getline/README.md b/components/libc/posix/getline/README.md
new file mode 100644
index 0000000000..ef3c19deae
--- /dev/null
+++ b/components/libc/posix/getline/README.md
@@ -0,0 +1,20 @@
+# getline/getdelim for RT-Thread POSIX(IEEE Std 1003.1-2008)
+
+[](https://travis-ci.org/ivanrad/getline)
+
+https://github.com/ivanrad/getline
+
+Read a delimited record from stream.
+
+Yet another (hopefully portable C) implementation of getline/getdelim.
+These are ersatz functions, a drop-in replacement, to be used on those occasions when your C library does not already support them.
+
+For more details, see [Open Group Base Specification for getdelim/getline][opengroup-spec].
+
+
+
+## License
+
+This code is unlicensed -- free and released into the public domain. See `UNLICENSE` file for more information.
+
+[opengroup-spec]: http://pubs.opengroup.org/onlinepubs/9699919799/functions/getline.html
diff --git a/components/libc/posix/getline/SConscript b/components/libc/posix/getline/SConscript
new file mode 100644
index 0000000000..fa4c8618c1
--- /dev/null
+++ b/components/libc/posix/getline/SConscript
@@ -0,0 +1,13 @@
+# RT-Thread building script for component
+
+from building import *
+
+cwd = GetCurrentDir()
+src = Glob('*.c') + Glob('*.cpp')
+CPPPATH = [cwd]
+
+group = DefineGroup('libc', src,
+ depend = ['RT_USING_LIBC', 'RT_USING_POSIX','RT_USING_POSIX_GETLINE'],
+ CPPPATH = CPPPATH)
+
+Return('group')
diff --git a/components/libc/posix/getline/UNLICENSE b/components/libc/posix/getline/UNLICENSE
new file mode 100644
index 0000000000..68a49daad8
--- /dev/null
+++ b/components/libc/posix/getline/UNLICENSE
@@ -0,0 +1,24 @@
+This is free and unencumbered software released into the public domain.
+
+Anyone is free to copy, modify, publish, use, compile, sell, or
+distribute this software, either in source code form or as a compiled
+binary, for any purpose, commercial or non-commercial, and by any
+means.
+
+In jurisdictions that recognize copyright laws, the author or authors
+of this software dedicate any and all copyright interest in the
+software to the public domain. We make this dedication for the benefit
+of the public at large and to the detriment of our heirs and
+successors. We intend this dedication to be an overt act of
+relinquishment in perpetuity of all present and future rights to this
+software under copyright law.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+For more information, please refer to
diff --git a/components/libc/posix/getline/posix_getline.c b/components/libc/posix/getline/posix_getline.c
new file mode 100644
index 0000000000..da80242ecc
--- /dev/null
+++ b/components/libc/posix/getline/posix_getline.c
@@ -0,0 +1,78 @@
+/* posix_getline.c
+ * RT-Thread POSIX
+ * getdelim(), getline() - read a delimited record from stream, ersatz implementation
+ * This code is unlicensed -- free and released into the public domain.
+ * https://man7.org/linux/man-pages/man3/getline.3.html
+ * Authors:
+ * https://github.com/ivanrad/getline
+ *
+ * Meco Man 2020-09-03 porting to RT-Thread
+ */
+
+#include "posix_getline.h"
+#include
+#include
+#include
+
+ssize_t getdelim(char **lineptr, size_t *n, int delim, FILE *stream) {
+ char *cur_pos, *new_lineptr;
+ size_t new_lineptr_len;
+ int c;
+
+ if (lineptr == NULL || n == NULL || stream == NULL) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ if (*lineptr == NULL) {
+ *n = 128; /* init len */
+ if ((*lineptr = (char *)malloc(*n)) == NULL) {
+ errno = ENOMEM;
+ return -1;
+ }
+ }
+
+ cur_pos = *lineptr;
+ for (;;) {
+ c = getc(stream);
+
+ if (ferror(stream) || (c == EOF && cur_pos == *lineptr))
+ return -1;
+
+ if (c == EOF)
+ break;
+
+ if ((*lineptr + *n - cur_pos) < 2) {
+ if (LONG_MAX / 2 < *n) {
+#ifdef EOVERFLOW
+ errno = EOVERFLOW;
+#else
+ errno = ERANGE; /* no EOVERFLOW defined */
+#endif
+ return -1;
+ }
+ new_lineptr_len = *n * 2;
+
+ if ((new_lineptr = (char *)realloc(*lineptr, new_lineptr_len)) == NULL) {
+ errno = ENOMEM;
+ return -1;
+ }
+ cur_pos = new_lineptr + (cur_pos - *lineptr);
+ *lineptr = new_lineptr;
+ *n = new_lineptr_len;
+ }
+
+ *cur_pos++ = (char)c;
+
+ if (c == delim)
+ break;
+ }
+
+ *cur_pos = '\0';
+ return (ssize_t)(cur_pos - *lineptr);
+}
+
+ssize_t getline(char **lineptr, size_t *n, FILE *stream) {
+ return getdelim(lineptr, n, '\n', stream);
+}
+
diff --git a/components/libc/posix/getline/posix_getline.h b/components/libc/posix/getline/posix_getline.h
new file mode 100644
index 0000000000..13a4487d7f
--- /dev/null
+++ b/components/libc/posix/getline/posix_getline.h
@@ -0,0 +1,23 @@
+/* posix_getline.h
+ * RT-Thread POSIX
+ * getdelim(), getline() - read a delimited record from stream, ersatz implementation
+ * This code is unlicensed -- free and released into the public domain.
+ * https://man7.org/linux/man-pages/man3/getline.3.html
+ * Authors:
+ * https://github.com/ivanrad/getline
+ *
+ * Meco Man 2020-09-03 porting to RT-Thread
+ */
+
+
+#ifndef POSIX_GETLINE_H
+#define POSIX_GETLINE_H
+
+#include
+#include
+
+ssize_t getdelim(char **lineptr, size_t *n, int delim, FILE *stream);
+ssize_t getline(char **lineptr, size_t *n, FILE *stream);
+
+#endif /* POSIX_GETLINE_H */
+
--
cgit v1.3.1