Skip to content

Repo sync for protected CLA branch #4243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Oct 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ ms.assetid: 842d1dc7-d6f8-41d3-b340-108d4b90df54
---
# `localtime_s`, `_localtime32_s`, `_localtime64_s`

Converts a **`time_t`** time value to a **`tm`** structure, and corrects for the local time zone. These are versions of [`localtime`, `_localtime32`, `_localtime64`](localtime-localtime32-localtime64.md) with security enhancements as described in [Security features in the CRT](../security-features-in-the-crt.md).
Converts a **`time_t`** time value to a **`tm`** structure, and corrects for the local time zone. These functions are versions of [`localtime`, `_localtime32`, `_localtime64`](localtime-localtime32-localtime64.md) with security enhancements as described in [Security features in the CRT](../security-features-in-the-crt.md).

## Syntax

Expand Down Expand Up @@ -41,7 +41,7 @@ Pointer to the stored time.

## Return value

Zero if successful. The return value is an error code if there is a failure. Error codes are defined in *`Errno.h`*. For a listing of these errors, see [`errno`](../errno-doserrno-sys-errlist-and-sys-nerr.md).
Zero if successful. The return value is an error code if there's a failure. Error codes are defined in *`Errno.h`*. For a listing of these errors, see [`errno`](../errno-doserrno-sys-errlist-and-sys-nerr.md).

### Error conditions

Expand All @@ -51,20 +51,20 @@ Zero if successful. The return value is an error code if there is a failure. Err
|Not `NULL` (points to valid memory)|`NULL`|`EINVAL`|All fields set to -1|Yes|
|Not `NULL` (points to valid memory)|less than 0 or greater than `_MAX__TIME64_T`|`EINVAL`|All fields set to -1|No|

In the case of the first two error conditions, the invalid parameter handler is invoked, as described in [Parameter validation](../parameter-validation.md). If execution is allowed to continue, these functions set `errno` to `EINVAL` and return `EINVAL`.
The first two error conditions invoke the invalid parameter handler, as described in [Parameter validation](../parameter-validation.md). If execution is allowed to continue, these functions set `errno` to `EINVAL` and return `EINVAL`.

## Remarks

The **`localtime_s`** function converts a time stored as a [`time_t`](../standard-types.md) value and stores the result in a structure of type [`tm`](../standard-types.md). The **`time_t`** value *`sourceTime`* represents the seconds elapsed since midnight (00:00:00), January 1, 1970, UTC. This value is usually obtained from the [`time`](time-time32-time64.md) function.
The **`localtime_s`** function converts a time stored as a [`time_t`](../standard-types.md) value and stores the result in a structure of type [`tm`](../standard-types.md). The **`time_t`** value *`sourceTime`* represents the seconds elapsed since midnight (00:00:00), January 1, 1970, UTC. This value is often obtained from the [`time`](time-time32-time64.md) function.

**`localtime_s`** corrects for the local time zone if the user first sets the global environment variable **`TZ`**. When **`TZ`** is set, three other environment variables (**`_timezone`**, **`_daylight`**, and **`_tzname`**) are automatically set as well. If the **`TZ`** variable is not set, **`localtime_s`** attempts to use the time zone information specified in the Date/Time application in Control Panel. If this information cannot be obtained, PST8PDT, which signifies the Pacific time zone, is used by default. See [`_tzset`](tzset.md) for a description of these variables. **`TZ`** is a Microsoft extension and not part of the ANSI standard definition of **`localtime`**.
**`localtime_s`** corrects for the local time zone if the user first sets the global environment variable **`TZ`**. When **`TZ`** is set, three other environment variables (**`_timezone`**, **`_daylight`**, and **`_tzname`**) are automatically set as well. If the **`TZ`** variable isn't set, **`localtime_s`** attempts to use the time zone information specified in the Date/Time application in Control Panel. If this information can't be obtained, PST8PDT, which signifies the Pacific time zone, is used by default. See [`_tzset`](tzset.md) for a description of these variables. **`TZ`** is a Microsoft extension and not part of the ANSI standard definition of **`localtime`**.

> [!NOTE]
> The target environment should try to determine whether daylight saving time is in effect.

**`_localtime64_s`**, which uses the **`__time64_t`** structure, allows dates to be expressed up through 23:59:59, January 18, 3001, coordinated universal time (UTC), whereas **`_localtime32_s`** represents dates through 23:59:59 January 18, 2038, UTC.

