projects
/
gnulib.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
maint: remove empty lines at EOF, but excluding modules/*
[gnulib.git]
/
tests
/
test-getdelim.c
diff --git
a/tests/test-getdelim.c
b/tests/test-getdelim.c
index
da4fe6b
..
08c6197
100644
(file)
--- a/
tests/test-getdelim.c
+++ b/
tests/test-getdelim.c
@@
-1,5
+1,5
@@
/* Test of getdelim() function.
/* Test of getdelim() function.
- Copyright (C) 2007-20
09
Free Software Foundation, Inc.
+ Copyright (C) 2007-20
12
Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@
-20,32
+20,26
@@
#include <config.h>
#include <stdio.h>
#include <config.h>
#include <stdio.h>
+
+#include "signature.h"
+SIGNATURE_CHECK (getdelim, ssize_t, (char **, size_t *, int, FILE *));
+
#include <stdlib.h>
#include <string.h>
#include <stdlib.h>
#include <string.h>
-#define ASSERT(expr) \
- do \
- { \
- if (!(expr)) \
- { \
- fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
- fflush (stderr); \
- abort (); \
- } \
- } \
- while (0)
+#include "macros.h"
int
main (void)
{
FILE *f;
int
main (void)
{
FILE *f;
- char *line
= NULL
;
- size_t len
= 0
;
+ char *line;
+ size_t len;
ssize_t result;
/* Create test file. */
f = fopen ("test-getdelim.txt", "wb");
ssize_t result;
/* Create test file. */
f = fopen ("test-getdelim.txt", "wb");
- if (!f || fwrite ("an
bcnd\0f", 1, 8, f) != 8
|| fclose (f) != 0)
+ if (!f || fwrite ("an
Anbcnd\0f", 1, 10, f) != 10
|| fclose (f) != 0)
{
fputs ("Failed to create sample file.\n", stderr);
remove ("test-getdelim.txt");
{
fputs ("Failed to create sample file.\n", stderr);
remove ("test-getdelim.txt");
@@
-60,13
+54,24
@@
main (void)
}
/* Test initial allocation, which must include trailing NUL. */
}
/* Test initial allocation, which must include trailing NUL. */
+ line = NULL;
+ len = 0;
result = getdelim (&line, &len, 'n', f);
ASSERT (result == 2);
ASSERT (strcmp (line, "an") == 0);
ASSERT (2 < len);
result = getdelim (&line, &len, 'n', f);
ASSERT (result == 2);
ASSERT (strcmp (line, "an") == 0);
ASSERT (2 < len);
+ free (line);
- /* Test growth of buffer. */
+ /* Test initial allocation again, with line = NULL and len != 0. */
+ line = NULL;
+ len = (size_t)(~0) / 4;
+ result = getdelim (&line, &len, 'n', f);
+ ASSERT (result == 2);
+ ASSERT (strcmp (line, "An") == 0);
+ ASSERT (2 < len);
free (line);
free (line);
+
+ /* Test growth of buffer. */
line = malloc (1);
len = 1;
result = getdelim (&line, &len, 'n', f);
line = malloc (1);
len = 1;
result = getdelim (&line, &len, 'n', f);