---
name: "sc_write_record"
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_write_record"
---

# sc\_write\_record(3)

Write a record to a file

## NAME

sc\_write\_record - Write a record to a file

## SYNOPSIS

```
#include <opensc.h>
int sc_write_record(struct sc_card *card, unsigned int record,
                    const unsigned char *buf, size_t buflen,
                    unsigned long flags);
```

## DESCRIPTION

This function writes a record that is *buflen* bytes long from the buffer pointed to by *buf* to a record-structured elementary file (EF) on *card*. The function corresponds to the ISO 7816 WRITE RECORD function. Call sc\_select\_file() first to select the file to write to.

*record* specifies the ID of the record to be written, 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.

This function is used for newly created files only; for updating or appending to existing files, see the sc\_update\_record() and sc\_append\_record() functions, respectively.

## RETURN VALUE

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