id3dev 26.01 An ID3 metadata library

Loading...
Searching...
No Matches
id3v1Parser.c File Reference

Declarations of ID3v1 tag parsing and memory management functions. More...

`#include <stdio.h>`
`#include <stdlib.h>`
`#include <string.h>`
`#include "id3v1/id3v1Types.h"`
`#include "id3v1/id3v1Parser.h"`
`#include "id3dependencies/ByteStream/include/byteStream.h"`
`#include "id3dependencies/ByteStream/include/byteInt.h"`
Include dependency graph for id3v1Parser.c:

Go to the source code of this file.

## Functions
bool | id3v1HasTag (const uint8_t *buffer)
| Checks if a buffer contains a valid ID3v1 tag identifier.
Id3v1Tag * | id3v1CreateTag (uint8_t *title, uint8_t *artist, uint8_t *albumTitle, int year, int track, uint8_t *comment, Genre genre)
| Creates and allocates a new Id3v1Tag structure.
void | id3v1ClearTag (Id3v1Tag *tag)
| Resets all tag fields to their default empty state.
void | id3v1DestroyTag (Id3v1Tag **toDelete)
| Frees an Id3v1Tag and nullifies the pointer.
Id3v1Tag * | id3v1TagFromBuffer (uint8_t *buffer)
| Parses an ID3V1_MAX_SIZE buffer into an Id3v1Tag structure.

## Detailed Description

Declarations of ID3v1 tag parsing and memory management functions.

Implementation of ID3v1 tag parsing and memory management functions.

Author
  Ewan Jones

Version
  26.01

Date
  2023-10-03 - 2026-01-11

Copyright
  Copyright (c) 2023 - 2026

Definition in file id3v1Parser.c.

## Function Documentation

## ◆ id3v1ClearTag()

void id3v1ClearTag | ( | Id3v1Tag * | tag | ) |

Resets all tag fields to their default empty state.

Zeros out all string fields and sets numeric fields to 0. Genre is set to OTHER_GENRE as the default unknown value.

Parameters

  tag | - The tag to clear.

Definition at line 82 of file id3v1Parser.c.

## ◆ id3v1CreateTag()

Id3v1Tag * id3v1CreateTag | ( | uint8_t * | title,
|  | uint8_t * | artist,
|  | uint8_t * | albumTitle,
|  | int | year,
|  | int | track,
|  | uint8_t * | comment,
|  | Genre | genre )

Creates and allocates a new Id3v1Tag structure.

Allocates memory, initializes all fields to zero, then copies provided values. String fields are truncated to ID3V1_FIELD_SIZE if needed. Caller must free with id3v1DestroyTag.

Parameters

  title | - Song title.
  artist | - Artist name.
  albumTitle | - Album title.
  year | - Release year
  track | - Track number
  comment | - Comment text.
  genre | - Genre enum value

Returns
  Id3v1Tag* - Heap allocated tag structure.

Definition at line 41 of file id3v1Parser.c.

## ◆ id3v1DestroyTag()

void id3v1DestroyTag | ( | Id3v1Tag ** | toDelete | ) |

Frees an Id3v1Tag and nullifies the pointer.

Deallocates the tag memory and sets the pointer to NULL to prevent dangling pointer issues.

Parameters

  toDelete | - Pointer to the tag pointer to free. Safe to call with NULL.

Definition at line 102 of file id3v1Parser.c.

## ◆ id3v1HasTag()

bool id3v1HasTag | ( | const uint8_t * | buffer | ) |

Checks if a buffer contains a valid ID3v1 tag identifier.

Compares the first ID3V1_TAG_ID_SIZE bytes of the buffer against the "TAG" identifier.

Parameters

  buffer | - The buffer to check. Must contain at least ID3V1_TAG_ID_SIZE bytes.

Returns
  bool - true if the buffer starts with "TAG", false otherwise.

Definition at line 25 of file id3v1Parser.c.

## ◆ id3v1TagFromBuffer()

Id3v1Tag * id3v1TagFromBuffer | ( | uint8_t * | buffer | ) |

Parses an ID3V1_MAX_SIZE buffer into an Id3v1Tag structure.

Performs sequential field extraction with extensive error checking. Returns partial tags with default values if parsing fails partway through. Detects ID3v1.1 track numbers via null byte at position 28.

Parameters

  buffer | - Buffer containing ID3V1_MAX_SIZE (128) bytes to parse.

Returns
  Id3v1Tag* - Newly allocated tag on success, partial tag with defaults on read errors, NULL if "TAG" identifier missing. Caller must free with id3v1DestroyTag.

Definition at line 119 of file id3v1Parser.c.