Board index » cppbuilder » C++ Builder 2007 Prof version & localtime_s

C++ Builder 2007 Prof version & localtime_s


2008-02-06 09:46:17 AM
cppbuilder104
In the help it defines localtime_s (a bit like the unix thread safe
localtime_r)
ms-help://borland.bds5/MS.NETFramework.v20.en/dv_vccrt/html/842d1dc7-d6f8-41d3-b340-108d4b90df54.htm
If I use this it wont compile complaining it doesn't exist. What do I
need to change to make C++ Builder find the proper header and library
for this function.
Adrian
 
 

Re:C++ Builder 2007 Prof version & localtime_s

I just looked in the help and it speaks of the function
struct tm *localtime(const time_t *tod);
However I was unable to find anything about localtime_s
The URL you provided contains the string "MS.NETFramework.v20.en" which
implies that it is speaking of .NET. C++ Builder does not have facilities
for .NET. It is supported by Delphi for .NET which, depending upon what
edition you have, may be on your machine.
. Ed
Quote
Adrian wrote in message
news:47a91167$ XXXX@XXXXX.COM ...

In the help it defines localtime_s (a bit like the unix thread safe
localtime_r)

ms-help://borland.bds5/MS.NETFramework.v20.en/dv_vccrt/html/842d1dc7-d6f8-41d3-b340-108d4b90df54.htm

If I use this it wont compile complaining it doesn't exist. What do I need
to change to make C++ Builder find the proper header and library for this
function.
 

Re:C++ Builder 2007 Prof version & localtime_s

I don't know the answer to your question (I have BCB 2007 also but could not
find that documentation), but AFAIK the Window API function GetLocalTime()
(and it's many friends) is reentrant, maybe you can use that instead. See
GetLocalTime, and also SystemTimeToFileTime which can convert the time to a
more convenient structure:
msdn2.microsoft.com/en-us/library/ms724338.aspx
msdn2.microsoft.com/en-us/library/ms724948(VS.85).aspx
And a summary of all related functions (you may find other useful things):
msdn2.microsoft.com/en-us/library/ms725473(VS.85).aspx
Jason
"Adrian" < XXXX@XXXXX.COM >wrote in message
Quote
In the help it defines localtime_s (a bit like the unix thread safe
localtime_r)

ms-help://borland.bds5/MS.NETFramework.v20.en/dv_vccrt/html/842d1dc7-d6f8-41d3-b340-108d4b90df54.htm

If I use this it wont compile complaining it doesn't exist. What do I need
to change to make C++ Builder find the proper header and library for this
function.



Adrian
 

{smallsort}

Re:C++ Builder 2007 Prof version & localtime_s

Ed Mulroy [TeamB] wrote:
Quote
I just looked in the help and it speaks of the function
struct tm *localtime(const time_t *tod);

However I was unable to find anything about localtime_s

The URL you provided contains the string "MS.NETFramework.v20.en" which
implies that it is speaking of .NET. C++ Builder does not have facilities
for .NET. It is supported by Delphi for .NET which, depending upon what
edition you have, may be on your machine.

. Ed
Thanks Ed, I dont have Delphi installed so why is this appearing in the
help.
And what is the thread safe version of localtime to use with BCC if you
know.
Adrian
 

Re:C++ Builder 2007 Prof version & localtime_s

Quote
And what is the thread safe version of localtime to use with BCC if you
know.
I don't think localtime can be made thread safe because it uses an alterable
global variable and what it returns is a pointer to a single static instance
of struct tm. One thread could be in a call modifying the structure as
another thread is using the values previoiusly stored in it and one thread
could be altering the global variable as the other's call to localtime is
using it.
For thread safety consider using the Windows API functions GetLocalTime. It
might look something like this:
/* requires windows.h and time.h be included */
struct tm* MyLocaltime(struct tm ×truc)
{
SYSTEMTIME st;
GetLocalTime(&st);
timestruc.tm_sec = st.wSecond;
timestruc.tm_min = st.wMinute;
timestruc.tm_hour = st.wHour;
// don't know what tm_mday is supposed to be
timestruc.tm_mon = st.wMonth;
timestruc.tm_year = st.wYear - 1900;
timestruc.tm_wday = st.wDayOfWeek;
// day of year and if daylight savings flag left for you to figure out
}
. Ed
Quote
Adrian wrote in message
news:47a91fc5$ XXXX@XXXXX.COM ...


Thanks Ed, I dont have Delphi installed so why is this appearing in the
help.

And what is the thread safe version of localtime to use with BCC if you
know.