delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2006/01/31/05:31:44

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
From: "Rod Pemberton" <dont_have AT bitbucket DOT cmm>
Newsgroups: comp.os.msdos.djgpp
Subject: A very rough snprintf for DJGPP.
Lines: 55
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
X-IWN-Posted-By: [68.60.59.250] Tue Jan 31 02:14:09 2006
Message-ID: <1cm3b3-vsr2.ln1@news.infowest.com>
X-Complaints-To: abuse AT eli DOT net
X-Trace: 52616e646f6d49564b835516cab6b1f728cd0aaad111e06a2859ca5fe614c2a3fdb4d17c804a296421caf04f2ab9f821806ff6d96bc5dc3cc5ee0d356a54fb054d1229516bb50476a81498288d0562d7fa5fb75ef6d0b21bb3c7eda75090a5bc61161a77129f0aa0cc505c4db40dd2a320e574aa23e1a097b47a365d66fce8039d7f5ef9259daa186e5841368f3f602d
X-Abuse-Info: Please be sure to forward ALL headers so that we may process your complaint properly.
NNTP-Posting-Date: Tue, 31 Jan 2006 09:29:22 UTC
Date: Tue, 31 Jan 2006 10:15:42 GMT
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

DJ,

I'm not sure if you've got snprintf() for 2.0.4 yet.  I've appended a very
rough snprinf() for DJGPP, derived from DJGPP sources.  It has a bunch of
issues...  BTW, is 2.0.4 CVS-able?

Rod Pemberton


#include <stdlib.h>
#include <string.h>

#include <stdio.h>
#include <limits.h> /* if error about syslimits.h, no LFN driver loaded...
*/
#include <libc/file.h>

int
snprintf(char *str, size_t n, const char *fmt, ...)
{
  FILE _strbuf;
  int len;
  char tmp[strlen(str)+strlen(fmt)+2*PATH_MAX]; /* GCC Dynamic Allocation */
  /* must be at least length of destination string */
  /* must be at least length of format string plus extra for args */
  /* FIXME: arg size unknown until after _doprnt, assume two paths? */

  _strbuf._flag = _IOWRT|_IOSTRG|_IONTERM;
  _strbuf._ptr = tmp;
  _strbuf._cnt = INT_MAX;
  len = _doprnt(fmt, (va_list)(&(fmt)+1), &_strbuf);
  *_strbuf._ptr = 0;
  tmp[n-1]=0; /* BOTH null terminators are needed, shortest "wins" */
  strcpy(str,tmp);
  len = strlen(str);
  return len;
}

int main(void)
{
        char    error[80];
        char    chop[12];

        snprintf(error, sizeof(error), "Unable to open %d\n", 32);
        printf("%s",error);
        snprintf(chop, sizeof(chop), "Second chopping %d\n", 63);
        printf("%s",chop);

exit(0);
}




- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019