**`localtime_s`** is an inline function which evaluates to **`_localtime64_s`**, and **`time_t`** is equivalent to **`__time64_t`**. If you need to force the compiler to interpret **`time_t`** as the old 32-bit **`time_t`**, you can define `_USE_32BIT_TIME_T`. Doing this will cause **`localtime_s`** to evaluate to **`_localtime32_s`**. This is not recommended because your application may fail after January 18, 2038, and it is not allowed on 64-bit platforms.
**`localtime_s`** is an inline function that evaluates to **`_localtime64_s`**, and **`time_t`** is equivalent to **`__time64_t`**. If you need to force the compiler to interpret **`time_t`** as the old 32-bit **`time_t`**, you can define `_USE_32BIT_TIME_T`, which causes **`localtime_s`** to evaluate to **`_localtime32_s`**. We don't recommend `_USE_32BIT_TIME_T`, because your application may fail after January 18, 2038, and it isn't allowed on 64-bit platforms.

The fields of the structure type [`tm`](../standard-types.md) store the following values, each of which is an **`int`**.

Expand All @@ -78,7 +78,7 @@ The fields of the structure type [`tm`](../standard-types.md) store the followin
|**`tm_year`**|Year (current year minus 1900).|
|**`tm_wday`**|Day of week (0 - 6; Sunday = 0).|
|**`tm_yday`**|Day of year (0 - 365; January 1 = 0).|
|**`tm_isdst`**|Positive value if daylight saving time is in effect; 0 if daylight saving time is not in effect; negative value if status of daylight saving time is unknown.|
|**`tm_isdst`**|Positive value if daylight saving time is in effect; 0 if daylight saving time isn't in effect; negative value if status of daylight saving time is unknown.|

If the **`TZ`** environment variable is set, the C run-time library assumes rules appropriate to the United States for implementing the calculation of daylight saving time (DST).

Expand Down
2 changes: 1 addition & 1 deletion docs/c-runtime-library/reference/lock-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ File handle.

## Remarks

The **`_lock_file`** function locks the `FILE` object specified by *`file`*. The underlying file is not locked by **`_lock_file`**. Use [`_unlock_file`](unlock-file.md) to release the lock on the file. Calls to **`_lock_file`** and **`_unlock_file`** must be matched in a thread.
The **`_lock_file`** function locks the `FILE` object specified by *`file`*. The underlying file isn't locked by **`_lock_file`**. Use [`_unlock_file`](unlock-file.md) to release the lock on the file. Calls to **`_lock_file`** and **`_unlock_file`** must be matched in a thread.

By default, this function's global state is scoped to the application. To change this behavior, see [Global state in the CRT](../global-state.md).

Expand Down
10 changes: 5 additions & 5 deletions docs/c-runtime-library/reference/locking.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,26 @@ Number of bytes to lock.
|-|-|
| `EACCES` | Locking violation (file already locked or unlocked). |
| `EBADF` | Invalid file descriptor. |
| `EDEADLOCK` | Locking violation. Returned when the `_LK_LOCK` or `_LK_RLCK` flag is specified and the file cannot be locked after 10 attempts. |
| `EDEADLOCK` | Locking violation. Returned when the `_LK_LOCK` or `_LK_RLCK` flag is specified and the file can't be locked after 10 attempts. |
| `EINVAL` | An invalid argument was given to **`_locking`**. |

If the failure is due to a bad parameter, such as an invalid file descriptor, the invalid parameter handler is invoked, as described in [Parameter validation](../parameter-validation.md).

## Remarks

The **`_locking`** function locks or unlocks *`nbytes`* bytes of the file specified by *`fd`*. Locking bytes in a file prevents access to those bytes by other processes. All locking or unlocking begins at the current position of the file pointer and proceeds for the next *`nbytes`* bytes. It is possible to lock bytes past end of file.
The **`_locking`** function locks or unlocks *`nbytes`* bytes of the file specified by *`fd`*. Locking bytes in a file prevents access to those bytes by other processes. All locking or unlocking begins at the current position of the file pointer and proceeds for the next *`nbytes`* bytes. It's possible to lock bytes past end of file.

*`mode`* must be one of the following manifest constants, which are defined in Locking.h.

