From octave-maintainers-request at bevo dot che dot wisc dot edu Mon Feb 5 23:47:48 2001 Subject: Re: extern char *strptime () on FreeBSD 2.2.8 From: Trond Varslot To: John "W." Eaton Cc: octave-maintainers at bevo dot che dot wisc dot edu Date: 05 Feb 2001 20:44:31 +0100 Will something along these lines be acceptable? It basicly checks if the function strptime() is defined in time.h. If it is, there is no need to define it in lo-cutils.c. If it is not, strptime will be defined as previously. This is atleast will get rid of the compilation error which I got because of the discrepancy in the definition of strptime in time.h and in lo-cutils.c. Yours sincerely Trond Varslot. -------------------------------- --------- BEGIN PATCH --------- -------------------------------- diff -cr octave-2.1.33/acconfig.h octave-2.1.33.tkv/acconfig.h *** octave-2.1.33/acconfig.h Sun Feb 4 14:23:07 2001 --- octave-2.1.33.tkv/acconfig.h Mon Feb 5 20:08:13 2001 *************** *** 61,66 **** --- 61,69 ---- /* Define if your system has program_invocation_name. */ #undef HAVE_PROGRAM_INVOCATION_NAME + /* Define if you have the strptime function defined in time.h. */ + #undef HAVE_STRPTIME_DECL + /* Define if your system has a sys_siglist variable. */ #undef HAVE_SYS_SIGLIST diff -cr octave-2.1.33/aclocal.m4 octave-2.1.33.tkv/aclocal.m4 *** octave-2.1.33/aclocal.m4 Sun Feb 4 14:23:39 2001 --- octave-2.1.33.tkv/aclocal.m4 Sun Feb 4 23:10:03 2001 *************** *** 931,933 **** --- 931,944 ---- AC_DEFINE(CXX_PREPENDS_UNDERSCORE) fi ]) + dnl + dnl OCTAVE_CHECK_STRPTIME_DECL -- See if strptime is defined in time.h + AC_DEFUN([OCTAVE_CHECK_STRPTIME_DECL], [ + define([TMP_CVAR], [octave_strptime_decl]) + AC_CACHE_CHECK([whether strptime is declared], TMP_CVAR, + AC_TRY_COMPILE([$1], [$2], + TMP_CVAR[=yes], TMP_CVAR[=no])) + if test $TMP_CVAR = yes; then + AC_DEFINE(HAVE_STRPTIME_DECL,1) + fi + undefine([TMP_CVAR])]) \ No newline at end of file diff -cr octave-2.1.33/configure.in octave-2.1.33.tkv/configure.in *** octave-2.1.33/configure.in Sun Feb 4 14:23:24 2001 --- octave-2.1.33.tkv/configure.in Sun Feb 4 23:09:40 2001 *************** *** 911,916 **** --- 911,918 ---- stricmp strncasecmp strnicmp strptime symlink tempnam umask unlink \ usleep vfprintf vsprintf vsnprintf waitpid) + OCTAVE_CHECK_STRPTIME_DECL([#include ], [char *iu_x = (char*)strptime()]) + OCTAVE_SMART_PUTENV LD_CXX='$(CXX)' diff -cr octave-2.1.33/liboctave/lo-cutils.c octave-2.1.33.tkv/liboctave/lo-cutils.c *** octave-2.1.33/liboctave/lo-cutils.c Sun Feb 4 14:23:25 2001 --- octave-2.1.33.tkv/liboctave/lo-cutils.c Mon Feb 5 07:44:43 2001 *************** *** 34,40 **** qsort (base, n, size, cmp); } ! extern char *strptime (); char * oct_strptime (const char *buf, const char *format, struct tm *tm) --- 34,42 ---- qsort (base, n, size, cmp); } ! #ifndef HAVE_STRPTIME_DECL ! extern char *strptime(const char *buf, const char *format, struct tm *tm); ! #endif char * oct_strptime (const char *buf, const char *format, struct tm *tm) ------------------------------------------ -------- END PATCH ---------------------- ------------------------------------------ Den 29 Jan 2001 08:56:11 -0600, skrev John W. Eaton: > On 26-Jan-2001, Trond Varslot wrote: > > | I have been trying to compile octave 2.1.33 on FreeBSC 2.2.8, and > | noticed that in the file > | liboctave/lo-cutils.c, the function strptime is defined as > | extern char *strptime (). > | This comflicts with the definition in /usr/inclide/time.h: > | const char *strptime(). > | > | I simply removed the prototype from lo-cutils.c, and octave seems to > | compile. I was not able to complete the linking, since the computer ran > | out of memory:( > | > | My question is this: What reasons are there for defining a function > | prototype which is also defined in the included header files? Isn't the > | proper place for the definition of strptime in time.h? If there are no > | rationales behind doing it this way, I suggest we remove the prototype > | from lo-cutils.c as it gives the compiler hickups on FreeBSD 2.2.8. > > strptime is not defined by ANSI C, so it is not necessarily going to > be declared by time.h. On my system, it has the following prototype: > > # ifdef __USE_XOPEN > /* Parse S according to FORMAT and store binary time information in TP. > The return value is a pointer to the first unparsed character in S. */ > extern char *strptime (__const char *__restrict __s, > __const char *__restrict __fmt, struct tm *__tp) > __THROW; > # endif > > When I remove the declaration in lo-cutils.c and recompile, I see the > following warnings: > > liboctave/lo-cutils.c: In function `oct_strptime': > lo-cutils.c:40: warning: implicit declaration of function `strptime' > lo-cutils.c:40: warning: return makes pointer from integer without a cast > > (presumably becuase __USE_XOPEN is not defined). > > So, I think some kind of declaration is needed. Do you have a better > solution that will work on all systems? > > Thanks, > > jwe