objfmt output.
svn path=/trunk/yasm/; revision=489
char *
-replace_extension(const char *orig, const char *ext, const char *def)
+replace_extension(const char *orig, /*@null@*/ const char *ext,
+ const char *def)
{
char *out, *outext;
/* allocate enough space for full existing name + extension */
- out = xmalloc(strlen(orig)+strlen(ext)+2);
+ out = xmalloc(strlen(orig)+(ext ? (strlen(ext)+2) : 1));
strcpy(out, orig);
outext = strrchr(out, '.');
if (outext) {
* (as we don't want to overwrite the source file).
*/
outext++; /* advance past '.' */
- if (strcmp(outext, ext) == 0) {
+ if (ext && strcmp(outext, ext) == 0) {
outext = NULL; /* indicate default should be used */
WarningNow(_("file name already ends in `.%s': output will be in `%s'"),
ext, def);
/* No extension: make sure the output extension is not empty
* (again, we don't want to overwrite the source file).
*/
- if (*ext == '\0')
+ if (!ext)
WarningNow(_("file name already has no extension: output will be in `%s'"),
def);
else {
}
/* replace extension or use default name */
- if (outext)
- strcpy(outext, ext);
- else
+ if (outext) {
+ if (!ext) {
+ /* Back up and replace '.' with string terminator */
+ outext--;
+ *outext = '\0';
+ } else
+ strcpy(outext, ext);
+ } else
strcpy(out, def);
return out;
/* Replace extension on a filename (or append one if none is present).
* If output filename would be identical to input (same extension out as in),
* returns (copy of) def.
+ * A NULL ext means the trailing '.' should NOT be included, whereas a "" ext
+ * means the trailing '.' should be included.
*/
-/*@only@*/ char *replace_extension(const char *orig, const char *ext,
- const char *def);
+/*@only@*/ char *replace_extension(const char *orig, /*@null@*/
+ const char *ext, const char *def);
/* These functions only work properly if p is an (unsigned char *) */
char *
-replace_extension(const char *orig, const char *ext, const char *def)
+replace_extension(const char *orig, /*@null@*/ const char *ext,
+ const char *def)
{
char *out, *outext;
/* allocate enough space for full existing name + extension */
- out = xmalloc(strlen(orig)+strlen(ext)+2);
+ out = xmalloc(strlen(orig)+(ext ? (strlen(ext)+2) : 1));
strcpy(out, orig);
outext = strrchr(out, '.');
if (outext) {
* (as we don't want to overwrite the source file).
*/
outext++; /* advance past '.' */
- if (strcmp(outext, ext) == 0) {
+ if (ext && strcmp(outext, ext) == 0) {
outext = NULL; /* indicate default should be used */
WarningNow(_("file name already ends in `.%s': output will be in `%s'"),
ext, def);
/* No extension: make sure the output extension is not empty
* (again, we don't want to overwrite the source file).
*/
- if (*ext == '\0')
+ if (!ext)
WarningNow(_("file name already has no extension: output will be in `%s'"),
def);
else {
}
/* replace extension or use default name */
- if (outext)
- strcpy(outext, ext);
- else
+ if (outext) {
+ if (!ext) {
+ /* Back up and replace '.' with string terminator */
+ outext--;
+ *outext = '\0';
+ } else
+ strcpy(outext, ext);
+ } else
strcpy(out, def);
return out;
/* Replace extension on a filename (or append one if none is present).
* If output filename would be identical to input (same extension out as in),
* returns (copy of) def.
+ * A NULL ext means the trailing '.' should NOT be included, whereas a "" ext
+ * means the trailing '.' should be included.
*/
-/*@only@*/ char *replace_extension(const char *orig, const char *ext,
- const char *def);
+/*@only@*/ char *replace_extension(const char *orig, /*@null@*/
+ const char *ext, const char *def);
/* These functions only work properly if p is an (unsigned char *) */