Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
ccan
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mirror
ccan
Commits
4c239570
Commit
4c239570
authored
Jun 10, 2014
by
Rusty Russell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
grab_file: don't use str_talloc for tests.
Signed-off-by:
Rusty Russell
<
rusty@rustcorp.com.au
>
parent
a2cb9a4f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
20 deletions
+37
-20
ccan/grab_file/_info
ccan/grab_file/_info
+0
-4
ccan/grab_file/grab_file.h
ccan/grab_file/grab_file.h
+13
-15
ccan/grab_file/test/run-grab.c
ccan/grab_file/test/run-grab.c
+24
-1
No files found.
ccan/grab_file/_info
View file @
4c239570
...
...
@@ -48,10 +48,6 @@ int main(int argc, char *argv[])
printf("ccan/noerr\n");
return 0;
}
if (strcmp(argv[1], "testdepends") == 0) {
printf("ccan/str_talloc\n");
return 0;
}
return 1;
}
ccan/grab_file/grab_file.h
View file @
4c239570
...
...
@@ -15,20 +15,18 @@
* byte after the end of the content will always be NUL.
*
* Example:
* #include <ccan/str_talloc/str_talloc.h>
* #include <ccan/talloc/talloc.h>
* ...
* // Return all of standard input, as lines.
* static char **read_stdin_as_lines(void)
* // Return the first line.
* static char *read_stdin_firstline(void)
* {
* char *
*lines, *al
l;
* char *
all, *n
l;
*
* all = grab_fd(NULL, 0, NULL);
* if (!all)
* return NULL;
* lines = strsplit(NULL, all, "\n");
* talloc_free(all);
* return lines;
* nl = strchr(all, '\n');
* if (nl)
* *nl = '\0';
* return all;
* }
*/
void
*
grab_fd
(
const
void
*
ctx
,
int
fd
,
size_t
*
size
);
...
...
@@ -45,17 +43,17 @@ void *grab_fd(const void *ctx, int fd, size_t *size);
* after the end of the content will always be NUL.
*
* Example:
* // Return all of a given file, as lines.
* static char **read_file_as_lines(const char *filename)
* static char *read_file_firstline(const char *filename)
* {
* char *
*lines
, *all;
* char *
nl
, *all;
*
* all = grab_file(NULL, filename, NULL);
* if (!all)
* return NULL;
* lines = strsplit(NULL, all, "\n");
* talloc_free(all);
* return lines;
* nl = strchr(all, '\n');
* if (nl)
* *nl = '\0';
* return all;
* }
*/
void
*
grab_file
(
const
void
*
ctx
,
const
char
*
filename
,
size_t
*
size
);
...
...
ccan/grab_file/test/run-grab.c
View file @
4c239570
...
...
@@ -7,7 +7,30 @@
#include <sys/stat.h>
#include <ccan/grab_file/grab_file.c>
#include <ccan/tap/tap.h>
#include <ccan/str_talloc/str_talloc.h>
#include <string.h>
static
char
**
strsplit
(
const
void
*
ctx
,
const
char
*
string
,
const
char
*
delims
)
{
char
**
lines
=
NULL
;
unsigned
int
max
=
64
,
num
=
0
;
lines
=
talloc_array
(
ctx
,
char
*
,
max
+
1
);
while
(
*
string
!=
'\0'
)
{
unsigned
int
len
=
strcspn
(
string
,
delims
);
lines
[
num
]
=
talloc_array
(
lines
,
char
,
len
+
1
);
memcpy
(
lines
[
num
],
string
,
len
);
lines
[
num
][
len
]
=
'\0'
;
string
+=
len
;
string
+=
strspn
(
string
,
delims
)
?
1
:
0
;
if
(
++
num
==
max
)
lines
=
talloc_realloc
(
ctx
,
lines
,
char
*
,
max
*=
2
+
1
);
}
lines
[
num
]
=
NULL
;
/* Shrink, so talloc_get_size works */
return
talloc_realloc
(
ctx
,
lines
,
char
*
,
num
+
1
);
}
int
main
(
int
argc
,
char
*
argv
[])
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment