Porting efforts... :)

This commit is contained in:
Vadim B. Mikheev 1998-09-10 04:11:52 +00:00
parent ee00b75441
commit 098c63c0ff

View file

@ -31,9 +31,18 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
*/ */
#if 0
# include "sendmail.h" # include "sendmail.h"
# include "pathnames.h" # include "pathnames.h"
#endif
# include "postgres.h"
# include <stdarg.h>
# define VA_LOCAL_DECL va_list args;
# define VA_START(f) va_start(args, f)
# define VA_END va_end(args)
# include <sys/ioctl.h> # include <sys/ioctl.h>
# include <sys/param.h> # include <sys/param.h>
@ -59,50 +68,43 @@
* causing nast effects. * causing nast effects.
**************************************************************/ **************************************************************/
/*static char _id[] = "$Id: snprintf.c,v 1.4 1998/09/04 14:34:23 scrappy Exp $";*/ /*static char _id[] = "$Id: snprintf.c,v 1.5 1998/09/10 04:11:52 vadim Exp $";*/
static void dopr();
static char *end; static char *end;
static int SnprfOverflow; static int SnprfOverflow;
/* VARARGS3 */ int snprintf(char *str, size_t count, const char *fmt, ...);
int vsnprintf(char *str, size_t count, const char *fmt, ...);
static void dopr (char *buffer, const char *format, ... );
int int
# ifdef __STDC__
snprintf(char *str, size_t count, const char *fmt, ...) snprintf(char *str, size_t count, const char *fmt, ...)
# else
snprintf(str, count, fmt, va_alist)
char *str;
size_t count;
const char *fmt;
va_dcl
#endif
{ {
int len; int len;
VA_LOCAL_DECL VA_LOCAL_DECL
VA_START(fmt); VA_START(fmt);
len = vsnprintf(str, count, fmt, ap); len = vsnprintf(str, count, fmt, args);
VA_END; VA_END;
return len; return len;
} }
# ifndef luna2
int int
vsnprintf(str, count, fmt, args) vsnprintf(char *str, size_t count, const char *fmt, ...)
char *str;
size_t count;
const char *fmt;
va_list args;
{ {
VA_LOCAL_DECL
VA_START(fmt);
str[0] = 0; str[0] = 0;
end = str + count - 1; end = str + count - 1;
SnprfOverflow = 0; SnprfOverflow = 0;
dopr( str, fmt, args ); dopr( str, fmt, args);
if (count > 0) if (count > 0)
end[0] = 0; end[0] = 0;
if (SnprfOverflow && tTd(57, 2)) if (SnprfOverflow)
printf("\nvsnprintf overflow, len = %d, str = %s", elog(NOTICE, "vsnprintf overflow, len = %d, str = %s",
count, shortenstring(str, 203)); count, str);
VA_END;
return strlen(str); return strlen(str);
} }
@ -117,20 +119,20 @@ static char *output;
static void dopr_outch __P(( int c )); static void dopr_outch __P(( int c ));
static void static void
dopr( buffer, format, args ) dopr (char *buffer, const char *format, ... )
char *buffer;
const char *format;
va_list args;
{ {
int ch; int ch;
long value; long value;
int longflag = 0; int longflag = 0;
int pointflag = 0; int pointflag = 0;
int maxwidth = 0; int maxwidth = 0;
char *strvalue; char *strvalue;
int ljust; int ljust;
int len; int len;
int zpad; int zpad;
VA_LOCAL_DECL
VA_START(format);
output = buffer; output = buffer;
while( (ch = *format++) ){ while( (ch = *format++) ){
@ -143,6 +145,7 @@ dopr( buffer, format, args )
switch( ch ){ switch( ch ){
case 0: case 0:
dostr( "**end of format**" , 0); dostr( "**end of format**" , 0);
VA_END;
return; return;
case '-': ljust = 1; goto nextch; case '-': ljust = 1; goto nextch;
case '0': /* set zero padding if len not set */ case '0': /* set zero padding if len not set */
@ -222,6 +225,7 @@ dopr( buffer, format, args )
} }
} }
*output = 0; *output = 0;
VA_END;
} }
static void static void
@ -340,4 +344,4 @@ dopr_outch( c )
SnprfOverflow++; SnprfOverflow++;
} }
# endif /* !luna2 */