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

c program : pb with Sparc ?



Hello,

I intend to resurrect the package cgi-scripts, and I'm working on brand new
programs.

Within them, there is `ldate', a c program which displays date informations
in a versatile format, according to the LC_TIME passed as an argument. This
uses strftime() which is POSIX defined.

The program compiles well on i386/Debian Slink and works as expected, but I have
tried to compile it on sparc, and, because I rent some place on a server,
try on it, which is a sparc/SunOS with the GNU utils.

Compilation is good ( no warning with flags -g -W -Wall), but there is a 
segmentation fault. I ran it under gdb and here are the messages :

/proc/05368: Permission denied
PIOCSTRACE failed : no such file or directory
/proc/05368 no such file or directory
PIOCWSTOP failed

Any hint about these messages welcome !
The part of the program involved seem to be obviously the dynamic memory 
allocation or the call of strftime() --- needs perhaps some files that are
missing ? Extract :

int
main(int argc, char *argv[])
{
	int c, format_defined = 0;
	const char *strftime_format;
	char tmp_format[3] = "%c";
	time_t temps = time(NULL);
	struct tm *local_time = localtime(&temps);
	size_t max, size_format = SIZE_FORMAT;
	const char *locale;
	char *format = (char *) malloc(size_format);
	
/* stuff skipped : initialisations, getopt etc...*/

	setlocale(LC_TIME, locale);
	/* if nb of char written == 0, then format is too small */
	while ( (max = 
		strftime(NULL, size_format, strftime_format, local_time))== 0) {
			size_format = 2 * size_format;
			if ((format = realloc(format, size_format)) == NULL) {
				free(format);
				if ((format = (char *) malloc(size_format)) == NULL)
				printerror(
				  _("unable to allocate enough memory for \
				   format : %s"), strftime_format);
		}
	}
	strftime(format, size_format, strftime_format, local_time);
	printf("%s\n", format);
	return EXIT_SUCCESS;
}

Am I doing something wrong ? Who/what is involved : me, Sparc, SunOs, some files
missing in the system, dynamic memory allocation forbidden in some way on the
server for user's programs ? 

Thanks in advance for any clue !
-- 
Thierry LARONDE
thierry.laronde@polynum.com
website : http://www.polynum.com


Reply to: