9
0
Fork 0

No longer uses _GNU_SOURCE-specific asprintf()

git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@276 7fd9a85b-ad96-42d3-883c-3090e2eb8679
This commit is contained in:
patacongo 2007-06-09 19:45:33 +00:00
parent bf0ca7304d
commit 2965087942
3 changed files with 16 additions and 6 deletions

View File

@ -169,5 +169,7 @@
* Restructured some Makefiles to better handle enabling and disabling * Restructured some Makefiles to better handle enabling and disabling
NuttX features without having so much conditional compilation in the NuttX features without having so much conditional compilation in the
source files. source files.
* tools/mkconfig.c: No long depends on asprintf() and _GNU_SOURCE and
so should now build in non-GNU, non-GLIBC environments.
* Started m68322 * Started m68322

View File

@ -603,6 +603,8 @@ Other memory:
* Restructured some Makefiles to better handle enabling and disabling * Restructured some Makefiles to better handle enabling and disabling
NuttX features without having so much conditional compilation in the NuttX features without having so much conditional compilation in the
source files. source files.
* tools/mkconfig.c: No long depends on asprintf() and _GNU_SOURCE and
so should now build in non-GNU, non-GLIBC environments.
* Started m68322 * Started m68322
</pre></ul> </pre></ul>

View File

@ -33,16 +33,16 @@
* *
************************************************************/ ************************************************************/
#define _GNU_SOURCE
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <limits.h>
#include <ctype.h> #include <ctype.h>
#include <unistd.h> #include <unistd.h>
#include <errno.h> #include <errno.h>
#define DEFCONFIG ".config" #define DEFCONFIG ".config"
#define LINESIZE 256 #define LINESIZE ( PATH_MAX > 256 ? PATH_MAX : 256 )
static char line[LINESIZE+1]; static char line[LINESIZE+1];
@ -154,6 +154,13 @@ static void parse_file(FILE *stream)
while (ptr); while (ptr);
} }
static inline char *getfilepath(const char *name)
{
snprintf(line, PATH_MAX, "%s/" DEFCONFIG, name);
line[PATH_MAX] = '\0';
return strdup(line);
}
static void show_usage(const char *progname) static void show_usage(const char *progname)
{ {
fprintf(stderr, "USAGE: %s <abs path to .config>\n", progname); fprintf(stderr, "USAGE: %s <abs path to .config>\n", progname);
@ -164,7 +171,6 @@ int main(int argc, char **argv, char **envp)
{ {
char *filepath; char *filepath;
FILE *stream; FILE *stream;
int status;
if (argc != 2) if (argc != 2)
{ {
@ -172,10 +178,10 @@ int main(int argc, char **argv, char **envp)
show_usage(argv[0]); show_usage(argv[0]);
} }
status = asprintf(&filepath, "%s/" DEFCONFIG, argv[1]); filepath = getfilepath(argv[1]);
if (status < 0) if (!filepath)
{ {
fprintf(stderr, "asprintf failed\n"); fprintf(stderr, "getfilepath failed\n");
exit(2); exit(2);
} }