|*`mode`* value|Effect|
|-|-|
| `_LK_LOCK` | Locks the specified bytes. If the bytes cannot be locked, the program immediately tries again after 1 second. If, after 10 attempts, the bytes cannot be locked, the constant returns an error. |
| `_LK_NBLCK` | Locks the specified bytes. If the bytes cannot be locked, the constant returns an error. |
| `_LK_LOCK` | Locks the specified bytes. If the bytes can't be locked, the program immediately tries again after 1 second. If the bytes can't be locked after 10 attempts, the constant returns an error. |
| `_LK_NBLCK` | Locks the specified bytes. If the bytes can't be locked, the constant returns an error. |
| `_LK_NBRLCK` | Same as `_LK_NBLCK`. |
| `_LK_RLCK` | Same as `_LK_LOCK`. |
| `_LK_UNLCK` | Unlocks the specified bytes, which must have been previously locked. |

Multiple regions of a file that do not overlap can be locked. A region being unlocked must have been previously locked. **`_locking`** does not merge adjacent regions; if two locked regions are adjacent, each region must be unlocked separately. Regions should be locked only briefly and should be unlocked before closing a file or exiting the program.
Multiple regions of a file that don't overlap can be locked. A region being unlocked must have been previously locked. **`_locking`** doesn't merge adjacent regions; if two locked regions are adjacent, each region must be unlocked separately. Regions should be locked only briefly and should be unlocked before closing a file or exiting the program.

By default, this function's global state is scoped to the application. To change this behavior, see [Global state in the CRT](../global-state.md).

Expand Down
4 changes: 2 additions & 2 deletions docs/c-runtime-library/reference/log-logf-log10-log10f.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ Value whose logarithm is to be found.

The **`log`** functions return the natural logarithm (base *`e`*) of *`x`* if successful. The **`log10`** functions return the base-10 logarithm. If *`x`* is negative, these functions return an indefinite (`IND`), by default. If *`x`* is 0, they return infinity (`INF`).

|Input|SEH Exception|Matherr Exception|
|Input|SEH Exception|`Matherr` Exception|
|-----------|-------------------|-----------------------|
`QNAN`, `IND`|none|`_DOMAIN`|
|± QNAN, IND|none|`_DOMAIN`|
|± 0|`ZERODIVIDE`|`_SING`|
|*`x < 0`*|`INVALID`|`_DOMAIN`|

Expand Down
8 changes: 4 additions & 4 deletions docs/c-runtime-library/reference/log1p-log1pf-log1pl2.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ Otherwise, may return one of the following values:

|Input|Result|SEH exception|errno|
|-----------|------------|-------------------|-----------|
|+inf|+inf|||
|+INF|+INF|||
|Denormals|Same as input|UNDERFLOW||
|±0|Same as input|||
|-1|-inf|DIVBYZERO|ERANGE|
|< -1|nan|INVALID|EDOM|
|-inf|nan|INVALID|EDOM|
|-1|-INF|DIVBYZERO|ERANGE|
|< -1|NaN|INVALID|EDOM|
|-INF|NaN|INVALID|EDOM|
|±SNaN|Same as input|INVALID||
|±QNaN, indefinite|Same as input|||

Expand Down
4 changes: 2 additions & 2 deletions docs/c-runtime-library/reference/log2-log2f-log2l.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ The value to determine the base-2 logarithm of.

## Return value

On success, returns return log2 *`x`*.
On success, the functions return the base-2 log of *`x`*.

Otherwise, may return one of the following values:
Otherwise, the functions may return one of the following values:

|Issue|Return|
|-----------|------------|
Expand Down
14 changes: 7 additions & 7 deletions docs/c-runtime-library/reference/longjmp.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,25 @@ Value to be returned to `setjmp` call.

## Remarks

The **`longjmp`** function restores a stack environment and execution locale previously saved in *`env`* by `setjmp`. `setjmp` and **`longjmp`** provide a way to execute a nonlocal **`goto`**; they are typically used to pass execution control to error-handling or recovery code in a previously called routine without using the normal call and return conventions.
The **`longjmp`** function restores a stack environment and execution locale previously saved in *`env`* by `setjmp`. `setjmp` and **`longjmp`** provide a way to execute a nonlocal **`goto`**; they're typically used to pass execution control to error-handling or recovery code in a previously called routine without using the normal call and return conventions.

