Subversion Repositories SvarDOS

Rev

Rev 269 | Rev 1972 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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