Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Compiling config.c on Mac OS X (and very likely other BSDs) #15

Closed
wants to merge 1 commit into from

1 participant

Greg Kroah-Hartman
Deleted user
ghost commented

In order to compile bti, the symbols strndup, getline, strchrnul and dprintf are required.
However, these are missing on Mac OS X, as well as other BSD derivates.

This commit fixes at least getline and strchrnul (strndup and dprintf aren't annoying me, since I don't need url shortening).

Greg Kroah-Hartman
Owner
gregkh commented

getline is in POSIX 2008, the BSDs surely must support that by now.
strchrnul I can understand, but can you please rewrite it to look "sane" (i.e. without ?)

Greg Kroah-Hartman gregkh closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

May 22, 2011
Bo Samuel optinal getline-frontend via fgetln 5564e70
This page is out of date. Refresh to see the latest.

Showing 2 changed files with 32 additions and 2 deletions. Show diff stats Hide diff stats

  1. +29 2 config.c
  2. +3 0  configure.ac
31 config.c
@@ -321,6 +321,31 @@ static void process_line(struct session *session, char *key, char *value)
321 321 }
322 322 }
323 323
  324 +#ifndef HAVE_GETLINE
  325 +#ifdef HAVE_FGETLN
  326 +static inline ssize_t getline(char **lineptr, size_t *n, FILE *stream)
  327 +{
  328 + char *line;
  329 + size_t len;
  330 +
  331 + line = fgetln(stream, &len);
  332 + if (!line)
  333 + return -1;
  334 + if (len >= *n) {
  335 + char *tmp = realloc(*lineptr, len + 1);
  336 + if (tmp == NULL)
  337 + return -1;
  338 + *lineptr = tmp;
  339 + *n = len + 1;
  340 + }
  341 + memcpy(*lineptr, line, len);
  342 + return len;
  343 +}
  344 +#else
  345 +#error Need getline or fgetln to work
  346 +#endif
  347 +#endif
  348 +
324 349 void bti_parse_configfile(struct session *session)
325 350 {
326 351 FILE *config_file;
@@ -351,7 +376,7 @@ void bti_parse_configfile(struct session *session)
351 376 * marker if it occurs at the beginning of the line, or after
352 377 * whitespace
353 378 */
354   - hashmarker = strchrnul(line, '#');
  379 + hashmarker = strchr(line, '#') ?: &line[n - 1];
355 380 if (line == hashmarker)
356 381 line[0] = '\0';
357 382 else {
@@ -364,7 +389,7 @@ void bti_parse_configfile(struct session *session)
364 389 * false positive; '#' occured
365 390 * within a string
366 391 */
367   - hashmarker = strchrnul(hashmarker+2, '#');
  392 + hashmarker = strchr(hashmarker+2, '#') ?: &hashmarker[strlen(hashmarker)];
368 393 }
369 394 }
370 395 }
@@ -382,7 +407,9 @@ void bti_parse_configfile(struct session *session)
382 407 } while (!feof(config_file));
383 408
384 409 /* Free buffer and close file. */
  410 +#if defined(USE_GETLINE)
385 411 free(line);
  412 +#endif
386 413 fclose(config_file);
387 414 }
388 415
3  configure.ac
@@ -19,6 +19,9 @@ PKG_CHECK_MODULES(LIBPCRE, libpcre)
19 19 PKG_CHECK_MODULES([LIBCURL], [libcurl])
20 20 PKG_CHECK_MODULES([XML], [libxml-2.0])
21 21
  22 +AC_CHECK_FUNCS(getline)
  23 +AC_CHECK_FUNCS(fgetln)
  24 +
22 25 AC_SEARCH_LIBS([dlopen], [dl])
23 26
24 27 AC_CONFIG_FILES([Makefile])

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.