text-store.c 1020 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

#include <string.h>
#include <errno.h>
#include <stdio.h>

#include "log.h"
#include "server/smalloc.h"
#include "kom-types.h"
#include "lyskomd.h"
13
#include "text-store.h"
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

extern Success
text_store_load_text(Text_no tno,
		     const Text_stat *t_stat,
		     String *res,
		     FILE *text_file)
{
    if (t_stat->text_store.generation == 0)
    {
	if (fseek(text_file, t_stat->text_store.file_pos, SEEK_SET) != 0)
	{
	    kom_log("Failed to seek to %ld in text mass file: %s.\n",
		    t_stat->text_store.file_pos, strerror(errno));
	    return FAILURE;
	}

	res->string = tmp_alloc(t_stat->no_of_chars);
	res->len = t_stat->no_of_chars;

	if ( fread(res->string, sizeof(char), res->len, text_file)
	    != (size_t)res->len )
	{
	    kom_log("WARNING: cached_get_text: premature end on text %lu\n",
		    tno);
	    return FAILURE;
	}

	return OK;
    }
    else
    {
#warning Generation > 0 not yet handled
	restart_kom("Only generation 0 is handled.\n");
    }
}