Skip to content

Commit b36c1cc

Browse files
committed
libiberty: {count,dup,write}argv: constify argv input slightly
Would be more useful if we could use "const char * const *", but there's a long standing bug where gcc warns about incompatible pointers when you try to pass in "char **". We can at least constify the array itself as gcc will not warn in that case.
1 parent 2032176 commit b36c1cc

5 files changed

Lines changed: 23 additions & 12 deletions

File tree

‎include/ChangeLog‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2016-01-05 Mike Frysinger <vapier@gentoo.org>
2+
3+
* libiberty.h (dupargv): Change arg to char * const *.
4+
(writeargv, countargv): Likewise.
5+
16
2016-01-01 Alan Modra <amodra@gmail.com>
27

38
Update year range in copyright notice of all files.

‎include/libiberty.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,19 @@ extern void freeargv (char **);
8080
/* Duplicate an argument vector. Allocates memory using malloc. Use
8181
freeargv to free the vector. */
8282

83-
extern char **dupargv (char **) ATTRIBUTE_MALLOC;
83+
extern char **dupargv (char * const *) ATTRIBUTE_MALLOC;
8484

8585
/* Expand "@file" arguments in argv. */
8686

8787
extern void expandargv (int *, char ***);
8888

8989
/* Write argv to an @-file, inserting necessary quoting. */
9090

91-
extern int writeargv (char **, FILE *);
91+
extern int writeargv (char * const *, FILE *);
9292

9393
/* Return the number of elements in argv. */
9494

95-
extern int countargv (char**);
95+
extern int countargv (char * const *);
9696

9797
/* Return the last component of a path name. Note that we can't use a
9898
prototype here because the parameter is declared inconsistently

‎libiberty/ChangeLog‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
2016-01-05 Mike Frysinger <vapier@gentoo.org>
2+
3+
* argv.c (dupargv): Change arg to char * const *. Update comment.
4+
(writeargv, countargv): Likewise.
5+
* functions.texi (dupargv, writeargv, countargv): Likewise.
6+
17
2016-01-05 Mike Frysinger <vapier@gentoo.org>
28

39
* argv.c (dupargv): Replace strlen/xmalloc/strcpy with xstrdup.

‎libiberty/argv.c‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Boston, MA 02110-1301, USA. */
4949

5050
/*
5151
52-
@deftypefn Extension char** dupargv (char **@var{vector})
52+
@deftypefn Extension char** dupargv (char * const *@var{vector})
5353
5454
Duplicate an argument vector. Simply scans through @var{vector},
5555
duplicating each argument until the terminating @code{NULL} is found.
@@ -62,7 +62,7 @@ argument vector.
6262
*/
6363

6464
char **
65-
dupargv (char **argv)
65+
dupargv (char * const *argv)
6666
{
6767
int argc;
6868
char **copy;
@@ -279,7 +279,7 @@ char **buildargv (const char *input)
279279

280280
/*
281281
282-
@deftypefn Extension int writeargv (const char **@var{argv}, FILE *@var{file})
282+
@deftypefn Extension int writeargv (char * const *@var{argv}, FILE *@var{file})
283283
284284
Write each member of ARGV, handling all necessary quoting, to the file
285285
named by FILE, separated by whitespace. Return 0 on success, non-zero
@@ -290,7 +290,7 @@ if an error occurred while writing to FILE.
290290
*/
291291

292292
int
293-
writeargv (char **argv, FILE *f)
293+
writeargv (char * const *argv, FILE *f)
294294
{
295295
int status = 0;
296296

@@ -463,7 +463,7 @@ expandargv (int *argcp, char ***argvp)
463463

464464
/*
465465
466-
@deftypefn Extension int countargv (char **@var{argv})
466+
@deftypefn Extension int countargv (char * const *@var{argv})
467467
468468
Return the number of elements in @var{argv}.
469469
Returns zero if @var{argv} is NULL.
@@ -473,7 +473,7 @@ Returns zero if @var{argv} is NULL.
473473
*/
474474

475475
int
476-
countargv (char **argv)
476+
countargv (char * const *argv)
477477
{
478478
int argc;
479479

‎libiberty/functions.texi‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ Concatenate zero or more of strings and return the result in freshly
176176
@end deftypefn
177177

178178
@c argv.c:470
179-
@deftypefn Extension int countargv (char **@var{argv})
179+
@deftypefn Extension int countargv (char * const *@var{argv})
180180

181181
Return the number of elements in @var{argv}.
182182
Returns zero if @var{argv} is NULL.
@@ -213,7 +213,7 @@ make it easy to compose the values of multiple blocks.
213213
@end deftypefn
214214

215215
@c argv.c:52
216-
@deftypefn Extension char** dupargv (char **@var{vector})
216+
@deftypefn Extension char** dupargv (char * const *@var{vector})
217217

218218
Duplicate an argument vector. Simply scans through @var{vector},
219219
duplicating each argument until the terminating @code{NULL} is found.
@@ -1915,7 +1915,7 @@ does the return value. The third argument is unused in @libib{}.
19151915
@end deftypefn
19161916

19171917
@c argv.c:286
1918-
@deftypefn Extension int writeargv (const char **@var{argv}, FILE *@var{file})
1918+
@deftypefn Extension int writeargv (char * const *@var{argv}, FILE *@var{file})
19191919

19201920
Write each member of ARGV, handling all necessary quoting, to the file
19211921
named by FILE, separated by whitespace. Return 0 on success, non-zero

0 commit comments

Comments
 (0)