diff options
author | Carl Worth <cworth@cworth.org> | 2007-04-19 13:54:50 -0700 |
---|---|---|
committer | Carl Worth <cworth@cworth.org> | 2007-04-25 11:27:33 -0700 |
commit | 876786b3f7316b99a51ba8225e34581be13a883d (patch) | |
tree | a8b1c8ef61bd25492a75eeffcfd96d534da50ecf /perf | |
parent | 90d532e08f25644c4e621b0b7e592f4531a39d88 (diff) | |
download | cairo-876786b3f7316b99a51ba8225e34581be13a883d.tar.gz |
Move implementation of getline and strndup
These kept getting in my way as I looked for structure declarations
at the top of the file.
Diffstat (limited to 'perf')
-rw-r--r-- | perf/cairo-perf-diff-files.c | 108 |
1 files changed, 53 insertions, 55 deletions
diff --git a/perf/cairo-perf-diff-files.c b/perf/cairo-perf-diff-files.c index 42c2ea11f..290b94195 100644 --- a/perf/cairo-perf-diff-files.c +++ b/perf/cairo-perf-diff-files.c @@ -27,7 +27,7 @@ #include "cairo-perf.h" -/* We use _GNU_SOURCE for getline and strndup. */ +/* We use _GNU_SOURCE for getline and strndup if available. */ #ifndef _GNU_SOURCE # define _GNU_SOURCE #endif @@ -38,60 +38,6 @@ #include <ctype.h> #include <math.h> -/* We conditionally provide a custom implementation of getline and strndup - * as needed. These aren't necessary full-fledged general purpose - * implementations. They just get the job done for our purposes. - */ -#ifndef __USE_GNU - -#define POORMANS_GETLINE_BUFFER_SIZE (65536) -ssize_t -getline (char **lineptr, size_t *n, FILE *stream) -{ - if (!*lineptr) - { - *n = POORMANS_GETLINE_BUFFER_SIZE; - *lineptr = (char *) malloc (*n); - } - - if (!fgets (*lineptr, *n, stream)) - return -1; - - if (!feof (stream) && !strchr (*lineptr, '\n')) - { - fprintf (stderr, "The poor man's implementation of getline in " - __FILE__ " needs a bigger buffer. Perhaps it's " - "time for a complete implementation of getline.\n"); - exit (0); - } - - return strlen (*lineptr); -} -#undef POORMANS_GETLINE_BUFFER_SIZE - -char * -strndup (const char *s, size_t n) -{ - size_t len; - char *sdup; - - if (!s) - return NULL; - - len = strlen (s); - len = (n < len ? n : len); - sdup = (char *) malloc (len + 1); - if (sdup) - { - memcpy (sdup, s, len); - sdup[len] = '\0'; - } - - return sdup; -} - -#endif /* ifndef __USE_GNU */ - typedef struct _test_report { int id; char *backend; @@ -285,6 +231,58 @@ test_report_parse (test_report_t *report, char *line) return TEST_REPORT_STATUS_SUCCESS; } +/* We conditionally provide a custom implementation of getline and strndup + * as needed. These aren't necessary full-fledged general purpose + * implementations. They just get the job done for our purposes. + */ +#ifndef __USE_GNU +#define POORMANS_GETLINE_BUFFER_SIZE (65536) +ssize_t +getline (char **lineptr, size_t *n, FILE *stream) +{ + if (!*lineptr) + { + *n = POORMANS_GETLINE_BUFFER_SIZE; + *lineptr = (char *) malloc (*n); + } + + if (!fgets (*lineptr, *n, stream)) + return -1; + + if (!feof (stream) && !strchr (*lineptr, '\n')) + { + fprintf (stderr, "The poor man's implementation of getline in " + __FILE__ " needs a bigger buffer. Perhaps it's " + "time for a complete implementation of getline.\n"); + exit (0); + } + + return strlen (*lineptr); +} +#undef POORMANS_GETLINE_BUFFER_SIZE + +char * +strndup (const char *s, size_t n) +{ + size_t len; + char *sdup; + + if (!s) + return NULL; + + len = strlen (s); + len = (n < len ? n : len); + sdup = (char *) malloc (len + 1); + if (sdup) + { + memcpy (sdup, s, len); + sdup[len] = '\0'; + } + + return sdup; +} +#endif /* ifndef __USE_GNU */ + static void cairo_perf_report_load (cairo_perf_report_t *report, const char *filename) { |