~ubuntu-desktop/compiz/quantal

« back to all changes in this revision

Viewing changes to compizconfig/libcompizconfig/src/ccs_text_file.c

  • Committer: Łukasz 'sil2100' Zemczak
  • Date: 2012-09-27 14:05:41 UTC
  • mfrom: (3248.2.11)
  • Revision ID: lukasz.zemczak@canonical.com-20120927140541-c1f3gk2no4x2iczw
* New upstream release.
  - FTBFS with -DCOMPIZ_BUILD_TESTING=OFF if libgtest-dev is not installed 
    (LP: #1057421)
  - [performance] glXSwapIntervalEXT called every frame, which is very slow 
    on Nvidia. (LP: #1051286)
  - opacify plugin: opacity isn't reset after switching window (LP: #1050757)
  - cmake fails on python 2.6 as sys.version_info does not contain 
    major_version or minor_version (LP: #1048964)
  - scale mode is not visible if a fullscreen window is unredirected 
    (LP: #1047168)
  - Unredirected fullscreen windows flicker briefly when another window 
    (like a menu) opens above them (LP: #1046664)
  - Week33 - Grid highlight window appears while switching between workspaces
    (LP: #1037142)
  - gtk-window-decorator leaks large numbers of pixmaps and pixmap memory 
    (LP: #1057263)
  - [fglrx] compiz crashed with SIGSEGV in glXDestroyContext() 
    [/usr/lib/fglrx/libGL.so.1] from GLScreen::~GLScreen() (LP: #1054724)
  - Maximized window gets unredirected when it's not fullscreen 
    (LP: #1053902)
  - Double shortcuts conflict with gnome-control-center ones (LP: #1050796)
  - gtk-window-decorator leaking window handles. Window operations become 
    sluggish after a few days of usage (LP: #1050610)
  - [valgrind] Up to 520,000 bytes lost when running 
    CCSGSettingsBackendConceptTest (LP: #1049169)
  - 1:0.9.8+bzr3319-0ubuntu1 regression: keeps setting gsettings keys to 
    wrong values (LP: #1042041)
  - Compiz r3275 breaks VirtualBox Guest Additions: black screen or just 
    wallpaper (LP: #1030891)
  - Incorrect (low/stuttering) refresh rate with NVIDIA driver (LP: #92599)
  - ARM build broken with 'swapInterval' is not a member of 'GL' 
    (LP: #1056645)
  - compiz.fix_927168 broke ARM building (LP: #1052838)
  - compiz crashed with SIGSEGV in __strcasestr_ia32() from 
    ccsStringToModifiers(binding=NULL) (LP: #1041535)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Compiz configuration system library
 
3
 *
 
4
 * ccs_text_file.c
 
5
 *
 
6
 * Copyright (C) 2012 Canonical Ltd.
 
7
 *
 
8
 * This library is free software; you can redistribute it and/or
 
9
 * modify it under the terms of the GNU Lesser General Public
 
10
 * License as published by the Free Software Foundation; either
 
11
 * version 2.1 of the License, or (at your option) any later version.
 
12
 
 
13
 * This library 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 GNU
 
16
 * Lesser General Public License for more details.
 
17
 
 
18
 * You should have received a copy of the GNU Lesser General Public
 
19
 * License along with this library; if not, write to the Free Software
 
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
21
 *
 
22
 * Authored By:
 
23
 * Sam Spilsbury <sam.spilsbury@canonical.com>
 
24
 */
 
25
 
 
26
#include <stdio.h>
 
27
#include <stdlib.h>
 
28
#include <string.h>
 
29
 
 
30
#include <ccs-defs.h>
 
31
#include <ccs-object.h>
 
32
#include <ccs_text_file_interface.h>
 
33
#include <ccs_text_file.h>
 
34
 
 
35
typedef struct _CCSUnixTextFilePrivate CCSUnixTextFilePrivate;
 
36
 
 
37
struct _CCSUnixTextFilePrivate
 
38
{
 
39
    FILE *unixFile;
 
40
};
 
41
 
 
42
static void
 
43
freeAndFinalizeCCSTextFile (CCSTextFile                  *file,
 
44
                            CCSObjectAllocationInterface *ai)
 
45
{
 
46
    ccsObjectFinalize (file);
 
47
    (*ai->free_) (ai->allocator, file);
 
48
}
 
49
 
 
50
static char *
 
51
ccsUnixTextFileReadFromStart (CCSTextFile *textFile)
 
52
{
 
53
    CCSUnixTextFilePrivate *priv = GET_PRIVATE (CCSUnixTextFilePrivate, textFile);
 
54
    FILE                   *completedUpgrades = priv->unixFile;
 
55
 
 
56
    char                   *cuBuffer;
 
57
    unsigned int           cuSize;
 
58
    size_t                 cuReadSize;
 
59
 
 
60
    fseek (completedUpgrades, 0, SEEK_END);
 
61
    cuSize = ftell (completedUpgrades);
 
62
    rewind (completedUpgrades);
 
63
 
 
64
    cuBuffer = calloc (cuSize + 1, sizeof (char));
 
65
 
 
66
    if (!cuBuffer)
 
67
        return NULL;
 
68
 
 
69
    cuReadSize = fread (cuBuffer, 1, cuSize, completedUpgrades);
 
70
 
 
71
    /*
 
72
        ccsWarning ("Couldn't read completed upgrades file!");
 
73
        */
 
74
    if (cuReadSize != cuSize)
 
75
    {
 
76
        free (cuBuffer);
 
77
        return NULL;
 
78
    }
 
79
 
 
80
    cuBuffer[cuSize] = '\0';
 
81
 
 
82
    return cuBuffer;
 
83
}
 
84
 
 
85
static Bool
 
86
ccsUnixTextFileAppendString (CCSTextFile *textFile, const char *str)
 
87
{
 
88
    CCSUnixTextFilePrivate *priv = GET_PRIVATE (CCSUnixTextFilePrivate, textFile);
 
89
    FILE                   *completedUpgrades = priv->unixFile;
 
90
 
 
91
    fprintf (completedUpgrades, "%s\n", str);
 
92
    return TRUE;
 
93
}
 
94
 
 
95
static void
 
96
ccsUnixFreeTextFile (CCSTextFile *textFile)
 
97
{
 
98
    CCSUnixTextFilePrivate *priv = GET_PRIVATE (CCSUnixTextFilePrivate, textFile);
 
99
 
 
100
    fclose (priv->unixFile);
 
101
    priv->unixFile = NULL;
 
102
 
 
103
    freeAndFinalizeCCSTextFile (textFile,
 
104
                                textFile->object.object_allocation);
 
105
}
 
106
 
 
107
CCSTextFileInterface ccsUnixTextFileInterface =
 
108
{
 
109
    ccsUnixTextFileReadFromStart,
 
110
    ccsUnixTextFileAppendString,
 
111
    ccsUnixFreeTextFile
 
112
};
 
113
 
 
114
const char * CCS_UNIX_TEXT_FILE_OPEN_MODE_READONLY = "r";
 
115
const char * CCS_UNIX_TEXT_FILE_OPEN_MODE_READWRITE = "r+";
 
116
const char * CCS_UNIX_TEXT_FILE_OPEN_MODE_READWRITECREATE = "a+";
 
117
 
 
118
static FILE *
 
119
openUnixFile (CCSTextFile                  *textFile,
 
120
              CCSObjectAllocationInterface *ai,
 
121
              const char                   *path,
 
122
              const char                   *openMode)
 
123
{
 
124
    FILE *file = fopen (path, openMode);
 
125
 
 
126
    if (!file)
 
127
    {
 
128
        ccsObjectFinalize (textFile);
 
129
        (*ai->free_) (ai->allocator, textFile);
 
130
        return NULL;
 
131
    }
 
132
 
 
133
    return file;
 
134
}
 
135
 
 
136
 
 
137
static CCSUnixTextFilePrivate *
 
138
allocateCCSUnixTextFilePrivate (CCSTextFile                      *file,
 
139
                                CCSObjectAllocationInterface     *ai)
 
140
{
 
141
    CCSUnixTextFilePrivate *priv = (*ai->calloc_) (ai->allocator, 1, sizeof (CCSUnixTextFilePrivate));
 
142
 
 
143
    if (!priv)
 
144
    {
 
145
        freeAndFinalizeCCSTextFile (file, ai);
 
146
        return NULL;
 
147
    }
 
148
 
 
149
    return priv;
 
150
}
 
151
 
 
152
static CCSTextFile *
 
153
allocateCCSTextFile (CCSObjectAllocationInterface *ai)
 
154
{
 
155
    CCSTextFile *textFile = (*ai->calloc_) (ai->allocator, 1, sizeof (CCSTextFile));
 
156
 
 
157
    if (!textFile)
 
158
        return NULL;
 
159
 
 
160
    ccsObjectInit (textFile, ai);
 
161
 
 
162
    return textFile;
 
163
}
 
164
 
 
165
CCSTextFile *
 
166
ccsUnixTextFileNew (const char          *path,
 
167
                    CCSTextFileOpenMode openMode,
 
168
                    CCSObjectAllocationInterface *ai)
 
169
{
 
170
    const char *fopenMode = NULL;
 
171
 
 
172
    switch (openMode)
 
173
    {
 
174
        case ReadOnly:
 
175
            fopenMode = CCS_UNIX_TEXT_FILE_OPEN_MODE_READONLY;
 
176
            break;
 
177
        case ReadWrite:
 
178
            fopenMode = CCS_UNIX_TEXT_FILE_OPEN_MODE_READWRITE;
 
179
            break;
 
180
        case ReadWriteCreate:
 
181
            fopenMode = CCS_UNIX_TEXT_FILE_OPEN_MODE_READWRITECREATE;
 
182
            break;
 
183
    }
 
184
 
 
185
    CCSTextFile *textFile = allocateCCSTextFile (ai);
 
186
 
 
187
    if (!textFile)
 
188
        return NULL;
 
189
 
 
190
    CCSUnixTextFilePrivate *priv = allocateCCSUnixTextFilePrivate (textFile, ai);
 
191
 
 
192
    if (!priv)
 
193
        return NULL;
 
194
 
 
195
    ccsObjectSetPrivate (textFile, (CCSPrivate *) priv);
 
196
 
 
197
    FILE *unixFile = openUnixFile (textFile,
 
198
                                   ai,
 
199
                                   path,
 
200
                                   fopenMode);
 
201
 
 
202
    if (!unixFile)
 
203
        return NULL;
 
204
 
 
205
    priv->unixFile = unixFile;
 
206
 
 
207
    ccsObjectAddInterface (textFile, (const CCSInterface *) &ccsUnixTextFileInterface,
 
208
                           GET_INTERFACE_TYPE (CCSTextFileInterface));
 
209
    ccsObjectRef (textFile);
 
210
 
 
211
    return textFile;
 
212
}