Oliver Schmidt [Wed, 15 Aug 2018 13:59:11 +0000 (15:59 +0200)]
Replaced _systime with clock_gettime.
We want to add the capability to not only get the time but also set the time, but there's no "setter" for the "getter" time().
The first ones that come into mind are gettimeofday() and settimeofday(). However, they take a struct timezone argument that doesn't make sense - even the man pages says "The use of the timezone structure is obsolete; the tz argument should normally be specified as NULL." And POSIX says "Applications should use the clock_gettime() function instead of the obsolescent gettimeofday() function."
The ...timeofday() functions work with microseconds while the clock_...time() functions work with nanoseconds. Given that we expect our targets to support only 1/10 of seconds the microseconds look preferable at first sight. However, already microseconds require the cc65 data type 'long' so it's not such a relevant difference to nanoseconds. Additionally clock_getres() seems useful.
In order to avoid code duplication clock_gettime() takes over the role of the actual time getter from _systime(). So time() now calls clock_gettime() instead of _systime().
For some reason beyond my understanding _systime() was mentioned in time.h. _systime() worked exactly like e.g. _sysremove() and those _sys...() functions are all considered internal. The only reason I could see would be a performance gain of bypassing the time() wrapper. However, all known _systime() implementations internally called mktime(). And mktime() is implemented in C using an iterative algorithm so I really can't see what would be left to gain here. From that perspective I decided to just remove _systime().
Oliver Schmidt [Thu, 2 Aug 2018 15:12:12 +0000 (17:12 +0200)]
"Inverted" time_t value handling.
So far time_t values were interpreted as local time values. However, usually time_t values are to be interpreted as "seconds since 1 Jan 1970 in UTC". Therefore all logic handling time_t values has to be changed.
- So far gmtime() called localtime() with an adjusted time_t, now localtime() calls gmtime() with an adjusted time_t.
- mktime() has to do "the opposite" of localtime(), to keep it that way mktime() does now the inverse adjustment made by localtime().
- All currently present time() implementations internally call mktime() so they don't require individual adjustments.
Oliver Schmidt [Thu, 2 Aug 2018 13:45:57 +0000 (15:45 +0200)]
Increased consistency.
The test program works as-is only if the timezone isn't set (to something different than UTC). However, using localtime() instead of gmtime() makes it at least consistent in that the original time (given to mktime()) is identical to the time retrieved.
Oliver Schmidt [Fri, 8 Jun 2018 17:16:18 +0000 (19:16 +0200)]
Allow spaces in path names.
The Microsoft C Library needs to have spawnvp() parameters with spaces quoted manually. We do this only if actually necessary to limit issues with parameters already containing double quotes.
Oliver Schmidt [Fri, 8 Jun 2018 16:58:36 +0000 (18:58 +0200)]
Use --print-target-path only as last resort.
--print-target-path may return a path with (escaped) spaces. We'll use that path with $(wildcard ...), that's fine. But then we use the outcome with $(foreach ...) and there things fail badly and there's nothing to do about it.
Therefore we a) try to avoid --print-target-path in the first place and b) explicitly bail out if we end up with spaces.
Oliver Schmidt [Thu, 7 Jun 2018 15:10:33 +0000 (17:10 +0200)]
Escape spaces in target path.
cc65 escapes spaces in paths it writes to dependency files (see WriteEscaped() in cc65/input.c). Given that the output of OptPrintTargetPath() is supposed to be used in Makefiles in pretty much the same way it is appropriate to escape spaces here too.