mirror of
https://gitlab.freedesktop.org/cairo/cairo.git
synced 2026-05-01 14:58:09 +02:00
Move implementation of getline and strndup
These kept getting in my way as I looked for structure declarations at the top of the file.
This commit is contained in:
parent
90d532e08f
commit
876786b3f7
1 changed files with 53 additions and 55 deletions
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue