Operating System - Linux
1748254 Members
4106 Online
108760 Solutions
New Discussion юеВ

Re: Conversion problem Pl help

 
gopala
New Member

Conversion problem Pl help

Hi We are converting piece of code from SUN to HP and this is old code posted below getting stuck while conversion.

clock = time(0);

cftime(system_date_day,"%d",&clock);

/* this next kludge is to prevent sccs from expanding things */
/* when letters are bracked by percent signs */

strcat(sccs_kludge,"%");
strcat(sccs_kludge,"Y");
strcat(sccs_kludge,"%");
strcat(sccs_kludge,"m");
strcat(sccs_kludge,"%");
strcat(sccs_kludge,"d");

cftime(full_date,sccs_kludge,&clock);


Hw do i convert the same above into HP, Pl help.

Thanks
Gopala
9 REPLIES 9
Peter Nikitka
Honored Contributor

Re: Conversion problem Pl help

Hi,

not knowing, how your variable sccs_kludge is defined + allocated, I suggest to use a
strcpy(sccs_kludge,"%");

for the first setting, then use your strcat()'s.
So no implicit NULLify of your array(?) is needed.

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
Sandman!
Honored Contributor

Re: Conversion problem Pl help

There is no cftime under HPUX and the closest you can get to it is strftime(3C). Replacing all instances of cftime with strftime with the correct arguments should more likely do it.


gopala
New Member

Re: Conversion problem Pl help

Hi Can you please send me the new code, How it looks like same equivalent in HP, We are using this part of old Proc code and I do not even know much of it but here is the place it is failing.

I appreciate your help.

Thanks
Gopala
Sandman!
Honored Contributor

Re: Conversion problem Pl help

Code snippet below shows how to use the strftime(3C) function:

#include
#include

int main(int argc, char *argv[])
{
time_t clock;
char buf[BUFSIZ];
struct tm tmobj, *tmptr = &tmobj;
clock = time(0);
tmptr = localtime(&clock);
strftime(buf, sizeof(buf), "%a %b %d %H:%M:%S %Z %Y", tmptr);
printf("%s\n", buf);
}
Sandman!
Honored Contributor

Re: Conversion problem Pl help

The specific format string i.e. "%a %b %d %H:%M:%S %Z %Y" was used only to make the output resemble that of the date(1) command. You can change it to whatever you prefer. See the manpage of strftime(3C) for details.

~cheers
gopala
New Member

Re: Conversion problem Pl help

Hi

I highly appreciate your response.

I converted to the below and getting core dump, Pl let me know what we are doing worng, Also when we pass that varaible to other program the full_date converts to sysdate in 20070720 in that format.

time_t clock;
char system_date_day[3];
char revenue_date[7];
char full_date[9];
char sccs_kludge[7];
struct tm *time_ptr;
struct tm *time_ptr;
#ifdef DBGtrace
printf("in get_tcm\n");
#endif

/*clock = time(0);
strftime(system_date_day,3,"%d",&clock);
*/

time_ptr = gmtime(&clock);


clock = time(0);

strftime(system_date_day,3,"%d",time_ptr);

/* this next kludge is to prevent sccs from expanding things */
/* when letters are bracked by percent signs */

strcat(sccs_kludge,"%");
strcat(sccs_kludge,"Y");
strcat(sccs_kludge,"%");
strcat(sccs_kludge,"m");
strcat(sccs_kludge,"%");
strcat(sccs_kludge,"d");


strftime(full_date,9,sccs_kludge,time_ptr);
Sandman!
Honored Contributor

Re: Conversion problem Pl help

>struct tm *time_ptr;

above struct is declared twice; not sure if you meant to declare an object of that type plus a pointer to it as in:

struct tm tmobj;
struct tm *tmptr;

>time_ptr = gmtime(&clock);

>clock = time(0);

"clock" variable is initialized after extracting its value with the gmtime() function which is incorrect. Swap the two statements around:

clock=time(0);
time_ptr=gmtime(&clock);

Other than giving erroneous results it does not core dump on my PARISC system. What machine and OS are you using? Try to get a stack trace from the core file.
gopala
New Member

Re: Conversion problem Pl help

okay, At present We fixed the problem using some other way.

Yesterday we got coredump and today it ran well but without the correct data, So we put another fix to copy value into the varaible.

I appreciate your response.

Thanks
Gopala
Dennis Handly
Acclaimed Contributor

Re: Conversion problem Pl help

As mentioned by Peter, you still haven't fixed your first strcat. This will randomly fail if there are no null chars in sccs_kludge.

In fact, you should NOT be using strcat nor strcpy. Use an array initializer:
char sccs_kludge[7] = { '%', 'Y', '%', 'm', '%', 'd' };

Instead of hardcoding 9 here: strftime(full_date,9
you should use: strftime(full_date,sizeof(full_date)