return s;
}
+/*
+ * Bacula's implementation of fgets(). The difference is that it handles
+ * being interrupted by a signal (e.g. a SIGCHLD) and it has a
+ * different calling sequence which implements input lines of
+ * up to a million characters.
+ */
+char *bfgets(POOLMEM *&s, FILE *fd)
+{
+ int ch;
+ int soft_max;
+ int i = 0;
+
+ s[0] = 0;
+ soft_max = sizeof_pool_memory(s) - 10;
+ for ( ;; ) {
+ do {
+ errno = 0;
+ ch = fgetc(fd);
+ } while (ch == EOF && ferror(fd) && (errno == EINTR || errno == EAGAIN));
+ if (ch == EOF) {
+ if (i == 0) {
+ return NULL;
+ } else {
+ return s;
+ }
+ }
+ if (i > soft_max) {
+ /* Insanity check */
+ if (soft_max > 1000000) {
+ return s;
+ }
+ s = check_pool_memory_size(s, soft_max+10000);
+ soft_max = sizeof_pool_memory(s) - 10;
+ }
+ s[i++] = ch;
+ s[i] = 0;
+ if (ch == '\r') { /* Support for Mac/Windows file format */
+ ch = fgetc(fd);
+ if (ch != '\n') { /* Mac (\r only) */
+ (void)ungetc(ch, fd); /* Push next character back to fd */
+ }
+ s[i-1] = '\n';
+ break;
+ }
+ if (ch == '\n') {
+ break;
+ }
+ }
+ return s;
+}
+
/*
* Make a "unique" filename. It is important that if
* called again with the same "what" that the result
}
Dmsg1(dbglvl, "Close cfg file %s\n", lf->fname);
free(lf->fname);
+ free_memory(lf->line);
+ lf->line = NULL;
if (of) {
of->options = lf->options; /* preserve options */
memcpy(lf, of, sizeof(LEX));
BPIPE *bpipe = NULL;
char *fname = bstrdup(filename);
-
if (fname[0] == '|') {
if ((bpipe = open_bpipe(fname+1, 0, "rb")) == NULL) {
free(fname);
lf->fd = fd;
lf->bpipe = bpipe;
lf->fname = fname;
+ lf->line = get_memory(5000);
lf->state = lex_none;
lf->ch = L_EOL;
Dmsg1(dbglvl, "Return lex=%x\n", lf);
" You may have a open double quote without the closing double quote.\n"));
}
if (lf->ch == L_EOL) {
- if (bfgets(lf->line, MAXSTRING, lf->fd) == NULL) {
+ if (bfgets(lf->line, lf->fd) == NULL) {
lf->ch = L_EOF;
if (lf->next) {
lex_close_file(lf);
/*
Bacula® - The Network Backup Solution
- Copyright (C) 2000-2007 Free Software Foundation Europe e.V.
+ Copyright (C) 2000-2012 Free Software Foundation Europe e.V.
The main author of Bacula is Kern Sibbald, with contributions from
many others, a complete list can be found in the file AUTHORS.
*
* Kern Sibbald, MM
*
- * Version $Id$
- *
*/
#ifndef _LEX_H
int options; /* scan options */
char *fname; /* filename */
FILE *fd; /* file descriptor */
- char line[MAXSTRING]; /* input line */
+ POOLMEM *line; /* input line */
char str[MAXSTRING]; /* string being scanned */
int str_len; /* length of string */
int line_no; /* file line number */
/*
Bacula® - The Network Backup Solution
- Copyright (C) 2000-2010 Free Software Foundation Europe e.V.
+ Copyright (C) 2000-2012 Free Software Foundation Europe e.V.
The main author of Bacula is Kern Sibbald, with contributions from
many others, a complete list can be found in the file AUTHORS.
void drop (char *uid, char *gid, bool keep_readall_caps);
int bmicrosleep (int32_t sec, int32_t usec);
char *bfgets (char *s, int size, FILE *fd);
+char *bfgets (POOLMEM *&s, FILE *fd);
void make_unique_filename (POOLMEM **name, int Id, char *what);
#ifndef HAVE_STRTOLL
long long int strtoll (const char *ptr, char **endptr, int base);