#endif
#include <ctype.h>
+#include <errno.h>
#include "errwarn.h"
#include "file.h"
return s-path+1;
}
+char *
+yasm__getcwd(void)
+{
+ char *buf;
+ size_t size;
+
+ size = 1024;
+ buf = yasm_xmalloc(size);
+ while (getcwd(buf, size) == NULL) {
+ if (errno != ERANGE) {
+ yasm__fatal(N_("could not determine current working directory"));
+ yasm_xfree(buf);
+ return NULL;
+ }
+ size *= 2;
+ buf = yasm_xrealloc(buf, size);
+ }
+ return buf;
+}
+
/* FIXME: dumb way for now */
char *
yasm__abspath_unix(const char *path)
char *curdir, *abspath;
static const char pathsep[2] = "/";
- curdir = getcwd(NULL, 0);
+ curdir = yasm__getcwd();
abspath = yasm_xmalloc(strlen(curdir) + strlen(path) + 2);
strcpy(abspath, curdir);
strcat(abspath, pathsep);
strcat(abspath, path);
- free(curdir);
+ yasm_xfree(curdir);
return abspath;
}
char *curdir, *abspath, *ch;
static const char pathsep[2] = "\\";
- curdir = getcwd(NULL, 0);
+ curdir = yasm__getcwd();
abspath = yasm_xmalloc(strlen(curdir) + strlen(path) + 2);
strcpy(abspath, curdir);
strcat(abspath, pathsep);
strcat(abspath, path);
- free(curdir);
+ yasm_xfree(curdir);
/* Replace all / with \ */
ch = abspath;
# endif
#endif
+/** Get the current working directory.
+ * \internal
+ * \return Current working directory pathname (newly allocated).
+ */
+/*@only@*/ char *yasm__getcwd(void);
+
/** Convert a UNIX relative or absolute pathname into an absolute pathname.
* \internal
* \param path pathname
#include <util.h>
/*@unused@*/ RCSID("$Id$");
-/* Need either unistd.h or direct.h (on Windows) to prototype getcwd() */
-#if defined(HAVE_UNISTD_H)
-#include <unistd.h>
-#elif defined(HAVE_DIRECT_H)
-#include <direct.h>
-#endif
-
#include <libyasm.h>
#include "dwarf2-dbgfmt.h"
/* compile directory (current working directory) */
abc->len += dwarf2_add_abbrev_attr(abbrev, DW_AT_comp_dir, DW_FORM_string);
- buf = getcwd(NULL, 0);
+ buf = yasm__getcwd();
dwarf2_append_str(debug_info, buf);
- free(buf);
+ yasm_xfree(buf);
/* producer - assembler name */
abc->len += dwarf2_add_abbrev_attr(abbrev, DW_AT_producer, DW_FORM_string);