Skip to Content.
Sympa Menu

freetds - RE: Non portable code

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "Lowden, James K" <LowdenJK AT bernstein.com>
  • To: "'TDS Development Group'" <freetds AT franklin.metalab.unc.edu>
  • Subject: RE: Non portable code
  • Date: Wed, 2 Oct 2002 10:31:53 -0400


> From: Jonas Benjaminsson [mailto:jonas.benjaminsson AT infogate.se]
> Sent: October 2, 2002 9:05 AM
>
> I'm porting FreeTDS to Windows and it's going well.

Glad to hear it, Jonas. :)

> (Brian or James: How should I commit the changes
> I make, by sending you the diffs or by accessing
> the CVS directly?)

As Brian said, it's best to post your "diff -ru" output to the sourceforge
patches page. If you've got CVS functioning, it's a good idea to keep your
tree up to date. Just let "cvs update" merge changes to the base into your
workfiles. That way, your patch can be cleanly applied when you send it,
and you won't wind up fixing something that becomes obsolete.

> When I find code like the one below I shiver.
>
> Ok, it's an easy aproach but will never compile
> on a non Unix system. And what about the speed?

Slow is better than broken.

Speed is not an issue here, really, because the client CPU is so much faster
than data transfer to the database. In any case, writing the null device
sure oughta be fast, and any algorithm that could determine the right
allocation size would have to do something a lot like what vfprintf(3) does.


Wouldn't this be portable?:

#ifdef WIN32
#define TDS_NULL "NUL:"
#else
#define TDS_NULL "/dev/null"
#endif
...
if ((fp = fopen(TDS_NULL, "w")) == NULL)

Besides, Win32 OS's ship with a vfprintf(), so you don't really have to
worry about compiling or using the replacement.

Send us a tough one next time! :)

Lucka till med din project, and regards,

--jkl


>
> The code was found in asprintf.c
>
> FILE *fp;
> int len;
> char *buf;
>
> *ret = NULL;
> if ((fp = fopen("/dev/null", "w")) == NULL)
> return -1;
> len = vfprintf(fp, fmt, ap);
> if (fclose(fp) != 0)
> return -1;
> if (len < 0)
> return len;
> if ((buf = malloc(len + 1)) == NULL)
> return -1;
> vsprintf(buf, fmt, ap);
> *ret = buf;
> return len;
>
>
>
>
>
>
> ---
> You are currently subscribed to freetds as: [LowdenJK AT bernstein.com]
> To unsubscribe, forward this message to
> $subst('Email.Unsub')
>


The information contained in this transmission may contain privileged and
confidential information and is intended only for the use of the person(s)
named above. If you are not the intended recipient, or an employee or agent
responsible for delivering this message to the intended recipient, any
review, dissemination, distribution or duplication of this communication is
strictly prohibited. If you are not the intended recipient, please contact
the sender immediately by reply e-mail and destroy all copies of the
original message. Please note that for certain accounts we do not accept
orders and/or instructions by e-mail, and for those accounts we will not be
responsible for carrying out such orders and/or instructions. Kindly refrain
from sending orders or instructions by e-mail unless you have confirmed that
we accept such communications for your account. Please also note that to
satisfy regulatory requirements we review the outgoing and incoming e-mail
correspondence of staff members serving certain functions.






Archive powered by MHonArc 2.6.24.

Top of Page