summaryrefslogtreecommitdiff
path: root/nuttx
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2007-06-09 19:45:33 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2007-06-09 19:45:33 +0000
commitc632e36db2bb7262cb645c7d59f0c3858621e390 (patch)
tree94d44478d502605c68c8de0ea61b665f891a4c1c /nuttx
parentcf0426d5964d50da8b21db6549ed19a987ee85e2 (diff)
downloadpx4-nuttx-c632e36db2bb7262cb645c7d59f0c3858621e390.tar.gz
px4-nuttx-c632e36db2bb7262cb645c7d59f0c3858621e390.tar.bz2
px4-nuttx-c632e36db2bb7262cb645c7d59f0c3858621e390.zip
No longer uses _GNU_SOURCE-specific asprintf()
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@276 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx')
-rw-r--r--nuttx/ChangeLog2
-rw-r--r--nuttx/Documentation/NuttX.html2
-rw-r--r--nuttx/tools/mkconfig.c18
3 files changed, 16 insertions, 6 deletions
diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog
index d5f148c2c..c02857e72 100644
--- a/nuttx/ChangeLog
+++ b/nuttx/ChangeLog
@@ -169,5 +169,7 @@
* Restructured some Makefiles to better handle enabling and disabling
NuttX features without having so much conditional compilation in the
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
diff --git a/nuttx/Documentation/NuttX.html b/nuttx/Documentation/NuttX.html
index 32ce071ba..1adab64be 100644
--- a/nuttx/Documentation/NuttX.html
+++ b/nuttx/Documentation/NuttX.html
@@ -603,6 +603,8 @@ Other memory:
* Restructured some Makefiles to better handle enabling and disabling
NuttX features without having so much conditional compilation in the
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
</pre></ul>
diff --git a/nuttx/tools/mkconfig.c b/nuttx/tools/mkconfig.c
index b9c91598c..20611ff1e 100644
--- a/nuttx/tools/mkconfig.c
+++ b/nuttx/tools/mkconfig.c
@@ -33,16 +33,16 @@
*
************************************************************/
-#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <limits.h>
#include <ctype.h>
#include <unistd.h>
#include <errno.h>
#define DEFCONFIG ".config"
-#define LINESIZE 256
+#define LINESIZE ( PATH_MAX > 256 ? PATH_MAX : 256 )
static char line[LINESIZE+1];
@@ -154,6 +154,13 @@ static void parse_file(FILE *stream)
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)
{
fprintf(stderr, "USAGE: %s <abs path to .config>\n", progname);
@@ -164,7 +171,6 @@ int main(int argc, char **argv, char **envp)
{
char *filepath;
FILE *stream;
- int status;
if (argc != 2)
{
@@ -172,10 +178,10 @@ int main(int argc, char **argv, char **envp)
show_usage(argv[0]);
}
- status = asprintf(&filepath, "%s/" DEFCONFIG, argv[1]);
- if (status < 0)
+ filepath = getfilepath(argv[1]);
+ if (!filepath)
{
- fprintf(stderr, "asprintf failed\n");
+ fprintf(stderr, "getfilepath failed\n");
exit(2);
}