commit 8ca09b4d61745d52786da16a6f59c11c87add3d4
parent d1ad64a27ac50a257adb47e3676ed97ee8376466
Author: Remy Noulin <loader2x@gmail.com>
Date: Fri, 3 Jul 2020 20:29:57 +0200
change readFileG and readTextG for char* and char** types - now they take a pointer to the variable instead of return type
Usage:
char *text = NULL;
readFileG(&text, "myfile.txt")
release/libsheepy.h | 2 +-
release/libsheepyObject.h | 50 ++++++++++++++++++++++++++++++++++++----------
src/json/libsheepyObject.c | 48 ++++++++++++++++++++++++++++++++++----------
src/libsheepy.h | 2 +-
src/libsheepyObject.h | 50 ++++++++++++++++++++++++++++++++++++----------
5 files changed, 120 insertions(+), 32 deletions(-)
Diffstat:
5 files changed, 120 insertions(+), 32 deletions(-)
diff --git a/release/libsheepy.h b/release/libsheepy.h
@@ -96,7 +96,7 @@
// version accoring to the version package: Release.Major.minor.patch
// https://noulin.net/version/file/README.md.html
-#define LIBSHEEPY_VERSION "1.1.2.1"
+#define LIBSHEEPY_VERSION "1.2"
#ifndef SH_PREFIX
#define SH_PREFIX(NAME) NAME
diff --git a/release/libsheepyObject.h b/release/libsheepyObject.h
@@ -3125,16 +3125,30 @@ void finishManyOF(void *paramType, ...);
smallStringt *: readFileSmallStringSmallJsonG \
), \
char **: _Generic(path, \
+ char *: readFileToG, \
+ const char *: readFileToG, \
+ FILE *: readStreamToG, \
+ smallJsont *: readToFileSmallJsonNotSupported, \
+ smallStringt *: readToFileSmallStringNotSupported \
+ ), \
+ char ***: _Generic(path, \
char *: readTextSG, \
const char *: readTextSG, \
FILE *: readTextStreamG, \
smallJsont *: readTextSmallJsonNotSupported, \
smallStringt *: readTextSmallStringNotSupported \
), \
+ char *: _Generic(path, \
+ char *: readFileToNewG, \
+ const char *: readFileToNewG, \
+ FILE *: readStreamToNewG, \
+ smallJsont *: readToFileSmallJsonNotSupported, \
+ smallStringt *: readToFileSmallStringNotSupported \
+ ), \
default: _Generic(path, \
- char *: readFileToG, \
- const char *: readFileToG, \
- FILE *: readStreamToG, \
+ char *: readFileToNewG, \
+ const char *: readFileToNewG, \
+ FILE *: readStreamToNewG, \
smallJsont *: readToFileSmallJsonNotSupported, \
smallStringt *: readToFileSmallStringNotSupported \
) \
@@ -3163,16 +3177,30 @@ void finishManyOF(void *paramType, ...);
smallStringt *: readTextSmallStringSmallJsonG \
), \
char **: _Generic(path, \
+ char *: readFileToG, \
+ const char *: readFileToG, \
+ FILE *: readStreamToG, \
+ smallJsont *: readToFileSmallJsonNotSupported, \
+ smallStringt *: readToFileSmallStringNotSupported \
+ ), \
+ char ***: _Generic(path, \
char *: readTextSG, \
const char *: readTextSG, \
FILE *: readTextStreamG, \
smallJsont *: readTextSmallJsonNotSupported, \
smallStringt *: readTextSmallStringNotSupported \
), \
+ char *: _Generic(path, \
+ char *: readFileToNewG, \
+ const char *: readFileToNewG, \
+ FILE *: readStreamToNewG, \
+ smallJsont *: readToFileSmallJsonNotSupported, \
+ smallStringt *: readToFileSmallStringNotSupported \
+ ), \
default: _Generic(path, \
- char *: readFileToG, \
- const char *: readFileToG, \
- FILE *: readStreamToG, \
+ char *: readFileToNewG, \
+ const char *: readFileToNewG, \
+ FILE *: readStreamToNewG, \
smallJsont *: readToFileSmallJsonNotSupported, \
smallStringt *: readToFileSmallStringNotSupported \
) \
@@ -9947,8 +9975,10 @@ ssize_t fileSizeO(smallStringt *filePath);
/**
* call readFileToS (for readFileG)
*/
-void *readFileToG(void *none UNUSED, const char *filePath);
-void *readStreamToG(void *none UNUSED, FILE *fp);
+void *readFileToNewG(void *none UNUSED, const char *filePath);
+void *readStreamToNewG(void *none UNUSED, FILE *fp);
+char *readFileToG(char **string, const char *filePath);
+char *readStreamToG(char **string, FILE *fp);
void readTextSmallJsonNotSupported(char **self UNUSED, smallJsont *path UNUSED);
void readTextSmallStringNotSupported(char **self UNUSED, smallStringt *path UNUSED);
@@ -9965,8 +9995,8 @@ int writeStreamFromG(const char *string, FILE *fp);
/**
* call readText (for readFileG)
*/
-char **readTextSG(char **retType UNUSED, const char *filePath);
-char **readTextStreamG(char **retType UNUSED, FILE *fp);
+char **readTextSG(char ***list, const char *filePath);
+char **readTextStreamG(char ***list, FILE *fp);
/**
* call writeText (for writeFileG)
diff --git a/src/json/libsheepyObject.c b/src/json/libsheepyObject.c
@@ -202,16 +202,18 @@ bool fileChmodJO(smallJsont *filePath, mode_t mode);
bool fileChmodO(smallStringt *filePath, mode_t mode);
ssize_t fileSizeJO(smallJsont *filePath);
ssize_t fileSizeO(smallStringt *filePath);
-void *readFileToG(void *none UNUSED, const char *filePath);
-void *readStreamToG(void *none UNUSED, FILE *fp);
+void *readFileToNewG(void *none UNUSED, const char *filePath);
+void *readStreamToNewG(void *none UNUSED, FILE *fp);
+char *readFileToG(char **string, const char *filePath);
+char *readStreamToG(char **string, FILE *fp);
void readTextSmallJsonNotSupported(char **self UNUSED, smallJsont *path UNUSED);
void readTextSmallStringNotSupported(char **self UNUSED, smallStringt *path UNUSED);
void readToFileSmallJsonNotSupported(void *self UNUSED, smallJsont *path UNUSED);
void readToFileSmallStringNotSupported(void *self UNUSED, smallStringt *path UNUSED);
int writeFileFromG(const char *string, const char *filePath);
int writeStreamFromG(const char *string, FILE *fp);
-char **readTextSG(char **retType UNUSED, const char *filePath);
-char **readTextStreamG(char **retType UNUSED, FILE *fp);
+char **readTextSG(char ***list, const char *filePath);
+char **readTextStreamG(char ***list, FILE *fp);
bool writeTextSG(char **list, const char *filePath);
bool writeTextStreamG(char **list, FILE *fp);
bool writeTextCG(const char **list, const char *filePath);
@@ -2401,16 +2403,34 @@ ssize_t fileSizeO(smallStringt *filePath) {
return(st.st_size);
}
-void *readFileToG(void *none UNUSED, const char *filePath) {
+void *readFileToNewG(void *none UNUSED, const char *filePath) {
return(readFileToS(filePath));
}
-void *readStreamToG(void *none UNUSED, FILE *fp) {
+void *readStreamToNewG(void *none UNUSED, FILE *fp) {
return(readStreamToS(fp));
}
+char *readFileToG(char **string, const char *filePath) {
+
+ if (!string) {
+ return(NULL);
+ }
+ *string = readFileToS(filePath);
+ return(*string);
+}
+
+char *readStreamToG(char **string, FILE *fp) {
+
+ if (!string) {
+ return(NULL);
+ }
+ *string = readStreamToS(fp);
+ return(*string);
+}
+
void readTextSmallJsonNotSupported(char **self UNUSED, smallJsont *path UNUSED) {
// TODO
@@ -2449,14 +2469,22 @@ int writeStreamFromG(const char *string, FILE *fp) {
return(writeStreamS(fp, string));
}
-char **readTextSG(char **retType UNUSED, const char *filePath) {
+char **readTextSG(char ***list, const char *filePath) {
- return(readText(filePath));
+ if (!list) {
+ return(NULL);
+ }
+ *list = readText(filePath);
+ return(*list);
}
-char **readTextStreamG(char **retType UNUSED, FILE *fp) {
+char **readTextStreamG(char ***list, FILE *fp) {
- return(readStream(fp));
+ if (!list) {
+ return(NULL);
+ }
+ *list = readStream(fp);
+ return(*list);
}
bool writeTextSG(char **list, const char *filePath) {
diff --git a/src/libsheepy.h b/src/libsheepy.h
@@ -96,7 +96,7 @@
// version accoring to the version package: Release.Major.minor.patch
// https://noulin.net/version/file/README.md.html
-#define LIBSHEEPY_VERSION "1.1.2.1"
+#define LIBSHEEPY_VERSION "1.2"
#ifndef SH_PREFIX
#define SH_PREFIX(NAME) NAME
diff --git a/src/libsheepyObject.h b/src/libsheepyObject.h
@@ -3125,16 +3125,30 @@ void finishManyOF(void *paramType, ...);
smallStringt *: readFileSmallStringSmallJsonG \
), \
char **: _Generic(path, \
+ char *: readFileToG, \
+ const char *: readFileToG, \
+ FILE *: readStreamToG, \
+ smallJsont *: readToFileSmallJsonNotSupported, \
+ smallStringt *: readToFileSmallStringNotSupported \
+ ), \
+ char ***: _Generic(path, \
char *: readTextSG, \
const char *: readTextSG, \
FILE *: readTextStreamG, \
smallJsont *: readTextSmallJsonNotSupported, \
smallStringt *: readTextSmallStringNotSupported \
), \
+ char *: _Generic(path, \
+ char *: readFileToNewG, \
+ const char *: readFileToNewG, \
+ FILE *: readStreamToNewG, \
+ smallJsont *: readToFileSmallJsonNotSupported, \
+ smallStringt *: readToFileSmallStringNotSupported \
+ ), \
default: _Generic(path, \
- char *: readFileToG, \
- const char *: readFileToG, \
- FILE *: readStreamToG, \
+ char *: readFileToNewG, \
+ const char *: readFileToNewG, \
+ FILE *: readStreamToNewG, \
smallJsont *: readToFileSmallJsonNotSupported, \
smallStringt *: readToFileSmallStringNotSupported \
) \
@@ -3163,16 +3177,30 @@ void finishManyOF(void *paramType, ...);
smallStringt *: readTextSmallStringSmallJsonG \
), \
char **: _Generic(path, \
+ char *: readFileToG, \
+ const char *: readFileToG, \
+ FILE *: readStreamToG, \
+ smallJsont *: readToFileSmallJsonNotSupported, \
+ smallStringt *: readToFileSmallStringNotSupported \
+ ), \
+ char ***: _Generic(path, \
char *: readTextSG, \
const char *: readTextSG, \
FILE *: readTextStreamG, \
smallJsont *: readTextSmallJsonNotSupported, \
smallStringt *: readTextSmallStringNotSupported \
), \
+ char *: _Generic(path, \
+ char *: readFileToNewG, \
+ const char *: readFileToNewG, \
+ FILE *: readStreamToNewG, \
+ smallJsont *: readToFileSmallJsonNotSupported, \
+ smallStringt *: readToFileSmallStringNotSupported \
+ ), \
default: _Generic(path, \
- char *: readFileToG, \
- const char *: readFileToG, \
- FILE *: readStreamToG, \
+ char *: readFileToNewG, \
+ const char *: readFileToNewG, \
+ FILE *: readStreamToNewG, \
smallJsont *: readToFileSmallJsonNotSupported, \
smallStringt *: readToFileSmallStringNotSupported \
) \
@@ -9947,8 +9975,10 @@ ssize_t fileSizeO(smallStringt *filePath);
/**
* call readFileToS (for readFileG)
*/
-void *readFileToG(void *none UNUSED, const char *filePath);
-void *readStreamToG(void *none UNUSED, FILE *fp);
+void *readFileToNewG(void *none UNUSED, const char *filePath);
+void *readStreamToNewG(void *none UNUSED, FILE *fp);
+char *readFileToG(char **string, const char *filePath);
+char *readStreamToG(char **string, FILE *fp);
void readTextSmallJsonNotSupported(char **self UNUSED, smallJsont *path UNUSED);
void readTextSmallStringNotSupported(char **self UNUSED, smallStringt *path UNUSED);
@@ -9965,8 +9995,8 @@ int writeStreamFromG(const char *string, FILE *fp);
/**
* call readText (for readFileG)
*/
-char **readTextSG(char **retType UNUSED, const char *filePath);
-char **readTextStreamG(char **retType UNUSED, FILE *fp);
+char **readTextSG(char ***list, const char *filePath);
+char **readTextStreamG(char ***list, FILE *fp);
/**
* call writeText (for writeFileG)