mirror of
https://sourceware.org/git/glibc.git
synced 2025-10-27 12:15:39 +03:00
Without _GNU_SOURCE defined this file fails to compile with the
following error:
$ gcc manual/examples/strdupa.c
manual/examples/strdupa.c: In function ‘main’:
manual/examples/strdupa.c:27:19: error: implicit declaration of function ‘strdupa’; did you mean ‘strdup’? [-Wimplicit-function-declaration]
27 | char *wr_path = strdupa (path);
| ^~~~~~~
| strdup
manual/examples/strdupa.c:27:19: error: initialization of ‘char *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion]
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
38 lines
1.0 KiB
C
38 lines
1.0 KiB
C
/* strdupa example.
|
|
Copyright (C) 1991-2025 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 the Free Software Foundation; either version 2
|
|
of the License, or (at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; if not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#define _GNU_SOURCE 1
|
|
#include <paths.h>
|
|
#include <string.h>
|
|
#include <stdio.h>
|
|
|
|
const char path[] = _PATH_STDPATH;
|
|
|
|
int
|
|
main (void)
|
|
{
|
|
char *wr_path = strdupa (path);
|
|
char *cp = strtok (wr_path, ":");
|
|
|
|
while (cp != NULL)
|
|
{
|
|
puts (cp);
|
|
cp = strtok (NULL, ":");
|
|
}
|
|
return 0;
|
|
}
|