A call to `setjmp` causes the current stack environment to be saved in *`env`*. A subsequent call to **`longjmp`** restores the saved environment and returns control to the point immediately following the corresponding `setjmp` call. Execution resumes as if *`value`* had just been returned by the `setjmp` call. The values of all variables (except register variables) that are accessible to the routine receiving control contain the values they had when **`longjmp`** was called. The values of register variables are unpredictable. The value returned by `setjmp` must be nonzero. If *`value`* is passed as 0, the value 1 is substituted in the actual return.
A call to `setjmp` causes the current stack environment to be saved in *`env`*. A subsequent call to **`longjmp`** restores the saved environment and returns control to the point immediately following the corresponding `setjmp` call. Execution resumes as if *`value`* had been returned by the `setjmp` call. The values of all variables (except register variables) that are accessible to the routine receiving control contain the values they had when **`longjmp`** was called. The values of register variables are unpredictable. The value returned by `setjmp` must be nonzero. If *`value`* is passed as 0, the value 1 is substituted in the actual return.

**Microsoft Specific**

In Microsoft C++ code on Windows, **`longjmp`** uses the same stack-unwinding semantics as exception-handling code. It is safe to use in the same places that C++ exceptions can be raised. However, this usage is not portable, and comes with some important caveats.
In Microsoft C++ code on Windows, **`longjmp`** uses the same stack-unwinding semantics as exception-handling code. It's safe to use in the same places that C++ exceptions can be raised. However, this usage isn't portable, and comes with some important caveats.

Only call **`longjmp`** before the function that called `setjmp` returns; otherwise the results are unpredictable.

Observe the following restrictions when using **`longjmp`**:

- Do not assume that the values of the register variables will remain the same. The values of register variables in the routine calling `setjmp` may not be restored to the proper values after **`longjmp`** is executed.
- Don't assume that the values of the register variables will remain the same. The values of register variables in the routine calling `setjmp` may not be restored to the proper values after **`longjmp`** is executed.

- Do not use **`longjmp`** to transfer control out of an interrupt-handling routine unless the interrupt is caused by a floating-point exception. In this case, a program may return from an interrupt handler via **`longjmp`** if it first reinitializes the floating-point math package by calling [`_fpreset`](fpreset.md).
- Don't use **`longjmp`** to transfer control out of an interrupt-handling routine unless the interrupt is caused by a floating-point exception. In this case, a program may return from an interrupt handler via **`longjmp`** if it first reinitializes the floating-point math package by calling [`_fpreset`](fpreset.md).

- Do not use **`longjmp`** to transfer control from a callback routine invoked directly or indirectly by Windows code.
- Don't use **`longjmp`** to transfer control from a callback routine invoked directly or indirectly by Windows code.

- If the code is compiled by using **/EHs** or **/EHsc** and the function that contains the **`longjmp`** call is **`noexcept`** then local objects in that function may not be destructed during the stack unwind.
- If the code is compiled by using **/EHs** or **/EHsc**, and the function that contains the **`longjmp`** call is **`noexcept`**, then local objects in that function may not be destructed during the stack unwind.

**END Microsoft Specific**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Because C++ allows overloading, you can call overloads of **`lrint`** and **`llr

If you use the \<tgmath.h> `llrint()` macro, the type of the argument determines which version of the function is selected. See [Type-generic math](../tgmath.md) for details.

If *`x`* does not represent the floating-point equivalent of an integral value, these functions raise `FE_INEXACT`.
If *`x`* doesn't represent the floating-point equivalent of an integral value, these functions raise `FE_INEXACT`.

**Microsoft-specific**: When the result is outside the range of the return type, or when the parameter is a NaN or infinity, the return value is implementation defined. The Microsoft compiler returns a zero (0) value.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ The floating-point value to round.

The **`lround`** and **`llround`** functions return the nearest **`long`** or **`long long`** integer to *`x`*. Halfway values are rounded away from zero, regardless of the setting of the floating-point rounding mode. There's no error return.

|Input|SEH Exception|Matherr Exception|
|Input|SEH Exception|`Matherr` Exception|
|-----------|-------------------|-----------------------|
|± `QNAN`, `IND`|none|`_DOMAIN`|

## Remarks

Because C++ allows overloading, you can call overloads of **`lround`** or **`llround`** that take and return **`float`** and **`long double`** values. In a C program, unless you're using the \<tgmath.h> macro to call this function, **`lround`** and **`llround`** always take and return a **`double`**.
Because C++ allows overloading, you can call **`lround`** or **`llround`** overloads that take and return **`float`** and **`long double`** values. In a C program, unless you're using the \<tgmath.h> macro to call this function, **`lround`** and **`llround`** always take and return a **`double`**.

If you use the \<tgmath.h> `lround()` macro, the type of the argument determines which version of the function is selected. See [Type-generic math](../tgmath.md) for details.

Expand Down
Loading