p: pcat pcat-diff pcat-print
-pcat: pcat.o
+pcat: pcat.o getdelim.o
$(LINK) -o $@ $+
-pcat-diff: pcat-diff.o
+pcat-diff: pcat-diff.o getdelim.o
$(LINK) -o $@ $+
-pcat-print: pcat-print.o
+pcat-print: pcat-print.o getdelim.o
$(LINK) -o $@ $+
clean:
rm -f pcat pcat-diff pcat-print
+ rm -f pcat.o pcat-diff.o pcat-print.o
realclean: clean
rm -f configure config.h config.log config.status
--- /dev/null
+#ifndef HAVE_GETDELIM
+
+#include "config.h"
+
+#define GETDELIM_BUFFER 128
+
+/* copied from xine-devel */
+ssize_t
+getdelim( char **lineptr, size_t *n, int delimiter, FILE *stream )
+{
+ char *p;
+ int c;
+ size_t len = 0;
+
+ if (!lineptr || !n || (!*lineptr && *n))
+ return -1;
+
+ /* allocate initial buffer */
+ if (!*lineptr || !*n) {
+ char *np;
+ np = realloc( *lineptr, GETDELIM_BUFFER );
+ if (!np)
+ return -1;
+ *n = GETDELIM_BUFFER;
+ *lineptr = np;
+ }
+
+ p = *lineptr;
+
+ /* read characters from stream */
+ while ((c = fgetc( stream )) != EOF) {
+ if (len >= *n) {
+ char *np = realloc( *lineptr, *n * 2 );
+ if (!np)
+ return -1;
+ p = np + (p - *lineptr);
+ *lineptr = np;
+ *n *= 2;
+ }
+ *p++ = (char) c;
+ len++;
+ if (delimiter == c)
+ break;
+ }
+
+ /* end of file without any bytes read */
+ if ((c == EOF) && (len == 0))
+ return -1;
+
+ /* trailing "\0" */
+ if (len >= *n) {
+ char *np = realloc( *lineptr, *n + 1 );
+ if (!np)
+ return -1;
+ p = np + (p - *lineptr);
+ *lineptr = np;
+ *n += 1;
+ }
+ *p = '\0';
+
+ return len;
+}
+
+#endif /* !HAVE_GETDELIM */
i = 1;
reread:
- read1 = getline(&line1, &len1, trace1);
- read2 = getline(&line2, &len2, trace2);
+ read1 = getdelim(&line1, &len1, '\n', trace1);
+ read2 = getdelim(&line2, &len2, '\n', trace2);
if (read1 == -1 || read2 == -1) {
fclose(trace1); fclose(trace2);
exit(EXIT_SUCCESS);
#define ANSWER1 3
#define ANSWER2 0
+#ifndef HAVE_GETDELIM
+ssize_t getdelim(char **lineptr, size_t *n, int delim, FILE *stream);
+#endif
+
void
usage(FILE *fp)
{
}
}
- while((read = getline(&line, &len, diff)) != -1) {
+ while((read = getdelim(&line, &len, '\n', diff)) != -1) {
if (read < 2 || read > LDNS_MAX_PACKETLEN) {
fprintf(stderr, "Under- or overflow - skipping line %zd\n", i);
i++;
#endif
#define DNS_UDP_OFFSET 42
+#ifndef HAVE_GETDELIM
+ssize_t getdelim(char **lineptr, size_t *n, int delim, FILE *stream);
+#endif
+
/* output: see usage() */
void