~ubuntu-branches/ubuntu/precise/libdatrie/precise

« back to all changes in this revision

Viewing changes to datrie/fileutils.c

  • Committer: Bazaar Package Importer
  • Author(s): Theppitak Karoonboonyanan
  • Date: 2009-04-29 15:24:31 UTC
  • mfrom: (1.2.1 upstream) (3.1.1 karmic)
  • Revision ID: james.westby@ubuntu.com-20090429152431-8zmxgfvir3mrog08
* Use complete sentences in libdatrie1 long description. (Closes: #525806)
* New upstream release, fixing builds on non-GNU systems.
* Remove duplicated field "section" for libdatrie1 [lintian].

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
 
11
11
#include "fileutils.h"
12
12
 
13
 
/*--------------------------------------*
14
 
 *    INTERNAL FUNCTIONS DECLARATIONS   *
15
 
 *--------------------------------------*/
16
 
 
17
 
static char *   make_full_path (const char *dir,
18
 
                                const char *name,
19
 
                                const char *ext);
20
 
 
21
13
/* ==================== BEGIN IMPLEMENTATION PART ====================  */
22
14
 
23
15
/*--------------------------------*
24
16
 *    FUNCTIONS IMPLEMENTATIONS   *
25
17
 *--------------------------------*/
26
18
 
27
 
static char *
28
 
make_full_path (const char *dir, const char *name, const char *ext)
29
 
{
30
 
    char   *path;
31
 
 
32
 
    path = (char *) malloc (strlen (dir) + strlen (name) + strlen (ext) + 2);
33
 
    sprintf (path, "%s/%s%s", dir, name, ext);
34
 
 
35
 
    return path;
36
 
}
37
 
 
38
 
FILE *
39
 
file_open (const char *dir, const char *name, const char *ext, TrieIOMode mode)
40
 
{
41
 
    const char *std_mode;
42
 
    char       *full_path;
43
 
    FILE       *file;
44
 
 
45
 
    if (mode & TRIE_IO_WRITE)
46
 
        std_mode = "r+";
47
 
    else
48
 
        std_mode = "r";
49
 
 
50
 
    full_path = make_full_path (dir, name, ext);
51
 
    file = fopen (full_path, std_mode);
52
 
    if (!file && mode & TRIE_IO_CREATE)
53
 
        file = fopen (full_path, "w+");
54
 
    free (full_path);
55
 
 
56
 
    return file;
57
 
}
58
 
 
59
 
long
60
 
file_length (FILE *file)
61
 
{
62
 
    long    cur_pos;
63
 
    long    size;
64
 
 
65
 
    cur_pos = ftell (file);
66
 
 
67
 
    fseek (file, 0L, SEEK_END);
68
 
    size = ftell (file);
69
 
 
70
 
    fseek (file, cur_pos, SEEK_SET);
71
 
 
72
 
    return size;
73
 
}
74
 
 
75
19
Bool
76
20
file_read_int32 (FILE *file, int32 *o_val)
77
21
{