---
name: "afOpenFile"
section: "3"
platform: "linux"
package: "audiofile"
version: "0.3.6-12"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/afOpenFile"
---

# afOpenFile(3)

open an audio file and create a file handle structure used for subsequent calls to the Audio File Library

## NAME

afOpenFile - open an audio file and create a file handle structure used for subsequent calls to the Audio File Library

## SYNOPSIS

```
#include <audiofile.h>
```

```
AFfilehandle afOpenFile(const char *path, const char *mode,
    AFfilesetup setup);
```

## PARAMETERS

*path* is the path to the file to be opened.

*mode* specifies a mode for opening the file: "r" for reading or "w" for writing.

*setup* is an AFfilesetup created by [**afNewFileSetup**(3)](/afNewFileSetup/3.md). This value is ignored for files opened for reading except when the file format is AF\_FILE\_RAWDATA.

## RETURN VALUE

Upon success, afOpenFile returns a valid AFfilehandle which can be used in subsequent calls to the Audio File Library. Upon failure, afOpenFile returns NULL and generates an error.

[**afCloseFile**(3)](/afCloseFile/3.md) is used to close the file when it is no longer needed.

## ERRORS

afOpenFile can produce the following errors:

AF\_BAD\_OPEN

A call to open failed.

AF\_BAD\_READ

A call to read failed

AF\_BAD\_WRITE

A call to write failed.

AF\_BAD\_LSEEK

A call to lseek failed.

AF\_BAD\_MALLOC

Memory allocation failed.

AF\_BAD\_FILEFMT

setup specifies a file format which is unsupported for mode.

AF\_BAD\_SAMPFMT

The file’s sample format is not supported.

AF\_BAD\_WIDTH

The file’s sample width is not supported.

AF\_BAD\_RATE

The file’s sample rate is not supported.

AF\_BAD\_CHANNELS

The number of channels in the file is not supported.

AF\_BAD\_FILESETUP

setup specifies an invalid or unsupported configuration.

## SEE ALSO

[**afCloseFile**(3)](/afCloseFile/3.md), [**afNewFileSetup**(3)](/afNewFileSetup/3.md), [**afInitFileFormat**(3)](/afInitFileFormat/3.md), [**afInitSampleFormat**(3)](/afInitSampleFormat/3.md), [**afReadFrames**(3)](/afReadFrames/3.md), [**afWriteFrames**(3)](/afWriteFrames/3.md)

## AUTHOR

Michael Pruett \<michael@68k.org\>
