summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2016-11-16 16:54:38 +0000
committerJeremy Allison <jra@samba.org>2016-11-20 02:28:11 +0100
commitc06b78d0be5066c7e56c7715798f5a7b0b676451 (patch)
tree7a8f6e11d8aba135a5da766cae94d041d5c1359a
parent8742d239b2ee0d4dd3219c140081f722644044ae (diff)
downloadsamba-c06b78d0be5066c7e56c7715798f5a7b0b676451.tar.gz
lib: Move x_fgets_slash to xfile.c
This makes it easier to remove the global #include xfile.h Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
-rw-r--r--lib/util/samba_util.h7
-rw-r--r--lib/util/util_file.c92
-rw-r--r--lib/util/xfile.c94
-rw-r--r--lib/util/xfile.h7
4 files changed, 101 insertions, 99 deletions
diff --git a/lib/util/samba_util.h b/lib/util/samba_util.h
index 74adb25df24..2f8de9e7890 100644
--- a/lib/util/samba_util.h
+++ b/lib/util/samba_util.h
@@ -333,13 +333,6 @@ const char **str_list_make_v3_const(TALLOC_CTX *mem_ctx,
/**
-read a line from a file with possible \ continuation chars.
-Blanks at the start or end of a line are stripped.
-The string will be allocated if s2 is NULL
-**/
-_PUBLIC_ char *x_fgets_slash(char *s2,int maxlen,XFILE *f);
-
-/**
* Read one line (data until next newline or eof) and allocate it
*/
_PUBLIC_ char *afdgets(int fd, TALLOC_CTX *mem_ctx, size_t hint);
diff --git a/lib/util/util_file.c b/lib/util/util_file.c
index 52749ea0509..4948afb16b6 100644
--- a/lib/util/util_file.c
+++ b/lib/util/util_file.c
@@ -27,98 +27,6 @@
#include "lib/util/debug.h"
/**
- * @file
- * @brief File-related utility functions
- */
-
-/**
-read a line from a file with possible \ continuation chars.
-Blanks at the start or end of a line are stripped.
-The string will be allocated if s2 is NULL
-**/
-_PUBLIC_ char *x_fgets_slash(char *s2,int maxlen,XFILE *f)
-{
- char *s=s2;
- int len = 0;
- int c;
- bool start_of_line = true;
-
- if (x_feof(f)) {
- return(NULL);
- }
-
- if (maxlen <2) {
- return(NULL);
- }
-
- if (!s2) {
- maxlen = MIN(maxlen,8);
- s = (char *)malloc(maxlen);
- }
-
- if (!s) {
- return(NULL);
- }
-
- *s = 0;
-
- while (len < maxlen-1) {
- c = x_getc(f);
- switch (c)
- {
- case '\r':
- break;
- case '\n':
- while (len > 0 && s[len-1] == ' ') {
- s[--len] = 0;
- }
- if (len > 0 && s[len-1] == '\\') {
- s[--len] = 0;
- start_of_line = true;
- break;
- }
- return(s);
- case EOF:
- if (len <= 0 && !s2) {
- SAFE_FREE(s);
- }
- return(len>0?s:NULL);
- case ' ':
- if (start_of_line) {
- break;
- }
- /* fall through */
- default:
- start_of_line = false;
- s[len++] = c;
- s[len] = 0;
- }
- if (!s2 && len > maxlen-3) {
- int m;
- char *t;
-
- m = maxlen * 2;
- if (m < maxlen) {
- DBG_ERR("length overflow");
- SAFE_FREE(s);
- return NULL;
- }
- maxlen = m;
-
- t = realloc_p(s, char, maxlen);
- if (!t) {
- DBG_ERR("failed to expand buffer!\n");
- SAFE_FREE(s);
- return(NULL);
- }
-
- s = t;
- }
- }
- return(s);
-}
-
-/**
* Read one line (data until next newline or eof) and allocate it
*/
_PUBLIC_ char *afdgets(int fd, TALLOC_CTX *mem_ctx, size_t hint)
diff --git a/lib/util/xfile.c b/lib/util/xfile.c
index 62dd1213a75..b22cb9871f2 100644
--- a/lib/util/xfile.c
+++ b/lib/util/xfile.c
@@ -37,6 +37,8 @@
#include "system/filesys.h"
#include "memory.h"
#include "xfile.h"
+#include "lib/util/debug.h"
+#include "lib/util/samba_util.h"
#define XBUFSIZE BUFSIZ
@@ -428,3 +430,95 @@ XFILE *x_fdup(const XFILE *f)
x_setvbuf(ret, NULL, X_IOFBF, XBUFSIZE);
return ret;
}
+
+/**
+ * @file
+ * @brief File-related utility functions
+ */
+
+/**
+read a line from a file with possible \ continuation chars.
+Blanks at the start or end of a line are stripped.
+The string will be allocated if s2 is NULL
+**/
+char *x_fgets_slash(char *s2,int maxlen,XFILE *f)
+{
+ char *s=s2;
+ int len = 0;
+ int c;
+ bool start_of_line = true;
+
+ if (x_feof(f)) {
+ return(NULL);
+ }
+
+ if (maxlen <2) {
+ return(NULL);
+ }
+
+ if (!s2) {
+ maxlen = MIN(maxlen,8);
+ s = (char *)malloc(maxlen);
+ }
+
+ if (!s) {
+ return(NULL);
+ }
+
+ *s = 0;
+
+ while (len < maxlen-1) {
+ c = x_getc(f);
+ switch (c)
+ {
+ case '\r':
+ break;
+ case '\n':
+ while (len > 0 && s[len-1] == ' ') {
+ s[--len] = 0;
+ }
+ if (len > 0 && s[len-1] == '\\') {
+ s[--len] = 0;
+ start_of_line = true;
+ break;
+ }
+ return(s);
+ case EOF:
+ if (len <= 0 && !s2) {
+ SAFE_FREE(s);
+ }
+ return(len>0?s:NULL);
+ case ' ':
+ if (start_of_line) {
+ break;
+ }
+ /* fall through */
+ default:
+ start_of_line = false;
+ s[len++] = c;
+ s[len] = 0;
+ }
+ if (!s2 && len > maxlen-3) {
+ int m;
+ char *t;
+
+ m = maxlen * 2;
+ if (m < maxlen) {
+ DBG_ERR("length overflow");
+ SAFE_FREE(s);
+ return NULL;
+ }
+ maxlen = m;
+
+ t = realloc_p(s, char, maxlen);
+ if (!t) {
+ DBG_ERR("failed to expand buffer!\n");
+ SAFE_FREE(s);
+ return(NULL);
+ }
+
+ s = t;
+ }
+ }
+ return(s);
+}
diff --git a/lib/util/xfile.h b/lib/util/xfile.h
index f52596dc8a8..5fb6341dfc7 100644
--- a/lib/util/xfile.h
+++ b/lib/util/xfile.h
@@ -104,4 +104,11 @@ off_t x_tseek(XFILE *f, off_t offset, int whence);
XFILE *x_fdup(const XFILE *f);
+/**
+read a line from a file with possible \ continuation chars.
+Blanks at the start or end of a line are stripped.
+The string will be allocated if s2 is NULL
+**/
+_PUBLIC_ char *x_fgets_slash(char *s2,int maxlen,XFILE *f);
+
#endif /* _XFILE_H_ */