# OpenSC API Reference

sc_read_record
3
opensc

# sc_read_record

Read a record from a file

## Synopsis

    #include <opensc.h>

    int sc_read_record(struct sc_card *card, unsigned int record,
                       unsigned char *buf, size_t buflen,
                       unsigned long flags);

## Description

This function reads a record-structured elementary file (EF) from card. The function corresponds to the ISO 7816 READ RECORD function. Call sc_select_file() first to select the file to read from.

record specifies the ID of the record to be read, or, if flags is set to SC_RECORD_BY_REC_NR, the record number. If record is set to zero, the current record will be read.

The read data is stored in buf, which is buflen bytes long.

## Return value

Returns the number of bytes read if successful, or a negative value in case of error.