[Previous] [Contents] [Index] [Next]

Global Data and the TZ Environment Variable

This chapter describes:

Global data

Certain data items are used by the C/C++ runtime library and may be inspected (or changed in some cases) by a program:

_amblksiz
Header: <stdlib.h>
Type: unsigned int

The increment by which the "break" pointer for memory allocation is advanced when there's no freed block large enough to satisfy a request to allocate a block of memory. This may be changed by a program at any time.

_argc
Header: N/A
Type: int

Number of arguments passed to main().

_argv
Header: N/A
Type: char **

Pointer to a vector containing the actual arguments passed to main().

_auxv
Header: N/A
Type: auxv_t *

Pointer to a vector of auxiliary arguments to main().

_btext
Header: N/A
Type: Linker symbol

Beginning of the text segment.

daylight
Header: <time.h>
Type: unsigned int

1 when daylight saving time is supported in this locale, and 0 otherwise. Whenever a time function is called, the tzset() function is called to set the variable, based on the TZ environment variable.

_edata
Header: N/A
Type: Linker symbol

End of the data segment, excluding BSS data.

_end
Header: N/A
Type: Linker symbol

End of the data segment, including BSS data.

environ
Header: <unistd.h>
Type: char **

Pointer to an array of character pointers to the environment strings.

errno
Header: <errno.h>
Type: int

The last error detected. The runtime library never resets errno to 0. Symbolic names for these errors are found in <errno.h>. See the description of errno and strerror().

_etext
Header: N/A
Type: Linker symbol

End of the text segment.

optarg
Header: <unistd.h>
Type: char *

Pointer to an optional argument.

opterr
Header: <unistd.h>
Type: int *

Indicates whether or not error messages are to be printed.

optind
Header: <unistd.h>
Type: int

Index of the current option being scanned.

optopt
Header: <unistd.h>
Type: int *

Pointer to the offending letter when an error was detected.

__progname
Header: N/A
Type: char *

Basename of the program being executed.

stderr
Header: <stdio.h>
Type: FILE *

Standard error stream (set to the console by default).

stdin
Header: <stdio.h>
Type: FILE *

Standard input stream (set to the console by default).

stdout
Header: <stdio.h>
Type: FILE *

Standard output stream (set to the console by default).

sys_errlist
Header: <errno.h>
Type: char*[]

Array of error messages corresponding to errno.

sys_nerr
Header: <errno.h>
Type: int

Number of entries in the sys_siglist array.

sys_nsig
Header: <signal.h>
Type: int

Number of entries in the sys_siglist array.

_syspage_ptr
Header: <sys/syspage.h>
Type: struct syspage_entry *

Information about the system, including the processor type, bus type, and the location and size of available system RAM. For information about this structure, see the Customizing Image Startup Programs chapter of Building Embedded Systems.

The best way to reference the system information page is via the kernel calls and POSIX cover functions. If there isn't a function to access the information you need, you should use the SYSPAGE_ENTRY() and SYSPAGE_CPU_ENTRY() macros instead of referencing the _syspage_ptr variable directly.

sys_siglist
Header: <signal.h>
Type: char*[]

Array of signal names.

timezone
Header: <time.h>
Type: long int

The number of seconds by which the local time zone is earlier than Coordinated Universal Time (UTC) (formerly known as Greenwich Mean Time). Whenever a time function is called, the tzset() function is called to set the variable, based on the TZ environment variable.

tzname
Header: <time.h>
Type: char *[]

The standard abbreviations for the time zone and the time zone when daylight saving time is in effect. Whenever a time function is called, the tzset() function is called to set the values in the array, based on the TZ environment variable.

The TZ environment variable

The TZ environment variable is used to establish the local time zone. The value of the variable is used by various time functions to compute times relative to Coordinated Universal Time (UTC), formerly known as Greenwich Mean Time (GMT).


