Mercurial > hg > octave-lojdl > gnulib-hg
annotate lib/readtokens0.c @ 17298:d536543d59a6
statat: new module, split out from fstatat
GNU Emacs needs the POSIX-specified fstatat, but not the
gnulib-specified statat and lstat. Split the latter two into a
new module 'statat'.
* lib/openat.h: Depend on GNULIB_STATAT, not GNULIB_FSTATAT.
* lib/openat.h, lib/statat.c (STATAT_INLINE):
Rename from FSTATAT_INLINE. All uses changed.
* modules/fstatat (Files): Remove lib/statat.c.
(gl_MODULE_INDICATOR([fstatat])): Remove.
(lib_SOURCES): Remove.
(Maintainer): Add self.
* modules/statat, modules/statat-tests, tests/test-statat.c: New files.
* tests/test-fstatat.c (BASE): Don't define if already defined.
(do_stat, do_lstat) [!TEST_STATAT]: Test fstatat instead.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Wed, 23 Jan 2013 18:20:09 -0800 |
parents | e542fd46ad6f |
children |
rev | line source |
---|---|
5143 | 1 /* readtokens0.c -- Read NUL-separated tokens from an input stream. |
7302
8a1a9361108c
* _fpending.c: Include <config.h> unconditionally, since we no
Paul Eggert <eggert@cs.ucla.edu>
parents:
6259
diff
changeset
|
2 |
17249
e542fd46ad6f
maint: update all copyright year number ranges
Eric Blake <eblake@redhat.com>
parents:
16201
diff
changeset
|
3 Copyright (C) 2004, 2006, 2009-2013 Free Software Foundation, Inc. |
5143 | 4 |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
7302
diff
changeset
|
5 This program is free software: you can redistribute it and/or modify |
5143 | 6 it under the terms of the GNU General Public License as published by |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
7302
diff
changeset
|
7 the Free Software Foundation; either version 3 of the License, or |
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
7302
diff
changeset
|
8 (at your option) any later version. |
5143 | 9 |
10 This program is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 GNU General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU General Public License | |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
7302
diff
changeset
|
16 along with this program. If not, see <http://www.gnu.org/licenses/>. |
5143 | 17 |
18 Written by Jim Meyering. */ | |
19 | |
7302
8a1a9361108c
* _fpending.c: Include <config.h> unconditionally, since we no
Paul Eggert <eggert@cs.ucla.edu>
parents:
6259
diff
changeset
|
20 #include <config.h> |
8a1a9361108c
* _fpending.c: Include <config.h> unconditionally, since we no
Paul Eggert <eggert@cs.ucla.edu>
parents:
6259
diff
changeset
|
21 |
5143 | 22 #include <stdlib.h> |
23 | |
24 #include "readtokens0.h" | |
25 | |
26 #define obstack_chunk_alloc malloc | |
27 #define obstack_chunk_free free | |
28 | |
29 void | |
30 readtokens0_init (struct Tokens *t) | |
31 { | |
32 t->n_tok = 0; | |
33 t->tok = NULL; | |
34 t->tok_len = NULL; | |
35 obstack_init (&t->o_data); | |
36 obstack_init (&t->o_tok); | |
37 obstack_init (&t->o_tok_len); | |
38 } | |
39 | |
40 void | |
41 readtokens0_free (struct Tokens *t) | |
42 { | |
43 obstack_free (&t->o_data, NULL); | |
44 obstack_free (&t->o_tok, NULL); | |
45 obstack_free (&t->o_tok_len, NULL); | |
46 } | |
47 | |
48 /* Finalize (in the obstack_finish sense) the current token | |
49 and record its pointer and length. */ | |
50 static void | |
51 save_token (struct Tokens *t) | |
52 { | |
53 /* Don't count the trailing NUL byte in the length. */ | |
54 size_t len = obstack_object_size (&t->o_data) - 1; | |
55 char const *s = obstack_finish (&t->o_data); | |
56 obstack_ptr_grow (&t->o_tok, s); | |
57 obstack_grow (&t->o_tok_len, &len, sizeof len); | |
58 t->n_tok++; | |
59 } | |
60 | |
61 /* Read NUL-separated tokens from stream IN into T until EOF or error. | |
62 The final NUL is optional. Always append a NULL pointer to the | |
63 resulting list of token pointers, but that pointer isn't counted | |
64 via t->n_tok. Return true if successful. */ | |
65 bool | |
66 readtokens0 (FILE *in, struct Tokens *t) | |
67 { | |
68 | |
69 while (1) | |
70 { | |
71 int c = fgetc (in); | |
72 if (c == EOF) | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
73 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
74 size_t len = obstack_object_size (&t->o_data); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
75 /* If the current object has nonzero length, then there |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
76 was no NUL byte at EOF -- or maybe there was an error, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
77 in which case, we need to append a NUL byte to our buffer. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
78 if (len) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
79 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
80 obstack_1grow (&t->o_data, '\0'); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
81 save_token (t); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
82 } |
5143 | 83 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
84 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
85 } |
5143 | 86 |
87 obstack_1grow (&t->o_data, c); | |
88 if (c == '\0') | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
89 save_token (t); |
5143 | 90 } |
91 | |
92 /* Add a NULL pointer at the end, in case the caller (like du) | |
93 requires an argv-style array of strings. */ | |
94 obstack_ptr_grow (&t->o_tok, NULL); | |
95 | |
96 t->tok = obstack_finish (&t->o_tok); | |
97 t->tok_len = obstack_finish (&t->o_tok_len); | |
98 return ! ferror (in); | |
99 } |