summaryrefslogtreecommitdiff
path: root/nasmlib
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@linux.intel.com>2017-12-20 13:33:49 -0800
committerH. Peter Anvin <hpa@linux.intel.com>2017-12-20 13:38:20 -0800
commit81b62b9f54ac8e4019a9b2ec2b95ec0faa86bd2a (patch)
tree5339576fc296a92504dbc5a07a8a97c2de4896ab /nasmlib
parentdcbaf677d4b5118d427a3a3b45a3499e22fa8635 (diff)
downloadnasm-81b62b9f54ac8e4019a9b2ec2b95ec0faa86bd2a.tar.gz
Eliminate filename length restrictions, remote ofmt->filename()
Get rid of remaining dependencies on FILENAME_MAX, which ought to have been removed a long time ago. Remove ofmt->filename(); all implementations pretty much do the same thing and there is absolutely no reason to duplicate that functionality all over the place. Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Diffstat (limited to 'nasmlib')
-rw-r--r--nasmlib/filename.c50
1 files changed, 22 insertions, 28 deletions
diff --git a/nasmlib/filename.c b/nasmlib/filename.c
index 799eb89a..172ae0bc 100644
--- a/nasmlib/filename.c
+++ b/nasmlib/filename.c
@@ -1,6 +1,6 @@
/* ----------------------------------------------------------------------- *
- *
- * Copyright 1996-2016 The NASM Authors - All Rights Reserved
+ *
+ * Copyright 1996-2017 The NASM Authors - All Rights Reserved
* See the file AUTHORS included with the NASM distribution for
* the specific copyright holders.
*
@@ -14,7 +14,7 @@
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
@@ -39,31 +39,25 @@
#include "nasmlib.h"
#include "error.h"
-void standard_extension(char *inname, char *outname, char *extension)
+/*
+ * Add/modify a filename extension, assumed to be a period-delimited
+ * field at the very end of the filename. Returns a newly allocated
+ * string buffer.
+ */
+const char *filename_set_extension(const char *inname, const char *extension)
{
- char *p, *q;
+ const char *q = inname;
+ char *p;
+ size_t elen = strlen(extension);
+ size_t baselen;
+
+ q = strrchrnul(inname, '.'); /* find extension or end of string */
+ baselen = q - inname;
+
+ p = nasm_malloc(baselen + elen + 1);
+
+ memcpy(p, inname, baselen);
+ memcpy(p+baselen, extension, elen+1);
- if (*outname) /* file name already exists, */
- return; /* so do nothing */
- q = inname;
- p = outname;
- while (*q)
- *p++ = *q++; /* copy, and find end of string */
- *p = '\0'; /* terminate it */
- while (p > outname && *--p != '.') ; /* find final period (or whatever) */
- if (*p != '.')
- while (*p)
- p++; /* go back to end if none found */
- if (!strcmp(p, extension)) { /* is the extension already there? */
- if (*extension)
- nasm_error(ERR_WARNING | ERR_NOFILE,
- "file name already ends in `%s': "
- "output will be in `nasm.out'", extension);
- else
- nasm_error(ERR_WARNING | ERR_NOFILE,
- "file name already has no extension: "
- "output will be in `nasm.out'");
- strcpy(outname, "nasm.out");
- } else
- strcpy(p, extension);
+ return p;
}