/* The following definitions come from lib/util/util_file.c */
-/**
-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
*/
#include "lib/util/samba_util.h"
#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
*/
#include "system/filesys.h"
#include "memory.h"
#include "xfile.h"
+#include "lib/util/debug.h"
+#include "lib/util/samba_util.h"
#define XBUFSIZE BUFSIZ
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);
+}
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_ */