---
name: "sc_establish_context"
section: "3"
platform: "linux"
package: "libopensc2-dev"
version: "0.11.13-1.1"
release: "Debian 6.0 (Squeeze)"
platforms: ["linux"]
url: "https://new.carta.tech/sc_establish_context"
---

# sc\_establish\_context(3)

Establish an OpenSC context

## NAME

sc\_establish\_context - Establish an OpenSC context

## SYNOPSIS

```
#include <opensc.h>
int sc_establish_context(sc_context_t **ctx,
                         const char *appname);
```

## DESCRIPTION

This function establishes an OpenSC context. This context is required in all subsequent calls to OpenSC functions.

*ctx* is a pointer to a pointer that will receive the allocated context.

*appname* is a string that identifies the application. This string will be used to apply application-specific settings from the opensc.conf configuration file. If NULL is passed, only the settings specified in the default section apply; otherwise, settings from the section identified by *appname* will be applied as well.

The sc\_context structure contains the following members:

```
#define SC_MAX_READERS			16
typedef struct sc_context {
	struct sc_reader *reader[SC_MAX_READERS];
	int reader_count;
} sc_context_t;
```

The *reader\_count* field contains the number of readers found. Information on the individual card readers is stored in *sc\_reader* objects, defined as follows:

```
typedef struct sc_reader {
	char *name;
	int slot_count;
}; sc_reader_t;
```

In this structure, *name* contains a printable name of the reader, and *slot\_count* has the number of slots supported by this device.

## RETURN VALUE

Returns 0 if successful, or a negative value in case of error.
