---
name: "ACE_Errno_Guard"
section: "3"
platform: "linux"
package: "libace-doc"
version: "5.0.7-4"
release: "Debian 2.2 (Potato)"
platforms: ["linux"]
url: "https://new.carta.tech/ACE_Errno_Guard"
---

# ACE\_Errno\_Guard(3)

Provides a wrapper to improve performance when thread-specific errno must be saved and restored in a block of code.

## NAME

ACE\_Errno\_Guard -  Provides a wrapper to improve performance when thread-specific errno must be saved and restored in a block of code.

## SYNOPSIS

```
#include <ace/OS.h>
class ACE_Errno_Guard
{
  public:
    ACE_Errno_Guard (ACE_ERRNO_TYPE &errno_ref, int error);
    ACE_Errno_Guard (ACE_ERRNO_TYPE &errno_ref);
    ~ACE_Errno_Guard (void);
    int operator= (const ACE_ERRNO_TYPE &errno_ref);
    int operator= (int error);
    int operator== (int error);
    int operator!= (int error);
  private:
    ACE_ERRNO_TYPE *errno_ptr_;
    int error_;
};
```

## DESCRIPTION

The typical use-case for this is the following:

int error = errno; call\_some\_function\_that\_might\_change\_errno (); errno = error;

This can be replaced with

{\
   ACE\_Errno\_Guard guard (errno);\
   call\_some\_function\_that\_might\_change\_errno (); }

This implementation is more elegant and more efficient since it avoids an unnecessary second access to thread-specific storage by caching a pointer to the value of errno in TSS.

## Initialization and termination methods.

```
ACE_Errno_Guard (ACE_ERRNO_TYPE &errno_ref, int error);
```

Stash the value of error into error\_ and initialize the errno\_ptr\_ to the address of errno\_ref.

```
ACE_Errno_Guard (ACE_ERRNO_TYPE &errno_ref);
```

Stash the value of errno into error\_ and initialize the errno\_ptr\_ to the address of errno\_ref.

```
~ACE_Errno_Guard (void);
```

Reset the value of errno to error.

```
int operator= (const ACE_ERRNO_TYPE &errno_ref);
```

Assign errno\_ref to error\_.

```
int operator= (int error);
```

Assign error to error\_.

```
int operator== (int error);
```

Compare error with error\_ for equality.

```
int operator!= (int error);
```

Compare error with error\_ for inequality.

## AUTHOR

Doug Schmidt schmidt@cs.wustl.edu, Jesper S. M\|ller stophph@diku.dk, and a cast of thousands...

## The ACE\_Sched\_Priority type should be used for platform-

independent thread and process priorities, by convention. int should be used for OS-specific priorities.

## typedef for the \_stat data structure

## Giving unique ACE scoped names for some important

RTSignal-Related constants. Becuase sometimes, different platforms use different names for these constants.

## LIBRARY

ace
