-char *get_current_dir_name(void)
-{
- size_t size;
- char *buf;
-
- /* Start with 100 bytes. If this turns out to be insufficient to
- contain the working directory, double the size. */
- size = 100;
- buf = xmalloc(size);
-
- errno = 0; /* Success */
- r = getcwd(buf, size);
- /* getcwd returns NULL and sets errno to ERANGE if the bufferspace
- is insufficient to contain the entire working directory. */
- while(r == NULL && errno = ERANGE)
- {
- free(buf);
- size <<= 1; /* double the size */
- buf = xmalloc(size);
- r = getcwd(buf, size);
- }
-
- return buf;
+char *get_current_dir_name(void) {
+ size_t size;
+ char *buf;
+ char *r;
+
+ /* Start with 100 bytes. If this turns out to be insufficient to
+ contain the working directory, double the size. */
+ size = 100;
+ buf = xmalloc(size);
+
+ errno = 0; /* Success */
+ r = getcwd(buf, size);
+
+ /* getcwd returns NULL and sets errno to ERANGE if the bufferspace
+ is insufficient to contain the entire working directory. */
+ while(r == NULL && errno == ERANGE) {
+ free(buf);
+ size <<= 1; /* double the size */
+ buf = xmalloc(size);
+ r = getcwd(buf, size);
+ }
+
+ return buf;
+}
+#endif
+
+#ifndef HAVE_ASPRINTF
+int asprintf(char **buf, const char *fmt, ...) {
+ int result;
+ va_list ap;
+ va_start(ap, fmt);
+ result = vasprintf(buf, fmt, ap);
+ va_end(ap);
+ return result;
+}
+
+int vasprintf(char **buf, const char *fmt, va_list ap) {
+ int status;
+ va_list aq;
+ int len;
+
+ len = 4096;
+ *buf = xmalloc(len);
+
+ va_copy(aq, ap);
+ status = vsnprintf(*buf, len, fmt, aq);
+ va_end(aq);
+
+ if(status >= 0)
+ *buf = xrealloc(*buf, status + 1);
+
+ if(status > len - 1) {
+ len = status;
+ va_copy(aq, ap);
+ status = vsnprintf(*buf, len, fmt, aq);
+ va_end(aq);
+ }
+
+ return status;
+}
+#endif
+
+#ifndef HAVE_GETTIMEOFDAY
+int gettimeofday(struct timeval *tv, void *tz) {
+ tv->tv_sec = time(NULL);
+ tv->tv_usec = 0;
+ return 0;
+}
+#endif
+
+#ifdef HAVE_MINGW
+int usleep(long usec) {
+ Sleep(usec / 1000);
+ return 0;