bug-commoncpp
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: "getTicks() in ms" to add for WIN32 and Linux to commonc++?


From: David Sugar
Subject: Re: "getTicks() in ms" to add for WIN32 and Linux to commonc++?
Date: Sun, 4 Jan 2004 09:33:38 -0500
User-agent: KMail/1.5.3

I have seen portable implementations used in other packages where the target 
doesn't have snprintf,  like in rsync, etc, some on bsd licenses, some on 
lgpl, so I assume we can find an existing one to port and use as a 
replacement function in Common C++ from somewhere.  And of course, it's damn 
useful for quick string hacks that are then at least stack/boundry safe.  
However, there are also very few modern platforms that do not have snprintf 
in their libc (even w32 has a "_snprintf" buried away).    

I also recall at one point there being added a w32 c library of explicitly 
"safe" string functions.  I looked at the headers for that, and it looked 
both overly complex and overkill for the scope of the given problem, 
especially given snprintf and it's relatives can be made into doing similar 
work, but we did recently add a few original string functions of our own to 
do safe string concatenation and other basic things (setString,  addString).  
However, I think the focus of "safe" string coding for C++ applications is 
surely in the use of a proper string class rather than in making libc derived 
string functions safer.

On Sunday 04 January 2004 05:49 am, Wolfgang Alper wrote:
> Thanks for adding ;-).
> And yes , i would like to see snprintf being emulated for targets not
> providing this function since it is being widly used.
>
> Best regards
>
> Wolfgang
>
> Am Samstag, 3. Januar 2004 15:59 schrieb David Sugar:
> > Done.  We probably should also add a snprintf implementation into missing
> > for targets that lack that...
> >
> > On Friday 02 January 2004 02:57 pm, Federico Montesino Pouzols wrote:
> > >   Yes, I think both should end up in missing.h. Also, as Marc
> > > Boris has pointed out, there are some classes in CC++ that use
> > > GetTickCount on Win32, particularly TimerPort (thread.h).
> > >
> > > On Fri, Jan 02, 2004 at 10:35:01AM -0500, David Sugar wrote:
> > > > I recall in reviewing recent changes in ccrtp, that Federico had to
> > > > add a simulated gettimeofday function for supporting w32 builds.  So
> > > > perhaps both of these functions, if needed for different things,
> > > > should end up with a representation in the Common C++ 1.1 reorganized
> > > > "missing" module for library functions missing from some platforms
> > > > (missing.h/missing.cpp) ...
> > > >
> > > > On Friday 02 January 2004 07:49 am, Wolfgang wrote:
> > > > > Would it make sense to add a getTicks() type function to the
> > > > > CommonC++ framework? Or do you think it is so trivial that it does
> > > > > not need to be there? I run into this recently when porting a
> > > > > project from linux to win32 using commonc++.
> > > > > Here a draft for for win32 and linux.
> > > > >
> > > > >
> > > > >
> > > > > #ifndef WIN32
> > > > > #include <sys/time.h>
> > > > > #else
> > > > > #include <time.h>
> > > > > #include <windows.h>
> > > > > #endif //win32
> > > > >
> > > > >
> > > > > //return number of ticks in ms
> > > > > long getTicks();
> > > > >
> > > > >
> > > > > ifdef WIN32
> > > > > long getTicks() {
> > > > >       return GetTickCount();
> > > > > };
> > > > > #else
> > > > > long getTicks() {
> > > > >       long ticks;
> > > > >       struct timeval now;
> > > > >       gettimeofday(&now, NULL);
> > > > >       ticks = now.tv_sec * 1000l;
> > > > >       ticks += now.tv_usec / 1000l;
> > > > >       return ticks;
> > > > > };
> > > > > #endif
> > > > >
> > > > >
> > > > >
> > > > > _______________________________________________
> > > > > Bug-commoncpp mailing list
> > > > > address@hidden
> > > > > http://mail.gnu.org/mailman/listinfo/bug-commoncpp
> > >
> > > _______________________________________________
> > > Bug-commoncpp mailing list
> > > address@hidden
> > > http://mail.gnu.org/mailman/listinfo/bug-commoncpp
> >
> > _______________________________________________
> > Bug-commoncpp mailing list
> > address@hidden
> > http://mail.gnu.org/mailman/listinfo/bug-commoncpp
>
> _______________________________________________
> Bug-commoncpp mailing list
> address@hidden
> http://mail.gnu.org/mailman/listinfo/bug-commoncpp





reply via email to

[Prev in Thread] Current Thread [Next in Thread]