From Martin Maechler <maechler@stat.math.ethz.ch>  Thu Aug 19 18:08:09 1999
From: Martin Maechler <maechler@stat.math.ethz.ch> (Martin Maechler)
Date: Thu, 19 Aug 1999 19:08:09 +0200
Subject: date() should not append a final "\n" ?!?
In-Reply-To: <14267.55357.387296.720135@fangorn.ci.tuwien.ac.at> (message from
 Kurt Hornik on Thu, 19 Aug 1999 12:11:09 +0200 (CEST))
References: <199908190845.KAA24041@sophie.ethz.ch>
 <14267.50386.581977.851244@galadriel.ci.tuwien.ac.at>
 <199908190938.LAA24130@sophie.ethz.ch>
 <14267.53714.885909.438577@fangorn.ci.tuwien.ac.at>
 <199908190948.LAA24138@sophie.ethz.ch> <14267.55357.387296.720135@fangorn.ci.tuwien.ac.at>
Message-ID: <199908191708.TAA08386@sophie.ethz.ch>

>>>>> On Thu, 19 Aug 1999 12:11:09 +0200 (CEST), Kurt Hornik <Kurt.Hornik@ci.tuwien.ac.at> said:

>>>>> Martin Maechler writes:
...

    MM> Between R 0.63.2 and 0.64, the behavior of date() has been changed
    MM> in order to become platform independent.  It now uses POSIX calls,
    MM> basically

    MM> time_t t; time(&t); return ctime(&t);


    MM> This currently returns (for me on Sun SPARC Solaris)

    >>>>>>> date()
    MM> [1] "Thu Aug 19 10:36:28 1999\n"

    MM> where I think the final "\n" is really UNdesired.

    FrL> Yes!

    >>>> Okay, I checked Lewine (1991) "POSIX Programmer's Guide" :

    >>>> POSIX specifies that ctime() has a final "\n" (before the string
    >>>> terminator \0) and always length 26 (incl. terminator)

    >>>> Hence, we have to drop the final "\n", already in function
    >>>> R_Date() which is [in src/main/platform.c] currently char
    >>>> *R_Date() { time_t t; time(&t); return ctime(&t); }

    >>>> How can we drop is this done in the most elegant way?  (without
    >>>> having to allocate a char[26] ?)

 <...>

    KH> Suggestion:

    KH> 	return strtok(ctime(&t), "\n");

Thanks Kurt, 
this works (and *is* elegant!);  

I've applied and committed it for 0.65.

Martin
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


date() should not append a final "\n" ?!?
Martin Maechler