summaryrefslogtreecommitdiff
path: root/src/mkheader.c
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2018-09-21 14:02:42 +0200
committerWerner Koch <wk@gnupg.org>2018-09-21 14:25:19 +0200
commit3fc4ce49b23a364a1cf255c8e9e259047206e1e8 (patch)
treef780452499d95ae6b2462bbfdfdff62ba2f33e9d /src/mkheader.c
parent15309d0fb4c78f8de9bc5dea7d0f8b7468a957b4 (diff)
downloadlibgpg-error-3fc4ce49b23a364a1cf255c8e9e259047206e1e8.tar.gz
core: Simplify calling convention of mkheader.
* src/Makefile.am (gpg-error.h): Remove HOST_OS from mkheader call. * src/mkheader.c (canon_host_triplet): Add return arg r_os. (main): Remove first arg and derive host_os from host_triplet. -- No need to let the caller pass the host_os, we can derive it from the triplet. Signed-off-by: Werner Koch <wk@gnupg.org>
Diffstat (limited to 'src/mkheader.c')
-rw-r--r--src/mkheader.c65
1 files changed, 40 insertions, 25 deletions
diff --git a/src/mkheader.c b/src/mkheader.c
index 7a38a1b..6071a20 100644
--- a/src/mkheader.c
+++ b/src/mkheader.c
@@ -22,8 +22,8 @@
#define LINESIZE 1024
-static const char *host_os;
-static char *host_triplet;
+static char *host_triplet; /* malloced. */
+static char *host_os; /* points into host_triplet. */
static char *srcdir;
static const char *hdr_version;
static const char *hdr_version_number;
@@ -78,12 +78,13 @@ xstrdup (const char *string)
/* Return a malloced string with TRIPLET. If TRIPLET has an alias
- return that instead. In general build-aux/config.sub should do the
- aliasing but some returned triplets are anyway identical and thus
- we use this function to map it to the canonical form.
- NO_VENDOR_HACK is for internal use; caller must call with 0. */
+ * return that instead. In general build-aux/config.sub should do the
+ * aliasing but some returned triplets are anyway identical and thus
+ * we use this function to map it to the canonical form. A pointer to
+ * the OS part of the returned value is stored at R_OS.
+ * NO_VENDOR_HACK is for internal use; caller must call with 0. */
static char *
-canon_host_triplet (const char *triplet, int no_vendor_hack)
+canon_host_triplet (const char *triplet, int no_vendor_hack, char **r_os)
{
struct {
const char *name;
@@ -117,6 +118,8 @@ canon_host_triplet (const char *triplet, int no_vendor_hack)
int i;
const char *lastalias = NULL;
const char *s;
+ char *p;
+ char *result;
for (i=0; tbl[i].name; i++)
{
@@ -126,7 +129,8 @@ canon_host_triplet (const char *triplet, int no_vendor_hack)
{
if (!lastalias)
break; /* Ooops: first entry has no alias. */
- return xstrdup (lastalias);
+ result = xstrdup (lastalias);
+ goto leave;
}
}
for (i=0, s=triplet; *s; s++)
@@ -139,7 +143,6 @@ canon_host_triplet (const char *triplet, int no_vendor_hack)
* The VENDOR part is then in general useless because
* KERNEL-SYSTEM is specific enough. We now do a second pass by
* replacing VENDOR with "unknown". */
- char *p;
char *buf = xmalloc (strlen (triplet) + 7 + 1);
for (p=buf,s=triplet,i=0; *s; s++)
@@ -154,12 +157,26 @@ canon_host_triplet (const char *triplet, int no_vendor_hack)
}
}
*p = 0;
- p = canon_host_triplet (buf, 1);
+ result = canon_host_triplet (buf, 1, NULL);
xfree (buf);
- return p;
+ goto leave;
+ }
+
+ result = xstrdup (triplet);
+ leave:
+ /* Find the OS part. */
+ if (r_os)
+ {
+ *r_os = result + strlen (result); /* Default to the empty string. */
+ for (i=0, p=result; *p; p++)
+ if (*p == '-' && ++i == 2)
+ {
+ *r_os = p+1;
+ break;
+ }
}
- return xstrdup (triplet);
+ return result;
}
@@ -176,7 +193,7 @@ parse_config_h (const char *fname)
fp = fopen (fname, "r");
if (!fp)
{
- fprintf (stderr, "%s:%d: can't open file: %s",
+ fprintf (stderr, "%s:%d: can't open file: %s\n",
fname, lnr, strerror (errno));
return 1;
}
@@ -623,30 +640,28 @@ main (int argc, char **argv)
if (argc == 1)
{
/* Print just the canonicalized host triplet. */
- host_triplet = canon_host_triplet (argv[0], 0);
+ host_triplet = canon_host_triplet (argv[0], 0, &host_os);
printf ("%s\n", host_triplet);
goto leave;
}
- else if (argc == 6)
+ else if (argc == 5)
; /* Standard operation. */
else
{
fputs ("usage: " PGM
- " host_os host_triplet template.h config.h"
- " version version_number\n"
+ " host_triplet template.h config.h version version_number\n"
" " PGM
" host_triplet\n",
stderr);
return 1;
}
- host_os = argv[0];
- host_triplet_raw = argv[1];
- fname = argv[2];
- config_h = argv[3];
- hdr_version = argv[4];
- hdr_version_number = argv[5];
+ host_triplet_raw = argv[0];
+ fname = argv[1];
+ config_h = argv[2];
+ hdr_version = argv[3];
+ hdr_version_number = argv[4];
- host_triplet = canon_host_triplet (host_triplet_raw, 0);
+ host_triplet = canon_host_triplet (host_triplet_raw, 0, &host_os);
srcdir = malloc (strlen (fname) + 2 + 1);
if (!srcdir)
@@ -667,7 +682,7 @@ main (int argc, char **argv)
fp = fopen (fname, "r");
if (!fp)
{
- fprintf (stderr, "%s:%d: can't open file: %s",
+ fprintf (stderr, "%s:%d: can't open file: %s\n",
fname, lnr, strerror (errno));
return 1;
}