Subversion Repositories SvarDOS

Rev

Rev 614 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
219 mateuszvis 1
/*
268 mateuszvis 2
 * This file is part of pkg (SvarDOS)
3
 * Copyright (C) 2013-2021 Mateusz Viste
219 mateuszvis 4
 */
5
 
6
#include <stdio.h>   /* fopen, fclose... */
7
#include <string.h>  /* strcasecmp() */
8
 
249 mateuszvis 9
#include "helpers.h"
10
 
219 mateuszvis 11
#include "lsm.h"     /* include self for control */
12
 
13
 
14
/* Loads metadata from an LSM file. Returns 0 on success, non-zero on error. */
249 mateuszvis 15
int readlsm(const char *filename, char *version, size_t version_maxlen) {
219 mateuszvis 16
  char linebuff[128];
17
  char *valuestr;
18
  FILE *fd;
19
  /* reset fields to be read to empty values */
20
  version[0] = 0;
21
  /* open the file */
22
  fd = fopen(filename, "rb");
23
  if (fd == NULL) return(-1);
24
  /* read the LSM file line by line */
249 mateuszvis 25
 
26
  while (freadtokval(fd, linebuff, sizeof(linebuff), &valuestr, ':') == 0) {
27
    if (valuestr != NULL) {
245 mateuszvis 28
      if (strcasecmp(linebuff, "version") == 0) snprintf(version, version_maxlen, "%s", valuestr);
219 mateuszvis 29
    }
30
  }
31
  fclose(fd);
32
  return(0);
33
}