Subversion Repositories SvarDOS

Rev

Rev 614 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 614 Rev 1972
Line 1... Line 1...
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-2024 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
 
Line 10... Line 10...
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, const char *field, char *result, size_t result_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 */
-
 
20
  version[0] = 0;
-
 
-
 
19
 
21
  /* open the file */
20
  /* open the file */
22
  fd = fopen(filename, "rb");
21
  fd = fopen(filename, "rb");
-
 
22
  result[0] = 0; /* reset fields to be read to empty values (now in case it is the same ptr as filename) */
23
  if (fd == NULL) return(-1);
23
  if (fd == NULL) return(-1);
24
  /* read the LSM file line by line */
-
 
25
 
24
 
-
 
25
  /* read the LSM file line by line */
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) continue;
-
 
28
    if (strcasecmp(linebuff, field) == 0) {
28
      if (strcasecmp(linebuff, "version") == 0) snprintf(version, version_maxlen, "%s", valuestr);
29
      snprintf(result, result_maxlen, "%s", valuestr);
-
 
30
      break;
29
    }
31
    }
30
  }
32
  }
31
  fclose(fd);
33
  fclose(fd);
32
  return(0);
34
  return(0);
33
}
35
}