summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Borowski <kilobyte@angband.pl>2009-12-17 11:38:36 +0100
committerAdam Borowski <kilobyte@angband.pl>2009-12-17 11:38:36 +0100
commitc266f14414471d5252130c70bafa0c60f85a265c (patch)
tree37a46a422f6ea7f1f88675cb728ac1be8dcd3619
parentb7d134a9c8a634cdab2cd060e561304e1d12979d (diff)
downloadcrawl-ref-c266f14414471d5252130c70bafa0c60f85a265c.tar.gz
crawl-ref-c266f14414471d5252130c70bafa0c60f85a265c.zip
Use snprintf() on DOS, we don't want crashes. Non-ancient compilers have it.
Preferably, we would detect the presence of such functions, but _some_ folks oppose feature tests.
-rw-r--r--crawl-ref/source/AppHdr.h9
-rw-r--r--crawl-ref/source/libutil.cc36
-rw-r--r--crawl-ref/source/libutil.h4
3 files changed, 0 insertions, 49 deletions
diff --git a/crawl-ref/source/AppHdr.h b/crawl-ref/source/AppHdr.h
index 1b43a1e646..44ab312c1a 100644
--- a/crawl-ref/source/AppHdr.h
+++ b/crawl-ref/source/AppHdr.h
@@ -179,14 +179,6 @@
#include <string>
#include "libdos.h"
- #ifdef __DJGPP__
- #define NEED_SNPRINTF
-
- // [dshaligram] This is distressing, but djgpp lacks (v)snprintf, and
- // we have to support DOS. Ow. FIXME
- #define vsnprintf(buf, size, format, args) vsprintf(buf, format, args)
- #endif
-
#include <dos.h>
#define round(x) floor((x)+0.5)
@@ -506,7 +498,6 @@
// Uncomment these if you can't find these functions on your system
// #define NEED_USLEEP
-// #define NEED_SNPRINTF
#ifdef __cplusplus
diff --git a/crawl-ref/source/libutil.cc b/crawl-ref/source/libutil.cc
index ace4a65309..0243452e77 100644
--- a/crawl-ref/source/libutil.cc
+++ b/crawl-ref/source/libutil.cc
@@ -667,42 +667,6 @@ void usleep(unsigned long time)
}
#endif
-// Not the greatest version of snprintf, but a functional one that's
-// a bit safer than raw sprintf(). Note that this doesn't do the
-// special behaviour for size == 0, largely because the return value
-// in that case varies depending on which standard is being used (SUSv2
-// returns an unspecified value < 1, whereas C99 allows str == NULL
-// and returns the number of characters that would have been written). -- bwr
-#ifdef NEED_SNPRINTF
-
-#include <string.h>
-
-int snprintf( char *str, size_t size, const char *format, ... )
-{
- va_list argp;
- va_start( argp, format );
-
- char *buff = new char [ 10 * size ]; // hopefully enough
- if (!buff)
- end(1, false, "Out of memory\n");
-
- vsprintf( buff, format, argp );
- strncpy( str, buff, size );
- str[ size - 1 ] = 0;
-
- int ret = strlen( str );
- if ((unsigned int) ret == size - 1 && strlen( buff ) >= size)
- ret = -1;
-
- delete [] buff;
-
- va_end( argp );
-
- return (ret);
-}
-
-#endif
-
#ifndef USE_TILE
void cgotoxy(int x, int y, GotoRegion region)
{
diff --git a/crawl-ref/source/libutil.h b/crawl-ref/source/libutil.h
index b32aa83be2..66cb9bb693 100644
--- a/crawl-ref/source/libutil.h
+++ b/crawl-ref/source/libutil.h
@@ -161,10 +161,6 @@ std::string comma_separated_line(Z start, Z end,
void usleep( unsigned long time );
#endif
-#ifdef NEED_SNPRINTF
-int snprintf( char *str, size_t size, const char *format, ... );
-#endif
-
#ifndef USE_TILE
void cgotoxy(int x, int y, GotoRegion region = GOTO_CRT);
#endif