Note: If TZ is not set, the system defaults to confstr(_CS_TIMEZONE) for all instances of TZ. The TZ environment variable is POSIX, _CS_TIMEZONE is QNX.

The time on the computer should be set to UTC. Use the date command if the time isn't automatically maintained by the computer hardware.

The TZ environment variable can be set (before the program is executed) by using:

You could also set the TZ environment variable during program execution by using the setenv() or putenv() library functions:

setenv( "TZ", "PST8PDT", 1 );
putenv( "TZ=PST8PDT" );

To obtain the value of the variable, use the getenv() function:

char *tzvalue;
...
tzvalue = getenv( "TZ" );

The tzset() function processes the TZ environment variable and sets the following global variables:

daylight
Indicates if daylight saving time is supported in the locale.
timezone
Contains the number of seconds of time difference between the local time zone and Coordinated Universal Time (UTC).
tzname
Vector of two pointers to character strings containing the standard and daylight time zone names.

The value of the TZ environment variable should be set as follows (spaces are for clarity only):

std offset dst offset, rule

The expanded format is as follows:

stdoffset[dst[offset][,start[/time],end[/time]]]

where

std, dst
Three or more letters that you specify to designate the standard (std) or summer (dst) time zone. Only std is required. If dst is omitted, then summer time doesn't apply in this locale. Upper- and lowercase letters are allowed. Any characters except for a leading colon (:), digits, comma (,), minus (-), plus (+), and ASCII NUL (\0) are allowed.
Note:

There's no specified list of time zone designations, you can specify whatever name or acronym you'd like. What's important for the library is the information that follows the names -- the numbers that indicate the difference between the local time and UTC, and the rules that specify when to switch on, or out of, daylight saving time.


offset
Indicates the value one must add to the local time to arrive at Coordinated Universal Time (UTC). The offset has the form:

hh[:mm[:ss]]

Minutes (mm) and seconds (ss) are optional. The hour (hh) is required; it may be a single digit.

The offset following std is required. If no offset follows dst, summer time is assumed to be one hour ahead of standard time.

One or more digits may be used; the value is always interpreted as a decimal number. The hour may be between 0 and 24; the minutes (and seconds), if present, between 0 and 59. If preceded by a "-", the time zone is east of the prime meridian; otherwise it's west (which may be indicated by an optional preceding "+").

rule
Indicates when to change to and back from summer time. The rule has the form:

date/time,date/time

where the first date describes when the change from standard to summer time occurs, and the second date describes when the change back happens. Each time field describes when, in current local time, the change to the other time is made.

The format of date may be one of the following:

Jn
The Julian day n (1 <= n <= 365). Leap days aren't counted. That is, in all years -- including leap years -- February 28 is day 59 and March 1 is day 60. It's impossible to refer explicitly to the occasional February 29.
n
The zero-based Julian day (0 <= n <= 365). Leap years are counted; it's possible to refer to February 29.
Mm.n.d
The dth day (0 <= d <= 6) of week n of month m of the year (1 <= n <= 5, 1 <= m <= 12, where week 5 means "the last d day in month m", which may occur in the fourth or fifth week). Week 1 is the first week in which the dth day occurs. Day zero is Sunday.

The time has the same format as offset, except that no leading sign ("+" or "-") is allowed. The default, if time is omitted, is 02:00:00.

Whenever you call ctime(), ctime_r(), localtime(), or mktime(), the time zone names contained in the external variable tzname are set as if you called tzset(). The same is true if you use the %Z directive of strftime().

Time zone examples

Here are some examples:

  1. TZ=EST5EDT

    This is the default when the TZ variable isn't set.

  2. TZ=EST5EDT4,M4.1.0/02:00:00,M10.5.0/02:00:00

    This is the full specification for the default when the TZ variable isn't set.

  3. TZ=PST8PDT
  4. TZ=NST3:30NDT1:30
  5. TZ=Central Europe Time-2:00
  6. TZ=JST-9

[Previous] [Contents] [Index] [Next]