~ubuntu-branches/ubuntu/karmic/libtinymail/karmic

« back to all changes in this revision

Viewing changes to libtinymail-camel/camel-lite/camel/camel-win32.c

  • Committer: Bazaar Package Importer
  • Author(s): Steve Kowalik
  • Date: 2007-10-12 11:21:12 UTC
  • Revision ID: james.westby@ubuntu.com-20071012112112-fod9fs7yrooxjr7i
Tags: upstream-0.0.2
ImportĀ upstreamĀ versionĀ 0.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
 
2
/* camel-win32.c : Win32-specific bits */
 
3
 
 
4
/*
 
5
 * Authors: Tor Lillqvist <tml@novell.com>
 
6
 *
 
7
 * Copyright 2005 Novell, Inc. (www.novell.com)
 
8
 *
 
9
 * This program is free software; you can redistribute it and/or
 
10
 * modify it under the terms of version 2 of the GNU Lesser General Public
 
11
 * License as published by the Free Software Foundation.
 
12
 *
 
13
 * This program is distributed in the hope that it will be useful,
 
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
 * GNU Lesser General Public License for more details.
 
17
 *
 
18
 * You should have received a copy of the GNU Lesser General Public License
 
19
 * along with this program; if not, write to the Free Software
 
20
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 
21
 * USA
 
22
 */
 
23
 
 
24
#include <errno.h>
 
25
#include <io.h>
 
26
#include <stdlib.h>
 
27
#include <sys/stat.h>
 
28
 
 
29
#include <windows.h>
 
30
 
 
31
#include <glib.h>
 
32
#include <glib/gstdio.h>
 
33
 
 
34
#include <libedataserver/e-data-server-util.h>
 
35
 
 
36
#include "camel.h"
 
37
 
 
38
G_LOCK_DEFINE_STATIC (mutex);
 
39
 
 
40
/* localedir uses system codepage as it is passed to the non-UTF8ified
 
41
 * gettext library
 
42
 */
 
43
static const char *localedir = NULL;
 
44
 
 
45
/* The others are in UTF-8 */
 
46
static const char *libexecdir;
 
47
static const char *providerdir;
 
48
 
 
49
static void
 
50
setup (void)
 
51
{
 
52
        G_LOCK (mutex);
 
53
        if (localedir != NULL) {
 
54
                G_UNLOCK (mutex);
 
55
                return;
 
56
        }
 
57
 
 
58
        localedir = e_util_replace_prefix (E_DATA_SERVER_PREFIX, e_util_get_cp_prefix (), LOCALEDIR);
 
59
 
 
60
        libexecdir = e_util_replace_prefix (E_DATA_SERVER_PREFIX, e_util_get_prefix (), CAMEL_LIBEXECDIR);
 
61
        providerdir = e_util_replace_prefix (E_DATA_SERVER_PREFIX, e_util_get_prefix (), CAMEL_PROVIDERDIR);
 
62
 
 
63
        G_UNLOCK (mutex);
 
64
}
 
65
 
 
66
#include "camel-private.h"      /* For prototypes */
 
67
 
 
68
#define GETTER(varbl)                           \
 
69
const char *                                    \
 
70
_camel_get_##varbl (void)                       \
 
71
{                                               \
 
72
        setup ();                               \
 
73
        return varbl;                           \
 
74
}
 
75
 
 
76
GETTER(localedir)
 
77
GETTER(libexecdir)
 
78
GETTER(providerdir)
 
79
 
 
80
int
 
81
fsync (int fd)
 
82
{
 
83
        int handle;
 
84
        struct stat st;
 
85
 
 
86
        handle = _get_osfhandle (fd);
 
87
        if (handle == -1)
 
88
                return -1;
 
89
 
 
90
        fstat (fd, &st);
 
91
 
 
92
        /* FlushFileBuffers() fails if called on a handle to the
 
93
         * console output. As we cannot know whether fd refers to the
 
94
         * console output or not, punt, and call FlushFileBuffers()
 
95
         * only for regular files and pipes.
 
96
         */
 
97
        if (!(S_ISREG (st.st_mode) || S_ISFIFO (st.st_mode)))
 
98
                return 0;
 
99
 
 
100
        if (FlushFileBuffers ((HANDLE) handle))
 
101
                return 0;
 
102
 
 
103
        errno = EIO;
 
104
        return -1;
 
105
}
 
106