Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "system.h"
31 : : #include "readwrite_helper.h"
32 : :
33 : : #include <osl/diagnose.h>
34 : : #include <osl/profile.h>
35 : : #include <osl/process.h>
36 : : #include <osl/thread.h>
37 : : #include <rtl/alloc.h>
38 : : #include <osl/util.h>
39 : :
40 : : #define LINES_INI 32
41 : : #define LINES_ADD 10
42 : : #define SECTIONS_INI 5
43 : : #define SECTIONS_ADD 3
44 : : #define ENTRIES_INI 5
45 : : #define ENTRIES_ADD 3
46 : :
47 : :
48 : : #define STR_INI_EXTENSION "rc"
49 : : #define STR_INI_METAHOME "?~"
50 : : #define STR_INI_METASYS "?$"
51 : : #define STR_INI_METACFG "?^"
52 : : #define STR_INI_METAINS "?#"
53 : :
54 : : #define STR_INI_BOOLYES "yes"
55 : : #define STR_INI_BOOLON "on"
56 : : #define STR_INI_BOOLONE "1"
57 : : #define STR_INI_BOOLNO "no"
58 : : #define STR_INI_BOOLOFF "off"
59 : : #define STR_INI_BOOLZERO "0"
60 : :
61 : : #define FLG_USER 0x00FF
62 : : #define FLG_AUTOOPEN 0x0100
63 : : #define FLG_MODIFIED 0x0200
64 : :
65 : : #define SVERSION_LOCATION STR_INI_METACFG
66 : : #define SVERSION_FALLBACK STR_INI_METASYS
67 : : #define SVERSION_NAME "sversion"
68 : : #define SVERSION_SECTION "Versions"
69 : : #define SVERSION_SOFFICE "StarOffice"
70 : : #define SVERSION_PROFILE "sofficerc"
71 : : #define SVERSION_OPTION "userid:"
72 : : #define SVERSION_DIRS { "bin", "program" }
73 : : #define SVERSION_USER "user"
74 : :
75 : : #define DEFAULT_PMODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)
76 : :
77 : : #define _BUILD_STR_(n) # n
78 : : #define BUILD_STR(n) _BUILD_STR_(n)
79 : :
80 : :
81 : : /*#define DEBUG_OSL_PROFILE*/
82 : : /*#define TRACE_OSL_PROFILE*/
83 : :
84 : : /*****************************************************************************/
85 : : /* Data Type Definition */
86 : : /*****************************************************************************/
87 : :
88 : : typedef time_t osl_TStamp;
89 : :
90 : : typedef enum _osl_TLockMode
91 : : {
92 : : un_lock, read_lock, write_lock
93 : : } osl_TLockMode;
94 : :
95 : : typedef struct _osl_TFile
96 : : {
97 : : int m_Handle;
98 : : sal_Char* m_pReadPtr;
99 : : sal_Char m_ReadBuf[512];
100 : : sal_Char* m_pWriteBuf;
101 : : sal_uInt32 m_nWriteBufLen;
102 : : sal_uInt32 m_nWriteBufFree;
103 : : } osl_TFile;
104 : :
105 : : typedef struct _osl_TProfileEntry
106 : : {
107 : : sal_uInt32 m_Line;
108 : : sal_uInt32 m_Offset;
109 : : sal_uInt32 m_Len;
110 : : } osl_TProfileEntry;
111 : :
112 : : typedef struct _osl_TProfileSection
113 : : {
114 : : sal_uInt32 m_Line;
115 : : sal_uInt32 m_Offset;
116 : : sal_uInt32 m_Len;
117 : : sal_uInt32 m_NoEntries;
118 : : sal_uInt32 m_MaxEntries;
119 : : osl_TProfileEntry* m_Entries;
120 : : } osl_TProfileSection;
121 : :
122 : :
123 : : /*
124 : : Profile-data structure hidden behind oslProfile:
125 : : */
126 : : typedef struct _osl_TProfileImpl
127 : : {
128 : : sal_uInt32 m_Flags;
129 : : osl_TFile* m_pFile;
130 : : osl_TStamp m_Stamp;
131 : : sal_Char m_FileName[PATH_MAX + 1];
132 : : sal_uInt32 m_NoLines;
133 : : sal_uInt32 m_MaxLines;
134 : : sal_uInt32 m_NoSections;
135 : : sal_uInt32 m_MaxSections;
136 : : sal_Char** m_Lines;
137 : : osl_TProfileSection* m_Sections;
138 : : pthread_mutex_t m_AccessLock;
139 : : sal_Bool m_bIsValid;
140 : : } osl_TProfileImpl;
141 : :
142 : :
143 : : /*****************************************************************************/
144 : : /* Static Module Function Declarations */
145 : : /*****************************************************************************/
146 : :
147 : : static osl_TFile* openFileImpl(const sal_Char* pszFilename, oslProfileOption ProfileFlags);
148 : : static osl_TStamp closeFileImpl(osl_TFile* pFile, oslProfileOption Flags);
149 : : static sal_Bool OslProfile_lockFile(const osl_TFile* pFile, osl_TLockMode eMode);
150 : : static sal_Bool OslProfile_rewindFile(osl_TFile* pFile, sal_Bool bTruncate);
151 : : static osl_TStamp OslProfile_getFileStamp(osl_TFile* pFile);
152 : :
153 : : static sal_Char* OslProfile_getLine(osl_TFile* pFile);
154 : : static sal_Bool OslProfile_putLine(osl_TFile* pFile, const sal_Char *pszLine);
155 : : static sal_Char* stripBlanks(sal_Char* String, sal_uInt32* pLen);
156 : : static sal_Char* addLine(osl_TProfileImpl* pProfile, const sal_Char* Line);
157 : : static sal_Char* insertLine(osl_TProfileImpl* pProfile, const sal_Char* Line, sal_uInt32 LineNo);
158 : : static void removeLine(osl_TProfileImpl* pProfile, sal_uInt32 LineNo);
159 : : static void setEntry(osl_TProfileImpl* pProfile, osl_TProfileSection* pSection,
160 : : sal_uInt32 NoEntry, sal_uInt32 Line,
161 : : sal_Char* Entry, sal_uInt32 Len);
162 : : static sal_Bool addEntry(osl_TProfileImpl* pProfile, osl_TProfileSection *pSection,
163 : : int Line, sal_Char* Entry, sal_uInt32 Len);
164 : : static void removeEntry(osl_TProfileSection *pSection, sal_uInt32 NoEntry);
165 : : static sal_Bool addSection(osl_TProfileImpl* pProfile, int Line, const sal_Char* Section, sal_uInt32 Len);
166 : : static void removeSection(osl_TProfileImpl* pProfile, osl_TProfileSection *pSection);
167 : : static osl_TProfileSection* findEntry(osl_TProfileImpl* pProfile, const sal_Char* Section,
168 : : const sal_Char* Entry, sal_uInt32 *pNoEntry);
169 : : static sal_Bool loadProfile(osl_TFile* pFile, osl_TProfileImpl* pProfile);
170 : : static sal_Bool storeProfile(osl_TProfileImpl* pProfile, sal_Bool bCleanup);
171 : : static osl_TProfileImpl* acquireProfile(oslProfile Profile, sal_Bool bWriteable);
172 : : static sal_Bool releaseProfile(osl_TProfileImpl* pProfile);
173 : :
174 : : static sal_Bool writeProfileImpl (osl_TFile* pFile);
175 : : static osl_TFile* osl_openTmpProfileImpl(osl_TProfileImpl*);
176 : : static sal_Bool osl_ProfileSwapProfileNames(osl_TProfileImpl*);
177 : : static void osl_ProfileGenerateExtension(sal_Char* pszFileName, sal_Char* pszExtension, sal_Char* pszTmpName);
178 : : static oslProfile SAL_CALL osl_psz_openProfile(const sal_Char *pszProfileName, oslProfileOption Flags);
179 : :
180 : : /* implemented in file.c */
181 : : extern oslFileError FileURLToPath( char *, size_t, rtl_uString* );
182 : :
183 : : /*****************************************************************************/
184 : : /* Exported Module Functions */
185 : : /*****************************************************************************/
186 : 506 : oslProfile SAL_CALL osl_openProfile(rtl_uString *ustrProfileName, oslProfileOption Options)
187 : : {
188 : 506 : char profilePath[PATH_MAX] = "";
189 : :
190 [ + - ][ + - ]: 506 : if ( ustrProfileName != 0 && ustrProfileName->buffer[0] != 0 )
191 : 506 : FileURLToPath( profilePath, PATH_MAX, ustrProfileName );
192 : :
193 : 506 : return osl_psz_openProfile( profilePath,Options );
194 : : }
195 : :
196 : :
197 : 506 : static oslProfile SAL_CALL osl_psz_openProfile(const sal_Char *pszProfileName, oslProfileOption Flags)
198 : : {
199 : : osl_TFile* pFile;
200 : : osl_TProfileImpl* pProfile;
201 : 506 : sal_Bool bRet = sal_False;
202 : :
203 : : #ifdef TRACE_OSL_PROFILE
204 : : OSL_TRACE("In osl_openProfile");
205 : : #endif
206 : :
207 : : #ifdef DEBUG_OSL_PROFILE
208 : : Flags=osl_Profile_FLUSHWRITE;
209 : :
210 : : OSL_TRACE("opening '%s'",pszProfileName);
211 : : if ( Flags == osl_Profile_DEFAULT )
212 : : {
213 : : OSL_TRACE("with osl_Profile_DEFAULT");
214 : : }
215 : : if ( Flags & osl_Profile_SYSTEM )
216 : : {
217 : : OSL_TRACE("with osl_Profile_SYSTEM");
218 : : }
219 : : if ( Flags & osl_Profile_READLOCK )
220 : : {
221 : : OSL_TRACE("with osl_Profile_READLOCK");
222 : : }
223 : : if ( Flags & osl_Profile_WRITELOCK )
224 : : {
225 : : OSL_TRACE("with osl_Profile_WRITELOCK");
226 : : }
227 : : if ( Flags & osl_Profile_FLUSHWRITE )
228 : : {
229 : : OSL_TRACE("with osl_Profile_FLUSHWRITE");
230 : : }
231 : : #endif
232 : :
233 : :
234 [ - + ]: 506 : if ( ( pFile = openFileImpl(pszProfileName, Flags ) ) == NULL )
235 : : {
236 : : #ifdef TRACE_OSL_PROFILE
237 : : OSL_TRACE("Out osl_openProfile [not opened]");
238 : : #endif
239 : 0 : return (NULL);
240 : : }
241 : :
242 : :
243 : 506 : pProfile = (osl_TProfileImpl*)calloc(1, sizeof(osl_TProfileImpl));
244 : :
245 [ - + ]: 506 : if ( pProfile == 0 )
246 : : {
247 : 0 : closeFileImpl(pFile, Flags);
248 : 0 : return 0;
249 : : }
250 : :
251 : 506 : pProfile->m_Flags = Flags & FLG_USER;
252 : :
253 [ - + ]: 506 : if ( Flags & ( osl_Profile_READLOCK | osl_Profile_WRITELOCK | osl_Profile_FLUSHWRITE ) )
254 : : {
255 : 0 : pProfile->m_pFile = pFile;
256 : : }
257 : :
258 : 506 : pthread_mutex_init(&(pProfile->m_AccessLock),PTHREAD_MUTEXATTR_DEFAULT);
259 : 506 : pProfile->m_bIsValid=sal_True;
260 : :
261 : 506 : pProfile->m_Stamp = OslProfile_getFileStamp(pFile);
262 : 506 : bRet=loadProfile(pFile, pProfile);
263 : 506 : bRet &= realpath(pszProfileName, pProfile->m_FileName) != NULL;
264 : : OSL_ASSERT(bRet);
265 : :
266 [ + - ]: 506 : if (pProfile->m_pFile == NULL)
267 : 506 : closeFileImpl(pFile,pProfile->m_Flags);
268 : :
269 : : #ifdef TRACE_OSL_PROFILE
270 : : OSL_TRACE("Out osl_openProfile [ok]");
271 : : #endif
272 : 506 : return (pProfile);
273 : : }
274 : :
275 : 506 : sal_Bool SAL_CALL osl_closeProfile(oslProfile Profile)
276 : : {
277 : 506 : osl_TProfileImpl* pProfile = (osl_TProfileImpl*)Profile;
278 : : osl_TProfileImpl* pTmpProfile;
279 : :
280 : : #ifdef TRACE_OSL_PROFILE
281 : : OSL_TRACE("In osl_closeProfile");
282 : : #endif
283 : :
284 [ - + ]: 506 : if ( Profile == 0 )
285 : : {
286 : : #ifdef TRACE_OSL_PROFILE
287 : : OSL_TRACE("Out osl_closeProfile [profile==0]");
288 : : #endif
289 : 0 : return sal_False;
290 : : }
291 : :
292 : 506 : pthread_mutex_lock(&(pProfile->m_AccessLock));
293 : :
294 [ - + ]: 506 : if ( pProfile->m_bIsValid == sal_False )
295 : : {
296 : : OSL_ASSERT(pProfile->m_bIsValid);
297 : 0 : pthread_mutex_unlock(&(pProfile->m_AccessLock));
298 : : #ifdef TRACE_OSL_PROFILE
299 : : OSL_TRACE("Out osl_closeProfile [not valid]");
300 : : #endif
301 : 0 : return sal_False;
302 : : }
303 : :
304 : 506 : pProfile->m_bIsValid=sal_False;
305 : :
306 [ + - ][ - + ]: 506 : if ( ! ( pProfile->m_Flags & osl_Profile_READLOCK ) && ( pProfile->m_Flags & FLG_MODIFIED ) )
307 : : {
308 : 0 : pTmpProfile = acquireProfile(Profile,sal_True);
309 : :
310 [ # # ]: 0 : if ( pTmpProfile != 0 )
311 : : {
312 : 0 : sal_Bool bRet = storeProfile(pTmpProfile, sal_True);
313 : : OSL_ASSERT(bRet);
314 : : (void)bRet;
315 : : }
316 : : }
317 : : else
318 : : {
319 : 506 : pTmpProfile = acquireProfile(Profile,sal_False);
320 : : }
321 : :
322 : :
323 [ - + ]: 506 : if ( pTmpProfile == 0 )
324 : : {
325 : 0 : pthread_mutex_unlock(&(pProfile->m_AccessLock));
326 : : #ifdef TRACE_OSL_PROFILE
327 : : OSL_TRACE("Out osl_closeProfile [pProfile==0]");
328 : : #endif
329 : 0 : return sal_False;
330 : : }
331 : :
332 : 506 : pProfile = pTmpProfile;
333 : :
334 [ + - ]: 506 : if (pProfile->m_pFile != NULL)
335 : 506 : closeFileImpl(pProfile->m_pFile,pProfile->m_Flags);
336 : :
337 : 506 : pProfile->m_pFile = NULL;
338 : 506 : pProfile->m_FileName[0] = '\0';
339 : :
340 : : /* release whole profile data types memory */
341 [ + + ]: 506 : if ( pProfile->m_NoLines > 0)
342 : : {
343 : 496 : unsigned int idx=0;
344 [ + - ]: 496 : if ( pProfile->m_Lines != 0 )
345 : : {
346 [ + + ]: 7440 : for ( idx = 0 ; idx < pProfile->m_NoLines ; ++idx)
347 : : {
348 [ + - ]: 6944 : if ( pProfile->m_Lines[idx] != 0 )
349 : : {
350 : 6944 : free(pProfile->m_Lines[idx]);
351 : 6944 : pProfile->m_Lines[idx]=0;
352 : : }
353 : : }
354 : 496 : free(pProfile->m_Lines);
355 : 496 : pProfile->m_Lines=0;
356 : : }
357 [ + - ]: 496 : if ( pProfile->m_Sections != 0 )
358 : : {
359 : : /*osl_TProfileSection* pSections=pProfile->m_Sections;*/
360 [ + + ]: 992 : for ( idx = 0 ; idx < pProfile->m_NoSections ; ++idx )
361 : : {
362 [ + - ]: 496 : if ( pProfile->m_Sections[idx].m_Entries != 0 )
363 : : {
364 : 496 : free(pProfile->m_Sections[idx].m_Entries);
365 : 496 : pProfile->m_Sections[idx].m_Entries=0;
366 : : }
367 : : }
368 : 496 : free(pProfile->m_Sections);
369 : 496 : pProfile->m_Sections=0;
370 : : }
371 : : }
372 : :
373 : 506 : pthread_mutex_unlock(&(pProfile->m_AccessLock));
374 : :
375 : 506 : pthread_mutex_destroy(&(pProfile->m_AccessLock));
376 : :
377 : 506 : free(pProfile);
378 : :
379 : : #ifdef TRACE_OSL_PROFILE
380 : : OSL_TRACE("Out osl_closeProfile [ok]");
381 : : #endif
382 : 506 : return (sal_True);
383 : : }
384 : :
385 : :
386 : 0 : sal_Bool SAL_CALL osl_flushProfile(oslProfile Profile)
387 : : {
388 : 0 : osl_TProfileImpl* pProfile = (osl_TProfileImpl*) Profile;
389 : : osl_TFile* pFile;
390 : 0 : sal_Bool bRet = sal_False;
391 : :
392 : : #ifdef TRACE_OSL_PROFILE
393 : : OSL_TRACE("In osl_flushProfile()");
394 : : #endif
395 : :
396 [ # # ]: 0 : if ( pProfile == 0 )
397 : : {
398 : : #ifdef TRACE_OSL_PROFILE
399 : : OSL_TRACE("Out osl_flushProfile() [pProfile == 0]");
400 : : #endif
401 : 0 : return sal_False;
402 : : }
403 : :
404 : 0 : pthread_mutex_lock(&(pProfile->m_AccessLock));
405 : :
406 [ # # ]: 0 : if ( pProfile->m_bIsValid == sal_False )
407 : : {
408 : : OSL_ASSERT(pProfile->m_bIsValid);
409 : 0 : pthread_mutex_unlock(&(pProfile->m_AccessLock));
410 : : #ifdef TRACE_OSL_PROFILE
411 : : OSL_TRACE("Out osl_flushProfile [not valid]");
412 : : #endif
413 : 0 : return sal_False;
414 : : }
415 : :
416 : 0 : pFile = pProfile->m_pFile;
417 [ # # ][ # # ]: 0 : if ( !( pFile != 0 && pFile->m_Handle >= 0 ) )
418 : : {
419 : 0 : pthread_mutex_unlock(&(pProfile->m_AccessLock));
420 : : #ifdef TRACE_OSL_PROFILE
421 : : OSL_TRACE("Out osl_flushProfile() [invalid file]");
422 : : #endif
423 : 0 : return sal_False;
424 : : }
425 : :
426 [ # # ]: 0 : if ( pProfile->m_Flags & FLG_MODIFIED )
427 : : {
428 : : #ifdef DEBUG_OSL_PROFILE
429 : : OSL_TRACE("swapping to storeprofile");
430 : : #endif
431 : 0 : bRet = storeProfile(pProfile,sal_False);
432 : : OSL_ASSERT(bRet);
433 : : }
434 : :
435 : : #ifdef TRACE_OSL_PROFILE
436 : : OSL_TRACE("Out osl_flushProfile() [ok]");
437 : : #endif
438 : 0 : pthread_mutex_unlock(&(pProfile->m_AccessLock));
439 : 0 : return bRet;
440 : : }
441 : :
442 : 0 : static sal_Bool writeProfileImpl(osl_TFile* pFile)
443 : : {
444 : : #if OSL_DEBUG_LEVEL > 1
445 : : unsigned int nLen=0;
446 : : #endif
447 : :
448 : : #ifdef TRACE_OSL_PROFILE
449 : : OSL_TRACE("In osl_writeProfileImpl()");
450 : : #endif
451 : :
452 [ # # ][ # # ]: 0 : if ( !( pFile != 0 && pFile->m_Handle >= 0 ) || ( pFile->m_pWriteBuf == 0 ) )
[ # # ]
453 : : {
454 : : #ifdef TRACE_OSL_PROFILE
455 : : OSL_TRACE("Out osl_writeProfileImpl() [invalid args]");
456 : : #endif
457 : 0 : return sal_False;
458 : : }
459 : :
460 : : #if OSL_DEBUG_LEVEL > 1
461 : : nLen=strlen(pFile->m_pWriteBuf);
462 : : OSL_ASSERT(nLen == (pFile->m_nWriteBufLen - pFile->m_nWriteBufFree));
463 : : #endif
464 : :
465 [ # # ]: 0 : if ( !safeWrite(pFile->m_Handle, pFile->m_pWriteBuf, pFile->m_nWriteBufLen - pFile->m_nWriteBufFree) )
466 : : {
467 : : OSL_TRACE("write failed '%s'",strerror(errno));
468 : 0 : return (sal_False);
469 : : }
470 : :
471 : 0 : free(pFile->m_pWriteBuf);
472 : 0 : pFile->m_pWriteBuf=0;
473 : 0 : pFile->m_nWriteBufLen=0;
474 : 0 : pFile->m_nWriteBufFree=0;
475 : : #ifdef TRACE_OSL_PROFILE
476 : : OSL_TRACE("Out osl_writeProfileImpl() [ok]");
477 : : #endif
478 : 0 : return sal_True;
479 : : }
480 : :
481 : :
482 : 496 : sal_Bool SAL_CALL osl_readProfileString(oslProfile Profile,
483 : : const sal_Char* pszSection, const sal_Char* pszEntry,
484 : : sal_Char* pszString, sal_uInt32 MaxLen,
485 : : const sal_Char* pszDefault)
486 : : {
487 : : sal_uInt32 NoEntry;
488 : 496 : sal_Char* pStr=0;
489 : : osl_TProfileSection* pSec;
490 : 496 : osl_TProfileImpl* pProfile=0;
491 : 496 : osl_TProfileImpl* pTmpProfile=0;
492 : 496 : sal_Bool bRet = sal_False;
493 : :
494 : : #ifdef TRACE_OSL_PROFILE
495 : : OSL_TRACE("In osl_readProfileString");
496 : : #endif
497 : :
498 : 496 : pTmpProfile = (osl_TProfileImpl*) Profile;
499 : :
500 [ - + ]: 496 : if ( pTmpProfile == 0 )
501 : : {
502 : : #ifdef TRACE_OSL_PROFILE
503 : : OSL_TRACE("Out osl_readProfileString [pTmpProfile==0]");
504 : : #endif
505 : 0 : return sal_False;
506 : : }
507 : :
508 : 496 : pthread_mutex_lock(&(pTmpProfile->m_AccessLock));
509 : :
510 [ - + ]: 496 : if ( pTmpProfile->m_bIsValid == sal_False )
511 : : {
512 : 0 : pthread_mutex_unlock(&(pTmpProfile->m_AccessLock));
513 : : #ifdef TRACE_OSL_PROFILE
514 : : OSL_TRACE("Out osl_readProfileString [not valid]");
515 : : #endif
516 : 0 : return sal_False;
517 : : }
518 : :
519 : 496 : pProfile = acquireProfile(Profile, sal_False);
520 : :
521 [ - + ]: 496 : if ( pProfile == NULL )
522 : : {
523 : : #ifdef TRACE_OSL_PROFILE
524 : : OSL_TRACE("Out osl_readProfileString [pProfile==0]");
525 : : #endif
526 : 0 : return (sal_False);
527 : : }
528 : :
529 [ + - ]: 496 : if (! (pProfile->m_Flags & osl_Profile_SYSTEM))
530 : : {
531 [ + - ][ + - ]: 496 : if (((pSec = findEntry(pProfile, pszSection, pszEntry, &NoEntry)) != NULL) &&
532 [ + - ]: 496 : (NoEntry < pSec->m_NoEntries) &&
533 : 496 : ((pStr = strchr(pProfile->m_Lines[pSec->m_Entries[NoEntry].m_Line],
534 : : '=')) != NULL))
535 : : {
536 : 496 : pStr++;
537 : : }
538 : : else
539 : : {
540 : 0 : pStr=(sal_Char*)pszDefault;
541 : : }
542 : :
543 [ + - ]: 496 : if ( pStr != 0 )
544 : : {
545 : 496 : pStr = stripBlanks(pStr, NULL);
546 [ - + ]: 496 : MaxLen = (MaxLen - 1 < strlen(pStr)) ? (MaxLen - 1) : strlen(pStr);
547 : 496 : pStr = stripBlanks(pStr, &MaxLen);
548 : 496 : strncpy(pszString, pStr, MaxLen);
549 : 496 : pszString[MaxLen] = '\0';
550 : : }
551 : : }
552 : : else
553 : : { /* not implemented */ }
554 : :
555 : :
556 : 496 : bRet=releaseProfile(pProfile);
557 : : OSL_ASSERT(bRet);
558 : : (void)bRet;
559 : :
560 [ - + ]: 496 : if ( pStr == 0 )
561 : : {
562 : 0 : pthread_mutex_unlock(&(pTmpProfile->m_AccessLock));
563 : : #ifdef TRACE_OSL_PROFILE
564 : : OSL_TRACE("Out osl_readProfileString [pStr==0]");
565 : : #endif
566 : 0 : return sal_False;
567 : : }
568 : :
569 : 496 : pthread_mutex_unlock(&(pTmpProfile->m_AccessLock));
570 : :
571 : : #ifdef TRACE_OSL_PROFILE
572 : : OSL_TRACE("Out osl_readProfileString [ok]");
573 : : #endif
574 : :
575 : 496 : return (sal_True);
576 : : }
577 : :
578 : :
579 : 0 : sal_Bool SAL_CALL osl_readProfileBool(oslProfile Profile,
580 : : const sal_Char* pszSection, const sal_Char* pszEntry,
581 : : sal_Bool Default)
582 : : {
583 : : sal_Char Line[32];
584 : 0 : Line[0] = '\0';
585 : :
586 : : #ifdef TRACE_OSL_PROFILE
587 : : OSL_TRACE("In osl_readProfileBool");
588 : : #endif
589 : :
590 [ # # ]: 0 : if (osl_readProfileString(Profile, pszSection, pszEntry, Line, sizeof(Line), ""))
591 : : {
592 [ # # ][ # # ]: 0 : if ((strcasecmp(Line, STR_INI_BOOLYES) == 0) ||
593 [ # # ]: 0 : (strcasecmp(Line, STR_INI_BOOLON) == 0) ||
594 : 0 : (strcasecmp(Line, STR_INI_BOOLONE) == 0))
595 : 0 : Default = sal_True;
596 : : else
597 [ # # ][ # # ]: 0 : if ((strcasecmp(Line, STR_INI_BOOLNO) == 0) ||
598 [ # # ]: 0 : (strcasecmp(Line, STR_INI_BOOLOFF) == 0) ||
599 : 0 : (strcasecmp(Line, STR_INI_BOOLZERO) == 0))
600 : 0 : Default = sal_False;
601 : : }
602 : :
603 : : #ifdef TRACE_OSL_PROFILE
604 : : OSL_TRACE("Out osl_readProfileBool [ok]");
605 : : #endif
606 : :
607 : 0 : return (Default);
608 : : }
609 : :
610 : :
611 : 0 : sal_uInt32 SAL_CALL osl_readProfileIdent(oslProfile Profile,
612 : : const sal_Char* pszSection, const sal_Char* pszEntry,
613 : : sal_uInt32 FirstId, const sal_Char* Strings[],
614 : : sal_uInt32 Default)
615 : : {
616 : : sal_uInt32 i;
617 : : sal_Char Line[256];
618 : 0 : Line[0] = '\0';
619 : :
620 : : #ifdef TRACE_OSL_PROFILE
621 : : OSL_TRACE("In osl_readProfileIdent");
622 : : #endif
623 : :
624 [ # # ]: 0 : if (osl_readProfileString(Profile, pszSection, pszEntry, Line, sizeof(Line), ""))
625 : : {
626 : 0 : i = 0;
627 [ # # ]: 0 : while (Strings[i] != NULL)
628 : : {
629 [ # # ]: 0 : if (strcasecmp(Line, Strings[i]) == 0)
630 : : {
631 : 0 : Default = i + FirstId;
632 : 0 : break;
633 : : }
634 : 0 : i++;
635 : : }
636 : : }
637 : :
638 : : #ifdef TRACE_OSL_PROFILE
639 : : OSL_TRACE("Out osl_readProfileIdent [ok]");
640 : : #endif
641 : 0 : return (Default);
642 : : }
643 : :
644 : 10 : sal_Bool SAL_CALL osl_writeProfileString(oslProfile Profile,
645 : : const sal_Char* pszSection, const sal_Char* pszEntry,
646 : : const sal_Char* pszString)
647 : : {
648 : : sal_uInt32 i;
649 : 10 : sal_Bool bRet = sal_False;
650 : : sal_uInt32 NoEntry;
651 : : sal_Char* pStr;
652 : 10 : sal_Char* Line = 0;
653 : : osl_TProfileSection* pSec;
654 : 10 : osl_TProfileImpl* pProfile = 0;
655 : 10 : osl_TProfileImpl* pTmpProfile = 0;
656 : :
657 : : #ifdef TRACE_OSL_PROFILE
658 : : OSL_TRACE("In osl_writeProfileString");
659 : : #endif
660 : :
661 : 10 : pTmpProfile = (osl_TProfileImpl*) Profile;
662 : :
663 [ - + ]: 10 : if ( pTmpProfile == 0 )
664 : : {
665 : : #ifdef TRACE_OSL_PROFILE
666 : : OSL_TRACE("Out osl_writeProfileString [pTmpProfile==0]");
667 : : #endif
668 : 0 : return sal_False;
669 : : }
670 : :
671 : 10 : pthread_mutex_lock(&(pTmpProfile->m_AccessLock));
672 : :
673 [ - + ]: 10 : if ( pTmpProfile->m_bIsValid == sal_False )
674 : : {
675 : : OSL_ASSERT(pTmpProfile->m_bIsValid);
676 : 0 : pthread_mutex_unlock(&(pTmpProfile->m_AccessLock));
677 : : #ifdef TRACE_OSL_PROFILE
678 : : OSL_TRACE("Out osl_writeProfileString [not valid]");
679 : : #endif
680 : 0 : return sal_False;
681 : : }
682 : :
683 : 10 : pProfile=acquireProfile(Profile, sal_True);
684 : :
685 [ + - ]: 10 : if (pProfile == NULL)
686 : : {
687 : 10 : pthread_mutex_unlock(&(pTmpProfile->m_AccessLock));
688 : : #ifdef TRACE_OSL_PROFILE
689 : : OSL_TRACE("Out osl_writeProfileString [pProfile==0]");
690 : : #endif
691 : 10 : return (sal_False);
692 : : }
693 : :
694 : 0 : Line = (sal_Char*) malloc(strlen(pszEntry)+strlen(pszString)+48);
695 : :
696 [ # # ]: 0 : if (! (pProfile->m_Flags & osl_Profile_SYSTEM))
697 : : {
698 [ # # ]: 0 : if ((pSec = findEntry(pProfile, pszSection, pszEntry, &NoEntry)) == NULL)
699 : : {
700 : 0 : Line[0] = '\0';
701 : 0 : addLine(pProfile, Line);
702 : :
703 : 0 : Line[0] = '[';
704 : 0 : strcpy(&Line[1], pszSection);
705 : 0 : Line[1 + strlen(pszSection)] = ']';
706 : 0 : Line[2 + strlen(pszSection)] = '\0';
707 : :
708 [ # # # # ]: 0 : if (((pStr = addLine(pProfile, Line)) == NULL) ||
709 : 0 : (! addSection(pProfile, pProfile->m_NoLines - 1, &pStr[1], strlen(pszSection))))
710 : : {
711 : 0 : bRet=releaseProfile(pProfile);
712 : : OSL_ASSERT(bRet);
713 : :
714 : 0 : pthread_mutex_unlock(&(pTmpProfile->m_AccessLock));
715 : :
716 : 0 : free(Line);
717 : :
718 : : #ifdef TRACE_OSL_PROFILE
719 : : OSL_TRACE("Out osl_writeProfileString [not added]");
720 : : #endif
721 : 0 : return (sal_False);
722 : : }
723 : :
724 : 0 : pSec = &pProfile->m_Sections[pProfile->m_NoSections - 1];
725 : 0 : NoEntry = pSec->m_NoEntries;
726 : : }
727 : :
728 : 0 : Line[0] = '\0';
729 : 0 : strcpy(&Line[0], pszEntry);
730 : 0 : Line[0 + strlen(pszEntry)] = '=';
731 : 0 : strcpy(&Line[1 + strlen(pszEntry)], pszString);
732 : :
733 [ # # ]: 0 : if (NoEntry >= pSec->m_NoEntries)
734 : : {
735 [ # # ]: 0 : if (pSec->m_NoEntries > 0)
736 : 0 : i = pSec->m_Entries[pSec->m_NoEntries - 1].m_Line + 1;
737 : : else
738 : 0 : i = pSec->m_Line + 1;
739 : :
740 [ # # # # ]: 0 : if (((pStr = insertLine(pProfile, Line, i)) == NULL) ||
741 : 0 : (! addEntry(pProfile, pSec, i, pStr, strlen(pszEntry))))
742 : : {
743 : 0 : bRet=releaseProfile(pProfile);
744 : : OSL_ASSERT(bRet);
745 : :
746 : 0 : pthread_mutex_unlock(&(pTmpProfile->m_AccessLock));
747 : 0 : free(Line);
748 : :
749 : : #ifdef TRACE_OSL_PROFILE
750 : : OSL_TRACE("Out osl_writeProfileString [not inserted]");
751 : : #endif
752 : 0 : return (sal_False);
753 : : }
754 : :
755 : 0 : pProfile->m_Flags |= FLG_MODIFIED;
756 : : }
757 : : else
758 : : {
759 : 0 : i = pSec->m_Entries[NoEntry].m_Line;
760 : 0 : free(pProfile->m_Lines[i]);
761 : 0 : pProfile->m_Lines[i] = strdup(Line);
762 : 0 : setEntry(pProfile, pSec, NoEntry, i, pProfile->m_Lines[i], strlen(pszEntry));
763 : :
764 : 0 : pProfile->m_Flags |= FLG_MODIFIED;
765 : : }
766 : : }
767 : : else {
768 : : /* not implemented */
769 : : }
770 : :
771 : 0 : bRet = releaseProfile(pProfile);
772 : : OSL_ASSERT(bRet);
773 : :
774 : 0 : pthread_mutex_unlock(&(pTmpProfile->m_AccessLock));
775 [ # # ]: 0 : if ( Line!= 0 )
776 : : {
777 : 0 : free(Line);
778 : : }
779 : :
780 : : #ifdef TRACE_OSL_PROFILE
781 : : OSL_TRACE("Out osl_writeProfileString [ok]");
782 : : #endif
783 : :
784 : 10 : return bRet;
785 : : }
786 : :
787 : :
788 : 10 : sal_Bool SAL_CALL osl_writeProfileBool(oslProfile Profile,
789 : : const sal_Char* pszSection, const sal_Char* pszEntry,
790 : : sal_Bool Value)
791 : : {
792 : 10 : sal_Bool bRet=sal_False;
793 : :
794 : : #ifdef TRACE_OSL_PROFILE
795 : : OSL_TRACE("In osl_writeProfileBool");
796 : : #endif
797 : :
798 [ + - ]: 10 : if (Value)
799 : 10 : bRet=osl_writeProfileString(Profile, pszSection, pszEntry, STR_INI_BOOLONE);
800 : : else
801 : 0 : bRet=osl_writeProfileString(Profile, pszSection, pszEntry, STR_INI_BOOLZERO);
802 : :
803 : : #ifdef TRACE_OSL_PROFILE
804 : : OSL_TRACE("Out osl_writeProfileBool [ok]");
805 : : #endif
806 : :
807 : 10 : return bRet;
808 : : }
809 : :
810 : :
811 : 0 : sal_Bool SAL_CALL osl_writeProfileIdent(oslProfile Profile,
812 : : const sal_Char* pszSection, const sal_Char* pszEntry,
813 : : sal_uInt32 FirstId, const sal_Char* Strings[],
814 : : sal_uInt32 Value)
815 : : {
816 : : int i, n;
817 : 0 : sal_Bool bRet=sal_False;
818 : :
819 : : #ifdef TRACE_OSL_PROFILE
820 : : OSL_TRACE("In osl_writeProfileIdent");
821 : : #endif
822 : :
823 [ # # ]: 0 : for (n = 0; Strings[n] != NULL; n++);
824 : :
825 [ # # ]: 0 : if ((i = Value - FirstId) >= n)
826 : 0 : bRet=sal_False;
827 : : else
828 : 0 : bRet = osl_writeProfileString(Profile, pszSection, pszEntry, Strings[i]);
829 : :
830 : : #ifdef TRACE_OSL_PROFILE
831 : : OSL_TRACE("Out osl_writeProfileIdent");
832 : : #endif
833 : 0 : return bRet;
834 : : }
835 : :
836 : :
837 : 0 : sal_Bool SAL_CALL osl_removeProfileEntry(oslProfile Profile,
838 : : const sal_Char *pszSection, const sal_Char *pszEntry)
839 : : {
840 : : sal_uInt32 NoEntry;
841 : : osl_TProfileSection* pSec;
842 : 0 : osl_TProfileImpl* pProfile = 0;
843 : 0 : osl_TProfileImpl* pTmpProfile = 0;
844 : 0 : sal_Bool bRet = sal_False;
845 : :
846 : : #ifdef TRACE_OSL_PROFILE
847 : : OSL_TRACE("In osl_removeProfileEntry");
848 : : #endif
849 : :
850 : 0 : pTmpProfile = (osl_TProfileImpl*) Profile;
851 : :
852 [ # # ]: 0 : if ( pTmpProfile == 0 )
853 : : {
854 : : #ifdef TRACE_OSL_PROFILE
855 : : OSL_TRACE("Out osl_removeProfileEntry [pProfile==0]");
856 : : #endif
857 : 0 : return sal_False;
858 : : }
859 : :
860 : 0 : pthread_mutex_lock(&(pTmpProfile->m_AccessLock));
861 : :
862 [ # # ]: 0 : if ( pTmpProfile->m_bIsValid == sal_False )
863 : : {
864 : : OSL_ASSERT(pTmpProfile->m_bIsValid);
865 : 0 : pthread_mutex_unlock(&(pTmpProfile->m_AccessLock));
866 : : #ifdef TRACE_OSL_PROFILE
867 : : OSL_TRACE("Out osl_removeProfileEntry [not valid]");
868 : : #endif
869 : 0 : return sal_False;
870 : : }
871 : :
872 : :
873 : 0 : pProfile = acquireProfile(Profile, sal_True);
874 : :
875 [ # # ]: 0 : if (pProfile == NULL)
876 : : {
877 : 0 : pthread_mutex_unlock(&(pTmpProfile->m_AccessLock));
878 : : #ifdef TRACE_OSL_PROFILE
879 : : OSL_TRACE("Out osl_removeProfileEntry [pProfile==0]");
880 : : #endif
881 : 0 : return (sal_False);
882 : : }
883 : :
884 : :
885 [ # # ]: 0 : if (! (pProfile->m_Flags & osl_Profile_SYSTEM))
886 : : {
887 [ # # ][ # # ]: 0 : if (((pSec = findEntry(pProfile, pszSection, pszEntry, &NoEntry)) != NULL) &&
888 : 0 : (NoEntry < pSec->m_NoEntries))
889 : : {
890 : 0 : removeLine(pProfile, pSec->m_Entries[NoEntry].m_Line);
891 : 0 : removeEntry(pSec, NoEntry);
892 [ # # ]: 0 : if (pSec->m_NoEntries == 0)
893 : : {
894 : 0 : removeLine(pProfile, pSec->m_Line);
895 : :
896 : : /* remove any empty separation line */
897 [ # # ][ # # ]: 0 : if ((pSec->m_Line > 0) && (pProfile->m_Lines[pSec->m_Line - 1][0] == '\0'))
898 : 0 : removeLine(pProfile, pSec->m_Line - 1);
899 : :
900 : 0 : removeSection(pProfile, pSec);
901 : : }
902 : :
903 : 0 : pProfile->m_Flags |= FLG_MODIFIED;
904 : : }
905 : : }
906 : : else
907 : : { /* not implemented */ }
908 : :
909 : :
910 : 0 : bRet = releaseProfile(pProfile);
911 : : OSL_ASSERT(bRet);
912 : :
913 : 0 : pthread_mutex_unlock(&(pTmpProfile->m_AccessLock));
914 : :
915 : : #ifdef TRACE_OSL_PROFILE
916 : : OSL_TRACE("Out osl_removeProfileEntry [ok]");
917 : : #endif
918 : 0 : return bRet;
919 : : }
920 : :
921 : :
922 : 0 : sal_uInt32 SAL_CALL osl_getProfileSectionEntries(oslProfile Profile, const sal_Char *pszSection,
923 : : sal_Char* pszBuffer, sal_uInt32 MaxLen)
924 : : {
925 : 0 : sal_uInt32 i, n = 0;
926 : : sal_uInt32 NoEntry;
927 : : osl_TProfileSection* pSec;
928 : 0 : osl_TProfileImpl* pProfile = 0;
929 : 0 : osl_TProfileImpl* pTmpProfile = 0;
930 : 0 : sal_Bool bRet = sal_False;
931 : :
932 : : #ifdef TRACE_OSL_PROFILE
933 : : OSL_TRACE("In osl_getProfileSectionEntries");
934 : : #endif
935 : :
936 : 0 : pTmpProfile = (osl_TProfileImpl*) Profile;
937 : :
938 [ # # ]: 0 : if ( pTmpProfile == 0 )
939 : : {
940 : : #ifdef TRACE_OSL_PROFILE
941 : : OSL_TRACE("Out osl_getProfileSectionEntries [pTmpProfile==0]");
942 : : #endif
943 : 0 : return sal_False;
944 : :
945 : : }
946 : :
947 : 0 : pthread_mutex_lock(&(pTmpProfile->m_AccessLock));
948 : :
949 [ # # ]: 0 : if ( pTmpProfile->m_bIsValid == sal_False )
950 : : {
951 : : OSL_ASSERT(pTmpProfile->m_bIsValid);
952 : :
953 : 0 : pthread_mutex_unlock(&(pTmpProfile->m_AccessLock));
954 : :
955 : : #ifdef TRACE_OSL_PROFILE
956 : : OSL_TRACE("Out osl_getProfileSectionEntries [not valid]");
957 : : #endif
958 : :
959 : 0 : return sal_False;
960 : : }
961 : :
962 : 0 : pProfile = acquireProfile(Profile, sal_False);
963 : :
964 [ # # ]: 0 : if (pProfile == NULL)
965 : : {
966 : 0 : pthread_mutex_unlock(&(pTmpProfile->m_AccessLock));
967 : :
968 : : #ifdef TRACE_OSL_PROFILE
969 : : OSL_TRACE("Out osl_getProfileSectionEntries [pProfile=0]");
970 : : #endif
971 : :
972 : 0 : return (0);
973 : : }
974 : :
975 : :
976 [ # # ]: 0 : if (! (pProfile->m_Flags & osl_Profile_SYSTEM))
977 : : {
978 [ # # ]: 0 : if ((pSec = findEntry(pProfile, pszSection, "", &NoEntry)) != NULL)
979 : : {
980 [ # # ]: 0 : if (MaxLen != 0)
981 : : {
982 [ # # ]: 0 : for (i = 0; i < pSec->m_NoEntries; i++)
983 : : {
984 [ # # ]: 0 : if ((n + pSec->m_Entries[i].m_Len + 1) < MaxLen)
985 : : {
986 : 0 : strncpy(&pszBuffer[n], &pProfile->m_Lines[pSec->m_Entries[i].m_Line]
987 : 0 : [pSec->m_Entries[i].m_Offset], pSec->m_Entries[i].m_Len);
988 : 0 : n += pSec->m_Entries[i].m_Len;
989 : 0 : pszBuffer[n++] = '\0';
990 : : }
991 : : else
992 : 0 : break;
993 : :
994 : : }
995 : :
996 : 0 : pszBuffer[n++] = '\0';
997 : : }
998 : : else
999 : : {
1000 [ # # ]: 0 : for (i = 0; i < pSec->m_NoEntries; i++)
1001 : 0 : n += pSec->m_Entries[i].m_Len + 1;
1002 : :
1003 : 0 : n += 1;
1004 : : }
1005 : : }
1006 : : else
1007 : 0 : n = 0;
1008 : : }
1009 : : else {
1010 : : /* not implemented */
1011 : : }
1012 : :
1013 : 0 : bRet=releaseProfile(pProfile);
1014 : : OSL_ASSERT(bRet);
1015 : : (void)bRet;
1016 : :
1017 : 0 : pthread_mutex_unlock(&(pTmpProfile->m_AccessLock));
1018 : :
1019 : : #ifdef TRACE_OSL_PROFILE
1020 : : OSL_TRACE("Out osl_getProfileSectionEntries [ok]");
1021 : : #endif
1022 : :
1023 : 0 : return (n);
1024 : : }
1025 : :
1026 : 0 : sal_uInt32 SAL_CALL osl_getProfileSections(oslProfile Profile, sal_Char* pszBuffer, sal_uInt32 MaxLen)
1027 : : {
1028 : 0 : sal_uInt32 i, n = 0;
1029 : : osl_TProfileSection* pSec;
1030 : 0 : osl_TProfileImpl* pProfile = 0;
1031 : 0 : osl_TProfileImpl* pTmpProfile = 0;
1032 : 0 : sal_Bool bRet = sal_False;
1033 : :
1034 : : #ifdef TRACE_OSL_PROFILE
1035 : : OSL_TRACE("In osl_getProfileSections");
1036 : : #endif
1037 : :
1038 : 0 : pTmpProfile = (osl_TProfileImpl*) Profile;
1039 : :
1040 [ # # ]: 0 : if ( pTmpProfile == 0 )
1041 : : {
1042 : : #ifdef TRACE_OSL_PROFILE
1043 : : OSL_TRACE("Out osl_getProfileSections [pTmpProfile==0]");
1044 : : #endif
1045 : 0 : return sal_False;
1046 : : }
1047 : :
1048 : 0 : pthread_mutex_lock(&(pTmpProfile->m_AccessLock));
1049 : :
1050 [ # # ]: 0 : if ( pTmpProfile->m_bIsValid == sal_False )
1051 : : {
1052 : : OSL_ASSERT(pTmpProfile->m_bIsValid);
1053 : 0 : pthread_mutex_unlock(&(pTmpProfile->m_AccessLock));
1054 : : #ifdef TRACE_OSL_PROFILE
1055 : : OSL_TRACE("Out osl_getProfileSections [not valid]");
1056 : : #endif
1057 : 0 : return sal_False;
1058 : : }
1059 : :
1060 : 0 : pProfile = acquireProfile(Profile, sal_False);
1061 : :
1062 [ # # ]: 0 : if (pProfile == NULL)
1063 : : {
1064 : 0 : pthread_mutex_unlock(&(pTmpProfile->m_AccessLock));
1065 : :
1066 : : #ifdef TRACE_OSL_PROFILE
1067 : : OSL_TRACE("Out osl_getProfileSections [pProfile==0]");
1068 : : #endif
1069 : 0 : return (0);
1070 : : }
1071 : :
1072 [ # # ]: 0 : if (! (pProfile->m_Flags & osl_Profile_SYSTEM))
1073 : : {
1074 [ # # ]: 0 : if (MaxLen != 0)
1075 : : {
1076 [ # # ]: 0 : for (i = 0; i < pProfile->m_NoSections; i++)
1077 : : {
1078 : 0 : pSec = &pProfile->m_Sections[i];
1079 : :
1080 [ # # ]: 0 : if ((n + pSec->m_Len + 1) < MaxLen)
1081 : : {
1082 : 0 : strncpy(&pszBuffer[n], &pProfile->m_Lines[pSec->m_Line][pSec->m_Offset],
1083 : 0 : pSec->m_Len);
1084 : 0 : n += pSec->m_Len;
1085 : 0 : pszBuffer[n++] = '\0';
1086 : : }
1087 : : else
1088 : 0 : break;
1089 : : }
1090 : :
1091 : 0 : pszBuffer[n++] = '\0';
1092 : : }
1093 : : else
1094 : : {
1095 [ # # ]: 0 : for (i = 0; i < pProfile->m_NoSections; i++)
1096 : 0 : n += pProfile->m_Sections[i].m_Len + 1;
1097 : :
1098 : 0 : n += 1;
1099 : : }
1100 : : }
1101 : : else
1102 : : { /* not implemented */ }
1103 : :
1104 : :
1105 : 0 : bRet=releaseProfile(pProfile);
1106 : : OSL_ASSERT(bRet);
1107 : : (void)bRet;
1108 : :
1109 : 0 : pthread_mutex_unlock(&(pTmpProfile->m_AccessLock));
1110 : :
1111 : : #ifdef TRACE_OSL_PROFILE
1112 : : OSL_TRACE("Out osl_getProfileSections [ok]");
1113 : : #endif
1114 : :
1115 : 0 : return (n);
1116 : : }
1117 : :
1118 : : /*****************************************************************************/
1119 : : /* Static Module Functions */
1120 : : /*****************************************************************************/
1121 : :
1122 : 2996 : static osl_TStamp OslProfile_getFileStamp(osl_TFile* pFile)
1123 : : {
1124 : : struct stat status;
1125 : :
1126 [ + + ][ - + ]: 2996 : if ( (pFile->m_Handle < 0) || (fstat(pFile->m_Handle, &status) < 0) )
1127 : : {
1128 : 20 : return (0);
1129 : : }
1130 : :
1131 : :
1132 : 2996 : return (status.st_mtime);
1133 : : }
1134 : :
1135 : 0 : static sal_Bool OslProfile_lockFile(const osl_TFile* pFile, osl_TLockMode eMode)
1136 : : {
1137 : : struct flock lock;
1138 : : /* boring hack, but initializers for static vars must be constant */
1139 : : static sal_Bool bIsInitialized = sal_False;
1140 : : static sal_Bool bLockingDisabled;
1141 : :
1142 : : #ifdef TRACE_OSL_PROFILE
1143 : : OSL_TRACE("In OslProfile_lockFile");
1144 : : #endif
1145 : :
1146 [ # # ]: 0 : if ( !bIsInitialized )
1147 : : {
1148 : : sal_Char* pEnvValue;
1149 : 0 : pEnvValue = getenv( "STAR_PROFILE_LOCKING_DISABLED" );
1150 : :
1151 [ # # ]: 0 : if ( pEnvValue == 0 )
1152 : : {
1153 : 0 : bLockingDisabled = sal_False;
1154 : :
1155 : : }
1156 : : else
1157 : : {
1158 : 0 : bLockingDisabled = sal_True;
1159 : : }
1160 : :
1161 : 0 : bIsInitialized = sal_True;
1162 : : }
1163 : :
1164 [ # # ]: 0 : if (pFile->m_Handle < 0)
1165 : : {
1166 : : #ifdef TRACE_OSL_PROFILE
1167 : : OSL_TRACE("Out OslProfile_lockFile [invalid file handle]");
1168 : : #endif
1169 : 0 : return (sal_False);
1170 : : }
1171 : :
1172 : :
1173 [ # # ]: 0 : if ( bLockingDisabled )
1174 : : {
1175 : : #ifdef TRACE_OSL_PROFILE
1176 : : OSL_TRACE("Out OslProfile_lockFile [locking disabled]");
1177 : : #endif
1178 : 0 : return (sal_True);
1179 : : }
1180 : :
1181 : :
1182 : 0 : lock.l_start = 0;
1183 : 0 : lock.l_whence = SEEK_SET;
1184 : 0 : lock.l_len = 0;
1185 : :
1186 [ # # # # ]: 0 : switch (eMode)
1187 : : {
1188 : : case un_lock:
1189 : 0 : lock.l_type = F_UNLCK;
1190 : 0 : break;
1191 : :
1192 : : case read_lock:
1193 : 0 : lock.l_type = F_RDLCK;
1194 : 0 : break;
1195 : :
1196 : : case write_lock:
1197 : 0 : lock.l_type = F_WRLCK;
1198 : 0 : break;
1199 : : }
1200 : :
1201 : : #ifndef MACOSX // not MAC OSX
1202 [ # # ]: 0 : if ( fcntl(pFile->m_Handle, F_SETLKW, &lock) == -1 )
1203 : : #else
1204 : : /* Mac OSX will return ENOTSUP for webdav drives so we should ignore it */
1205 : : if ( fcntl(pFile->m_Handle, F_SETLKW, &lock) == -1 && errno != ENOTSUP )
1206 : : #endif /* MACOSX */
1207 : : {
1208 : : OSL_TRACE("fcntl returned -1 (%s)",strerror(errno));
1209 : : #ifdef TRACE_OSL_PROFILE
1210 : : OSL_TRACE("Out OslProfile_lockFile [fcntl F_SETLKW]");
1211 : : #endif
1212 : 0 : return sal_False;
1213 : : }
1214 : :
1215 : : #ifdef TRACE_OSL_PROFILE
1216 : : OSL_TRACE("Out OslProfile_lockFile [ok]");
1217 : : #endif
1218 : 0 : return sal_True;
1219 : : }
1220 : :
1221 : 1518 : static osl_TFile* openFileImpl(const sal_Char* pszFilename, oslProfileOption ProfileFlags )
1222 : : {
1223 : : int Flags;
1224 : 1518 : osl_TFile* pFile = (osl_TFile*) calloc(1, sizeof(osl_TFile));
1225 : 1518 : sal_Bool bWriteable = sal_False;
1226 : :
1227 [ + + ]: 1518 : if ( ProfileFlags & ( osl_Profile_WRITELOCK | osl_Profile_FLUSHWRITE ) )
1228 : : {
1229 : : #ifdef DEBUG_OSL_PROFILE
1230 : : OSL_TRACE("setting bWriteable to TRUE");
1231 : : #endif
1232 : 10 : bWriteable=sal_True;
1233 : : }
1234 : :
1235 [ + + ]: 1518 : if (! bWriteable)
1236 : : {
1237 : : #ifdef DEBUG_OSL_PROFILE
1238 : : OSL_TRACE("opening '%s' read only",pszFilename);
1239 : : #endif
1240 : :
1241 : 1508 : pFile->m_Handle = open(pszFilename, O_RDONLY);
1242 : : /* mfe: argghh!!! do not check if the file could be openend */
1243 : : /* default mode expects it that way!!! */
1244 : : }
1245 : : else
1246 : : {
1247 : : #ifdef DEBUG_OSL_PROFILE
1248 : : OSL_TRACE("opening '%s' read/write",pszFilename);
1249 : : #endif
1250 [ + - + - ]: 20 : if (((pFile->m_Handle = open(pszFilename, O_RDWR | O_CREAT | O_EXCL, DEFAULT_PMODE)) < 0) &&
1251 : 10 : ((pFile->m_Handle = open(pszFilename, O_RDWR)) < 0))
1252 : : {
1253 : 10 : free(pFile);
1254 : : #ifdef TRACE_OSL_PROFILE
1255 : : OSL_TRACE("Out openFileImpl [open read/write]");
1256 : : #endif
1257 : 10 : return (NULL);
1258 : : }
1259 : : }
1260 : :
1261 : : /* set close-on-exec flag */
1262 [ + + ]: 1508 : if ((Flags = fcntl(pFile->m_Handle, F_GETFD, 0)) != -1)
1263 : : {
1264 : 1488 : Flags |= FD_CLOEXEC;
1265 : 1488 : fcntl(pFile->m_Handle, F_SETFD, Flags);
1266 : : }
1267 : :
1268 : 1508 : pFile->m_pWriteBuf=0;
1269 : 1508 : pFile->m_nWriteBufFree=0;
1270 : 1508 : pFile->m_nWriteBufLen=0;
1271 : :
1272 [ - + ]: 1508 : if ( ProfileFlags & (osl_Profile_WRITELOCK | osl_Profile_READLOCK ) )
1273 : : {
1274 : : #ifdef DEBUG_OSL_PROFILE
1275 : : OSL_TRACE("locking '%s' file",pszFilename);
1276 : : #endif
1277 [ # # ]: 0 : OslProfile_lockFile(pFile, bWriteable ? write_lock : read_lock);
1278 : : }
1279 : :
1280 : : #ifdef TRACE_OSL_PROFILE
1281 : : OSL_TRACE("Out openFileImpl [ok]");
1282 : : #endif
1283 : 1518 : return (pFile);
1284 : : }
1285 : :
1286 : 1508 : static osl_TStamp closeFileImpl(osl_TFile* pFile, oslProfileOption Flags)
1287 : : {
1288 : 1508 : osl_TStamp stamp = 0;
1289 : :
1290 : : #ifdef TRACE_OSL_PROFILE
1291 : : OSL_TRACE("In closeFileImpl");
1292 : : #endif
1293 : :
1294 [ - + ]: 1508 : if ( pFile == 0 )
1295 : : {
1296 : : #ifdef TRACE_OSL_PROFILE
1297 : : OSL_TRACE("Out closeFileImpl [pFile == 0]");
1298 : : #endif
1299 : 0 : return stamp;
1300 : : }
1301 : :
1302 [ + + ]: 1508 : if ( pFile->m_Handle >= 0 )
1303 : : {
1304 : 1488 : stamp = OslProfile_getFileStamp(pFile);
1305 : :
1306 [ - + ]: 1488 : if ( Flags & (osl_Profile_WRITELOCK | osl_Profile_READLOCK ) )
1307 : : {
1308 : 0 : OslProfile_lockFile(pFile, un_lock);
1309 : : }
1310 : :
1311 : 1488 : close(pFile->m_Handle);
1312 : 1488 : pFile->m_Handle = -1;
1313 : : }
1314 : :
1315 : :
1316 [ - + ]: 1508 : if ( pFile->m_pWriteBuf )
1317 : : {
1318 : 0 : free(pFile->m_pWriteBuf);
1319 : : }
1320 : :
1321 : 1508 : free(pFile);
1322 : :
1323 : : #ifdef TRACE_OSL_PROFILE
1324 : : OSL_TRACE("Out closeFileImpl [ok]");
1325 : : #endif
1326 : :
1327 : 1508 : return(stamp);
1328 : : }
1329 : :
1330 : 506 : static sal_Bool OslProfile_rewindFile(osl_TFile* pFile, sal_Bool bTruncate)
1331 : : {
1332 : 506 : sal_Bool bRet = sal_True;
1333 : : #ifdef TRACE_OSL_PROFILE
1334 : : OSL_TRACE("In osl_OslProfile_rewindFile");
1335 : : #endif
1336 : :
1337 [ + + ]: 506 : if (pFile->m_Handle >= 0)
1338 : : {
1339 : 496 : pFile->m_pReadPtr = pFile->m_ReadBuf + sizeof(pFile->m_ReadBuf);
1340 : :
1341 : : #ifdef DEBUG_OSL_PROFILE
1342 : : OSL_TRACE("rewinding");
1343 : : #endif
1344 : 496 : bRet = (lseek(pFile->m_Handle, SEEK_SET, 0L) == 0L);
1345 : :
1346 [ - + ]: 496 : if (bTruncate)
1347 : : {
1348 : : #ifdef DEBUG_OSL_PROFILE
1349 : : OSL_TRACE("truncating");
1350 : : #endif
1351 : 0 : bRet &= (ftruncate(pFile->m_Handle, 0L) == 0);
1352 : : }
1353 : :
1354 : : }
1355 : :
1356 : : #ifdef TRACE_OSL_PROFILE
1357 : : OSL_TRACE("Out osl_OslProfile_rewindFile [ok]");
1358 : : #endif
1359 : 506 : return bRet;
1360 : : }
1361 : :
1362 : :
1363 : 7450 : static sal_Char* OslProfile_getLine(osl_TFile* pFile)
1364 : : {
1365 : 7450 : int Max, Free, Bytes, nLineBytes = 0;
1366 : : sal_Char* pChr;
1367 : 7450 : sal_Char* pLine = NULL;
1368 : : sal_Char* pNewLine;
1369 : :
1370 [ - + ]: 7450 : if ( pFile == 0 )
1371 : : {
1372 : 0 : return 0;
1373 : : }
1374 : :
1375 [ + + ]: 7450 : if (pFile->m_Handle < 0)
1376 : 10 : return NULL;
1377 : :
1378 : : do
1379 : : {
1380 : 7440 : Bytes = sizeof(pFile->m_ReadBuf) - (pFile->m_pReadPtr - pFile->m_ReadBuf);
1381 : :
1382 [ + + ]: 7440 : if (Bytes <= 1)
1383 : : {
1384 : : /* refill buffer */
1385 : 992 : memcpy(pFile->m_ReadBuf, pFile->m_pReadPtr, Bytes);
1386 : 992 : pFile->m_pReadPtr = pFile->m_ReadBuf;
1387 : :
1388 : 992 : Free = sizeof(pFile->m_ReadBuf) - Bytes;
1389 : :
1390 [ - + ]: 992 : if ((Max = read(pFile->m_Handle, &pFile->m_ReadBuf[Bytes], Free)) < 0)
1391 : : {
1392 : : OSL_TRACE("read failed '%s'",strerror(errno));
1393 : :
1394 [ # # ]: 0 : if( pLine )
1395 : 0 : rtl_freeMemory( pLine );
1396 : 0 : pLine = NULL;
1397 : 0 : break;
1398 : : }
1399 : :
1400 [ + - ]: 992 : if (Max < Free)
1401 : : {
1402 [ + + ][ + - ]: 992 : if ((Max == 0) && ! pLine)
1403 : 496 : break;
1404 : :
1405 : 496 : pFile->m_ReadBuf[Bytes + Max] = '\0';
1406 : : }
1407 : : }
1408 : :
1409 [ + + ]: 197904 : for (pChr = pFile->m_pReadPtr;
1410 [ + - ][ + - ]: 190960 : (*pChr != '\n') && (*pChr != '\r') && (*pChr != '\0') &&
[ + - ]
1411 : 190960 : (pChr < (pFile->m_ReadBuf + sizeof(pFile->m_ReadBuf) - 1));
1412 : 190960 : pChr++);
1413 : :
1414 : 6944 : Max = pChr - pFile->m_pReadPtr;
1415 : 6944 : pNewLine = (sal_Char*) rtl_allocateMemory( nLineBytes + Max + 1 );
1416 [ - + ]: 6944 : if( pLine )
1417 : : {
1418 : 0 : memcpy( pNewLine, pLine, nLineBytes );
1419 : 0 : rtl_freeMemory( pLine );
1420 : : }
1421 : 6944 : memcpy(pNewLine+nLineBytes, pFile->m_pReadPtr, Max);
1422 : 6944 : nLineBytes += Max;
1423 : 6944 : pNewLine[ nLineBytes ] = 0;
1424 : 6944 : pLine = pNewLine;
1425 : :
1426 [ + - ]: 6944 : if (pChr < (pFile->m_ReadBuf + sizeof(pFile->m_ReadBuf) - 1))
1427 : : {
1428 [ + - ]: 6944 : if (*pChr != '\0')
1429 : : {
1430 [ - + ][ # # ]: 6944 : if ((pChr[0] == '\r') && (pChr[1] == '\n'))
1431 : 0 : pChr += 2;
1432 : : else
1433 : 6944 : pChr += 1;
1434 : : }
1435 : :
1436 [ + - ][ + + ]: 6944 : if ((pChr < (pFile->m_ReadBuf + sizeof(pFile->m_ReadBuf))) &&
1437 : 6944 : (*pChr == '\0'))
1438 : 496 : pChr = pFile->m_ReadBuf + sizeof(pFile->m_ReadBuf);
1439 : :
1440 : : /* setting Max to -1 indicates terminating read loop */
1441 : 6944 : Max = -1;
1442 : : }
1443 : :
1444 : 6944 : pFile->m_pReadPtr = pChr;
1445 : : }
1446 [ - + ]: 6944 : while (Max > 0);
1447 : :
1448 : 7450 : return pLine;
1449 : : }
1450 : :
1451 : 0 : static sal_Bool OslProfile_putLine(osl_TFile* pFile, const sal_Char *pszLine)
1452 : : {
1453 : 0 : unsigned int Len = strlen(pszLine);
1454 : :
1455 : : #ifdef DEBUG_OSL_PROFILE
1456 : : int strLen=0;
1457 : : #endif
1458 : :
1459 [ # # ][ # # ]: 0 : if ( pFile == 0 || pFile->m_Handle < 0 )
1460 : : {
1461 : 0 : return (sal_False);
1462 : : }
1463 : :
1464 [ # # ]: 0 : if ( pFile->m_pWriteBuf == 0 )
1465 : : {
1466 : 0 : pFile->m_pWriteBuf = (sal_Char*) malloc(Len+3);
1467 : 0 : pFile->m_nWriteBufLen = Len+3;
1468 : 0 : pFile->m_nWriteBufFree = Len+3;
1469 : : }
1470 : : else
1471 : : {
1472 [ # # ]: 0 : if ( pFile->m_nWriteBufFree <= Len + 3 )
1473 : : {
1474 : : sal_Char* pTmp;
1475 : :
1476 : 0 : pTmp=(sal_Char*) realloc(pFile->m_pWriteBuf,( ( pFile->m_nWriteBufLen + Len ) * 2) );
1477 [ # # ]: 0 : if ( pTmp == 0 )
1478 : : {
1479 : 0 : return sal_False;
1480 : : }
1481 : 0 : pFile->m_pWriteBuf = pTmp;
1482 : 0 : pFile->m_nWriteBufFree = pFile->m_nWriteBufFree + pFile->m_nWriteBufLen + ( 2 * Len );
1483 : 0 : pFile->m_nWriteBufLen = ( pFile->m_nWriteBufLen + Len ) * 2;
1484 : 0 : memset( (pFile->m_pWriteBuf) + ( pFile->m_nWriteBufLen - pFile->m_nWriteBufFree ), 0, pFile->m_nWriteBufFree);
1485 : : }
1486 : : }
1487 : :
1488 : :
1489 : :
1490 : 0 : memcpy(pFile->m_pWriteBuf + ( pFile->m_nWriteBufLen - pFile->m_nWriteBufFree ),pszLine,Len+1);
1491 : : #ifdef DEBUG_OSL_PROFILE
1492 : : strLen = strlen(pFile->m_pWriteBuf);
1493 : : #endif
1494 : 0 : pFile->m_pWriteBuf[pFile->m_nWriteBufLen - pFile->m_nWriteBufFree + Len]='\n';
1495 : 0 : pFile->m_pWriteBuf[pFile->m_nWriteBufLen - pFile->m_nWriteBufFree + Len + 1]='\0';
1496 : :
1497 : 0 : pFile->m_nWriteBufFree-=Len+1;
1498 : :
1499 : 0 : return sal_True;
1500 : : }
1501 : :
1502 : : /* platform specific end */
1503 : :
1504 : 20832 : static sal_Char* stripBlanks(sal_Char* String, sal_uInt32* pLen)
1505 : : {
1506 [ + + ][ + - ]: 34224 : if ( ( pLen != NULL ) && ( *pLen != 0 ) )
1507 : : {
1508 [ - + ][ - + ]: 13392 : while ((String[*pLen - 1] == ' ') || (String[*pLen - 1] == '\t'))
1509 : 0 : (*pLen)--;
1510 : :
1511 [ - + ][ - + ]: 13392 : while ( (*String == ' ') || (*String == '\t') )
1512 : : {
1513 : 0 : String++;
1514 : 0 : (*pLen)--;
1515 : : }
1516 : : }
1517 : : else
1518 [ - + ][ - + ]: 7440 : while ( (*String == ' ') || (*String == '\t') )
1519 : 0 : String++;
1520 : :
1521 : 20832 : return (String);
1522 : : }
1523 : :
1524 : 6944 : static sal_Char* addLine(osl_TProfileImpl* pProfile, const sal_Char* Line)
1525 : : {
1526 [ + + ]: 6944 : if (pProfile->m_NoLines >= pProfile->m_MaxLines)
1527 : : {
1528 [ + - ]: 496 : if (pProfile->m_Lines == NULL)
1529 : : {
1530 : 496 : pProfile->m_MaxLines = LINES_INI;
1531 : 496 : pProfile->m_Lines = (sal_Char **)malloc(pProfile->m_MaxLines * sizeof(sal_Char *));
1532 : 496 : memset(pProfile->m_Lines,0,pProfile->m_MaxLines * sizeof(sal_Char *));
1533 : : }
1534 : : else
1535 : : {
1536 : 0 : unsigned int idx=0;
1537 : 0 : unsigned int oldmax=pProfile->m_MaxLines;
1538 : :
1539 : 0 : pProfile->m_MaxLines += LINES_ADD;
1540 : 0 : pProfile->m_Lines = (sal_Char **)realloc(pProfile->m_Lines,
1541 : 0 : pProfile->m_MaxLines * sizeof(sal_Char *));
1542 [ # # ]: 0 : for ( idx = oldmax ; idx < pProfile->m_MaxLines ; ++idx )
1543 : : {
1544 : 0 : pProfile->m_Lines[idx]=0;
1545 : : }
1546 : : }
1547 : :
1548 [ - + ]: 496 : if (pProfile->m_Lines == NULL)
1549 : : {
1550 : 0 : pProfile->m_NoLines = 0;
1551 : 0 : pProfile->m_MaxLines = 0;
1552 : 0 : return (NULL);
1553 : : }
1554 : :
1555 : : }
1556 : :
1557 [ + - ][ - + ]: 6944 : if ( pProfile->m_Lines != 0 && pProfile->m_Lines[pProfile->m_NoLines] != 0 )
1558 : : {
1559 : 0 : free(pProfile->m_Lines[pProfile->m_NoLines]);
1560 : : }
1561 : 6944 : pProfile->m_Lines[pProfile->m_NoLines++] = strdup(Line);
1562 : :
1563 : 6944 : return (pProfile->m_Lines[pProfile->m_NoLines - 1]);
1564 : : }
1565 : :
1566 : 0 : static sal_Char* insertLine(osl_TProfileImpl* pProfile, const sal_Char* Line, sal_uInt32 LineNo)
1567 : : {
1568 [ # # ]: 0 : if (pProfile->m_NoLines >= pProfile->m_MaxLines)
1569 : : {
1570 [ # # ]: 0 : if (pProfile->m_Lines == NULL)
1571 : : {
1572 : 0 : pProfile->m_MaxLines = LINES_INI;
1573 : 0 : pProfile->m_Lines = (sal_Char **)malloc(pProfile->m_MaxLines * sizeof(sal_Char *));
1574 : 0 : memset(pProfile->m_Lines,0,pProfile->m_MaxLines * sizeof(sal_Char *));
1575 : : }
1576 : : else
1577 : : {
1578 : 0 : pProfile->m_MaxLines += LINES_ADD;
1579 : 0 : pProfile->m_Lines = (sal_Char **)realloc(pProfile->m_Lines,
1580 : 0 : pProfile->m_MaxLines * sizeof(sal_Char *));
1581 : :
1582 : 0 : memset(&pProfile->m_Lines[pProfile->m_NoLines],
1583 : : 0,
1584 : 0 : (pProfile->m_MaxLines - pProfile->m_NoLines - 1) * sizeof(sal_Char*));
1585 : : }
1586 : :
1587 [ # # ]: 0 : if (pProfile->m_Lines == NULL)
1588 : : {
1589 : 0 : pProfile->m_NoLines = 0;
1590 : 0 : pProfile->m_MaxLines = 0;
1591 : 0 : return (NULL);
1592 : : }
1593 : : }
1594 : :
1595 : 0 : LineNo = LineNo > pProfile->m_NoLines ? pProfile->m_NoLines : LineNo;
1596 : :
1597 [ # # ]: 0 : if (LineNo < pProfile->m_NoLines)
1598 : : {
1599 : : sal_uInt32 i, n;
1600 : : osl_TProfileSection* pSec;
1601 : :
1602 : 0 : memmove(&pProfile->m_Lines[LineNo + 1], &pProfile->m_Lines[LineNo],
1603 : 0 : (pProfile->m_NoLines - LineNo) * sizeof(sal_Char *));
1604 : :
1605 : :
1606 : : /* adjust line references */
1607 [ # # ]: 0 : for (i = 0; i < pProfile->m_NoSections; i++)
1608 : : {
1609 : 0 : pSec = &pProfile->m_Sections[i];
1610 : :
1611 [ # # ]: 0 : if (pSec->m_Line >= LineNo)
1612 : 0 : pSec->m_Line++;
1613 : :
1614 [ # # ]: 0 : for (n = 0; n < pSec->m_NoEntries; n++)
1615 [ # # ]: 0 : if (pSec->m_Entries[n].m_Line >= LineNo)
1616 : 0 : pSec->m_Entries[n].m_Line++;
1617 : : }
1618 : : }
1619 : :
1620 : 0 : pProfile->m_NoLines++;
1621 : :
1622 : 0 : pProfile->m_Lines[LineNo] = strdup(Line);
1623 : :
1624 : 0 : return (pProfile->m_Lines[LineNo]);
1625 : : }
1626 : :
1627 : 0 : static void removeLine(osl_TProfileImpl* pProfile, sal_uInt32 LineNo)
1628 : : {
1629 [ # # ]: 0 : if (LineNo < pProfile->m_NoLines)
1630 : : {
1631 : 0 : free(pProfile->m_Lines[LineNo]);
1632 : 0 : pProfile->m_Lines[LineNo]=0;
1633 [ # # ]: 0 : if (pProfile->m_NoLines - LineNo > 1)
1634 : : {
1635 : : sal_uInt32 i, n;
1636 : : osl_TProfileSection* pSec;
1637 : :
1638 : 0 : memmove(&pProfile->m_Lines[LineNo], &pProfile->m_Lines[LineNo + 1],
1639 : 0 : (pProfile->m_NoLines - LineNo - 1) * sizeof(sal_Char *));
1640 : :
1641 : 0 : memset(&pProfile->m_Lines[pProfile->m_NoLines - 1],
1642 : : 0,
1643 : 0 : (pProfile->m_MaxLines - pProfile->m_NoLines) * sizeof(sal_Char*));
1644 : :
1645 : : /* adjust line references */
1646 [ # # ]: 0 : for (i = 0; i < pProfile->m_NoSections; i++)
1647 : : {
1648 : 0 : pSec = &pProfile->m_Sections[i];
1649 : :
1650 [ # # ]: 0 : if (pSec->m_Line > LineNo)
1651 : 0 : pSec->m_Line--;
1652 : :
1653 [ # # ]: 0 : for (n = 0; n < pSec->m_NoEntries; n++)
1654 [ # # ]: 0 : if (pSec->m_Entries[n].m_Line > LineNo)
1655 : 0 : pSec->m_Entries[n].m_Line--;
1656 : : }
1657 : : }
1658 : : else
1659 : : {
1660 : 0 : pProfile->m_Lines[LineNo] = 0;
1661 : : }
1662 : :
1663 : 0 : pProfile->m_NoLines--;
1664 : : }
1665 : :
1666 : 0 : return;
1667 : : }
1668 : :
1669 : 6448 : static void setEntry(osl_TProfileImpl* pProfile, osl_TProfileSection* pSection,
1670 : : sal_uInt32 NoEntry, sal_uInt32 Line,
1671 : : sal_Char* Entry, sal_uInt32 Len)
1672 : : {
1673 : 6448 : Entry = stripBlanks(Entry, &Len);
1674 : 6448 : pSection->m_Entries[NoEntry].m_Line = Line;
1675 : 6448 : pSection->m_Entries[NoEntry].m_Offset = Entry - pProfile->m_Lines[Line];
1676 : 6448 : pSection->m_Entries[NoEntry].m_Len = Len;
1677 : :
1678 : 6448 : return;
1679 : : }
1680 : :
1681 : 6448 : static sal_Bool addEntry(osl_TProfileImpl* pProfile, osl_TProfileSection *pSection,
1682 : : int Line, sal_Char* Entry, sal_uInt32 Len)
1683 : : {
1684 [ + - ]: 6448 : if (pSection != NULL)
1685 : : {
1686 [ + + ]: 6448 : if (pSection->m_NoEntries >= pSection->m_MaxEntries)
1687 : : {
1688 [ + + ]: 1984 : if (pSection->m_Entries == NULL)
1689 : : {
1690 : 496 : pSection->m_MaxEntries = ENTRIES_INI;
1691 : 496 : pSection->m_Entries = (osl_TProfileEntry *)malloc(
1692 : 496 : pSection->m_MaxEntries * sizeof(osl_TProfileEntry));
1693 : : }
1694 : : else
1695 : : {
1696 : 1488 : pSection->m_MaxEntries += ENTRIES_ADD;
1697 : 1488 : pSection->m_Entries = (osl_TProfileEntry *)realloc(pSection->m_Entries,
1698 : 1488 : pSection->m_MaxEntries * sizeof(osl_TProfileEntry));
1699 : : }
1700 : :
1701 [ - + ]: 1984 : if (pSection->m_Entries == NULL)
1702 : : {
1703 : 0 : pSection->m_NoEntries = 0;
1704 : 0 : pSection->m_MaxEntries = 0;
1705 : 0 : return (sal_False);
1706 : : }
1707 : : }
1708 : :
1709 : 6448 : pSection->m_NoEntries++;
1710 : :
1711 : 6448 : Entry = stripBlanks(Entry, &Len);
1712 : 6448 : setEntry(pProfile, pSection, pSection->m_NoEntries - 1, Line,
1713 : : Entry, Len);
1714 : :
1715 : 6448 : return (sal_True);
1716 : : }
1717 : :
1718 : 6448 : return (sal_False);
1719 : : }
1720 : :
1721 : 0 : static void removeEntry(osl_TProfileSection *pSection, sal_uInt32 NoEntry)
1722 : : {
1723 [ # # ]: 0 : if (NoEntry < pSection->m_NoEntries)
1724 : : {
1725 [ # # ]: 0 : if (pSection->m_NoEntries - NoEntry > 1)
1726 : : {
1727 : 0 : memmove(&pSection->m_Entries[NoEntry],
1728 : 0 : &pSection->m_Entries[NoEntry + 1],
1729 : 0 : (pSection->m_NoEntries - NoEntry - 1) * sizeof(osl_TProfileEntry));
1730 : 0 : pSection->m_Entries[pSection->m_NoEntries - 1].m_Line=0;
1731 : 0 : pSection->m_Entries[pSection->m_NoEntries - 1].m_Offset=0;
1732 : 0 : pSection->m_Entries[pSection->m_NoEntries - 1].m_Len=0;
1733 : : }
1734 : :
1735 : 0 : pSection->m_NoEntries--;
1736 : : }
1737 : :
1738 : 0 : return;
1739 : : }
1740 : :
1741 : 496 : static sal_Bool addSection(osl_TProfileImpl* pProfile, int Line, const sal_Char* Section, sal_uInt32 Len)
1742 : : {
1743 [ + - ]: 496 : if (pProfile->m_NoSections >= pProfile->m_MaxSections)
1744 : : {
1745 [ + - ]: 496 : if (pProfile->m_Sections == NULL)
1746 : : {
1747 : 496 : pProfile->m_MaxSections = SECTIONS_INI;
1748 : 496 : pProfile->m_Sections = (osl_TProfileSection *)malloc(pProfile->m_MaxSections * sizeof(osl_TProfileSection));
1749 : 496 : memset(pProfile->m_Sections,0,pProfile->m_MaxSections * sizeof(osl_TProfileSection));
1750 : : }
1751 : : else
1752 : : {
1753 : 0 : unsigned int idx=0;
1754 : 0 : unsigned int oldmax=pProfile->m_MaxSections;
1755 : :
1756 : 0 : pProfile->m_MaxSections += SECTIONS_ADD;
1757 : 0 : pProfile->m_Sections = (osl_TProfileSection *)realloc(pProfile->m_Sections,
1758 : 0 : pProfile->m_MaxSections * sizeof(osl_TProfileSection));
1759 [ # # ]: 0 : for ( idx = oldmax ; idx < pProfile->m_MaxSections ; ++idx )
1760 : : {
1761 : 0 : pProfile->m_Sections[idx].m_Entries=0;
1762 : : }
1763 : : }
1764 : :
1765 [ - + ]: 496 : if (pProfile->m_Sections == NULL)
1766 : : {
1767 : 0 : pProfile->m_NoSections = 0;
1768 : 0 : pProfile->m_MaxSections = 0;
1769 : 0 : return (sal_False);
1770 : : }
1771 : : }
1772 : :
1773 : 496 : pProfile->m_NoSections++;
1774 : :
1775 [ - + ]: 496 : if ( pProfile->m_Sections[(pProfile->m_NoSections) - 1].m_Entries != 0 )
1776 : : {
1777 : 0 : free(pProfile->m_Sections[(pProfile->m_NoSections) - 1].m_Entries);
1778 : : }
1779 : 496 : pProfile->m_Sections[pProfile->m_NoSections - 1].m_Entries = NULL;
1780 : 496 : pProfile->m_Sections[pProfile->m_NoSections - 1].m_NoEntries = 0;
1781 : 496 : pProfile->m_Sections[pProfile->m_NoSections - 1].m_MaxEntries = 0;
1782 : :
1783 : 496 : pProfile->m_Sections[pProfile->m_NoSections - 1].m_Line = Line;
1784 : 496 : pProfile->m_Sections[pProfile->m_NoSections - 1].m_Offset = Section - pProfile->m_Lines[Line];
1785 : 496 : pProfile->m_Sections[pProfile->m_NoSections - 1].m_Len = Len;
1786 : :
1787 : 496 : return (sal_True);
1788 : : }
1789 : :
1790 : 0 : static void removeSection(osl_TProfileImpl* pProfile, osl_TProfileSection *pSection)
1791 : : {
1792 : : sal_uInt32 Section;
1793 : :
1794 [ # # ]: 0 : if ((Section = pSection - pProfile->m_Sections) < pProfile->m_NoSections)
1795 : : {
1796 : 0 : free (pSection->m_Entries);
1797 : 0 : pSection->m_Entries=0;
1798 [ # # ]: 0 : if (pProfile->m_NoSections - Section > 1)
1799 : : {
1800 : 0 : memmove(&pProfile->m_Sections[Section], &pProfile->m_Sections[Section + 1],
1801 : 0 : (pProfile->m_NoSections - Section - 1) * sizeof(osl_TProfileSection));
1802 : :
1803 : 0 : memset(&pProfile->m_Sections[pProfile->m_NoSections - 1],
1804 : : 0,
1805 : 0 : (pProfile->m_MaxSections - pProfile->m_NoSections) * sizeof(osl_TProfileSection));
1806 : 0 : pProfile->m_Sections[pProfile->m_NoSections - 1].m_Entries = 0;
1807 : : }
1808 : : else
1809 : : {
1810 : 0 : pSection->m_Entries = 0;
1811 : : }
1812 : :
1813 : 0 : pProfile->m_NoSections--;
1814 : : }
1815 : :
1816 : 0 : return;
1817 : : }
1818 : :
1819 : 496 : static osl_TProfileSection* findEntry(osl_TProfileImpl* pProfile, const sal_Char* Section,
1820 : : const sal_Char* Entry, sal_uInt32 *pNoEntry)
1821 : : {
1822 : : static sal_uInt32 Sect = 0;
1823 : : sal_uInt32 i, n;
1824 : : sal_uInt32 Len;
1825 : : const sal_Char* pStr;
1826 : 496 : osl_TProfileSection* pSec=0;
1827 : :
1828 : 496 : Len = strlen(Section);
1829 : :
1830 : 496 : n = Sect;
1831 : :
1832 [ + - ]: 496 : for (i = 0; i < pProfile->m_NoSections; i++)
1833 : : {
1834 : 496 : n %= pProfile->m_NoSections;
1835 : 496 : pSec = &pProfile->m_Sections[n];
1836 [ + - ][ + - ]: 496 : if ((Len == pSec->m_Len) &&
1837 : 496 : (strncasecmp(Section, &pProfile->m_Lines[pSec->m_Line][pSec->m_Offset], pSec->m_Len)
1838 : : == 0))
1839 : 496 : break;
1840 : 0 : n++;
1841 : : }
1842 : :
1843 : 496 : Sect = n;
1844 : :
1845 [ + - ]: 496 : if (i < pProfile->m_NoSections)
1846 : : {
1847 : 496 : Len = strlen(Entry);
1848 : :
1849 : 496 : *pNoEntry = pSec->m_NoEntries;
1850 : :
1851 [ + - ]: 4960 : for (i = 0; i < pSec->m_NoEntries; i++)
1852 : : {
1853 : 8928 : pStr = &pProfile->m_Lines[pSec->m_Entries[i].m_Line]
1854 : 4464 : [pSec->m_Entries[i].m_Offset];
1855 [ + + ][ + - ]: 4464 : if ((Len == pSec->m_Entries[i].m_Len) &&
1856 : 496 : (strncasecmp(Entry, pStr, pSec->m_Entries[i].m_Len)
1857 : : == 0))
1858 : : {
1859 : 496 : *pNoEntry = i;
1860 : 496 : break;
1861 : : }
1862 : : }
1863 : : }
1864 : : else
1865 : 0 : pSec = NULL;
1866 : :
1867 : 496 : return (pSec);
1868 : : }
1869 : :
1870 : 506 : static sal_Bool loadProfile(osl_TFile* pFile, osl_TProfileImpl* pProfile)
1871 : : {
1872 : : sal_uInt32 i;
1873 : : sal_Char* pStr;
1874 : : sal_Char* pChar;
1875 : :
1876 : : sal_Char* pLine;
1877 : 506 : sal_Char* bWasAdded = NULL;
1878 : :
1879 : :
1880 [ - + ]: 506 : if ( !pFile )
1881 : : {
1882 : 0 : return sal_False;
1883 : : }
1884 : :
1885 [ - + ]: 506 : if ( !pProfile )
1886 : : {
1887 : 0 : return sal_False;
1888 : : }
1889 : :
1890 : 506 : pProfile->m_NoLines = 0;
1891 : 506 : pProfile->m_NoSections = 0;
1892 : :
1893 : 506 : OSL_VERIFY(OslProfile_rewindFile(pFile, sal_False));
1894 : :
1895 [ + + ]: 7450 : while ( ( pLine=OslProfile_getLine(pFile) ) != 0 )
1896 : : {
1897 : 6944 : bWasAdded = addLine( pProfile, pLine );
1898 : 6944 : rtl_freeMemory( pLine );
1899 : : OSL_ASSERT(bWasAdded);
1900 [ - + ]: 6944 : if ( ! bWasAdded )
1901 : 0 : return (sal_False);
1902 : : }
1903 : :
1904 [ + + ]: 7450 : for (i = 0; i < pProfile->m_NoLines; i++)
1905 : : {
1906 : 6944 : pStr = (sal_Char *)stripBlanks(pProfile->m_Lines[i], NULL);
1907 : :
1908 [ - + ][ + - ]: 6944 : if ((*pStr == '\0') || (*pStr == ';'))
1909 : 0 : continue;
1910 : :
1911 [ + + ][ + - ]: 6944 : if ((*pStr != '[') || ((pChar = strrchr(pStr, ']')) == NULL) ||
[ - + ]
1912 : 496 : ((pChar - pStr) <= 2))
1913 : : {
1914 : : /* insert entry */
1915 : :
1916 [ - + ]: 6448 : if (pProfile->m_NoSections < 1)
1917 : 0 : continue;
1918 : :
1919 [ - + ]: 6448 : if ((pChar = strchr(pStr, '=')) == NULL)
1920 : 0 : pChar = pStr + strlen(pStr);
1921 : :
1922 [ - + ]: 6448 : if (! addEntry(pProfile, &pProfile->m_Sections[pProfile->m_NoSections - 1],
1923 : 6448 : i, pStr, pChar - pStr))
1924 : : {
1925 : : OSL_ASSERT(0);
1926 : 0 : continue;
1927 : : }
1928 : :
1929 : : }
1930 : : else
1931 : : {
1932 : : /* new section */
1933 : :
1934 [ - + ]: 496 : if (! addSection(pProfile, i, pStr + 1, pChar - pStr - 1))
1935 : : {
1936 : : OSL_ASSERT(0);
1937 : 0 : continue;
1938 : : }
1939 : :
1940 : : }
1941 : : }
1942 : :
1943 : 506 : return (sal_True);
1944 : : }
1945 : :
1946 : 0 : static sal_Bool storeProfile(osl_TProfileImpl* pProfile, sal_Bool bCleanup)
1947 : : {
1948 : : #ifdef TRACE_OSL_PROFILE
1949 : : OSL_TRACE("In storeProfile");
1950 : : #endif
1951 : :
1952 [ # # ]: 0 : if (pProfile->m_Lines != NULL)
1953 : : {
1954 [ # # ]: 0 : if (pProfile->m_Flags & FLG_MODIFIED)
1955 : : {
1956 : : sal_uInt32 i;
1957 : :
1958 : 0 : osl_TFile* pTmpFile = osl_openTmpProfileImpl(pProfile);
1959 : :
1960 [ # # ]: 0 : if ( pTmpFile == 0 )
1961 : : {
1962 : 0 : return sal_False;
1963 : : }
1964 : :
1965 : 0 : OSL_VERIFY(OslProfile_rewindFile(pTmpFile, sal_True));
1966 : :
1967 [ # # ]: 0 : for ( i = 0 ; i < pProfile->m_NoLines ; i++ )
1968 : : {
1969 : 0 : OSL_VERIFY(OslProfile_putLine(pTmpFile, pProfile->m_Lines[i]));
1970 : : }
1971 : :
1972 [ # # ]: 0 : if ( ! writeProfileImpl(pTmpFile) )
1973 : : {
1974 [ # # ]: 0 : if ( pTmpFile->m_pWriteBuf != 0 )
1975 : : {
1976 : 0 : free(pTmpFile->m_pWriteBuf);
1977 : : }
1978 : :
1979 : 0 : pTmpFile->m_pWriteBuf=0;
1980 : 0 : pTmpFile->m_nWriteBufLen=0;
1981 : 0 : pTmpFile->m_nWriteBufFree=0;
1982 : :
1983 : : #ifdef TRACE_OSL_PROFILE
1984 : : OSL_TRACE("Out storeProfile [not flushed]");
1985 : : #endif
1986 : 0 : closeFileImpl(pTmpFile,pProfile->m_Flags);
1987 : :
1988 : 0 : return sal_False;
1989 : : }
1990 : :
1991 : 0 : pProfile->m_Flags &= ~FLG_MODIFIED;
1992 : :
1993 : 0 : closeFileImpl(pProfile->m_pFile,pProfile->m_Flags);
1994 : 0 : closeFileImpl(pTmpFile,pProfile->m_Flags);
1995 : :
1996 : 0 : osl_ProfileSwapProfileNames(pProfile);
1997 : :
1998 : 0 : pProfile->m_pFile = openFileImpl(pProfile->m_FileName,pProfile->m_Flags);
1999 : :
2000 : : }
2001 : :
2002 [ # # ]: 0 : if (bCleanup)
2003 : : {
2004 [ # # ]: 0 : while (pProfile->m_NoLines > 0)
2005 : 0 : removeLine(pProfile, pProfile->m_NoLines - 1);
2006 : :
2007 : 0 : free(pProfile->m_Lines);
2008 : 0 : pProfile->m_Lines = NULL;
2009 : 0 : pProfile->m_NoLines = 0;
2010 : 0 : pProfile->m_MaxLines = 0;
2011 : :
2012 [ # # ]: 0 : while (pProfile->m_NoSections > 0)
2013 : 0 : removeSection(pProfile, &pProfile->m_Sections[pProfile->m_NoSections - 1]);
2014 : :
2015 : 0 : free(pProfile->m_Sections);
2016 : 0 : pProfile->m_Sections = NULL;
2017 : 0 : pProfile->m_NoSections = 0;
2018 : 0 : pProfile->m_MaxSections = 0;
2019 : : }
2020 : : }
2021 : :
2022 : : #ifdef TRACE_OSL_PROFILE
2023 : : OSL_TRACE("Out storeProfile [ok]");
2024 : : #endif
2025 : 0 : return (sal_True);
2026 : : }
2027 : :
2028 : :
2029 : 0 : static osl_TFile* osl_openTmpProfileImpl(osl_TProfileImpl* pProfile)
2030 : : {
2031 : 0 : osl_TFile* pFile=0;
2032 : 0 : sal_Char* pszExtension = "tmp";
2033 : : sal_Char pszTmpName[PATH_MAX];
2034 : 0 : oslProfileOption PFlags=0;
2035 : :
2036 : 0 : pszTmpName[0] = '\0';
2037 : :
2038 : : /* generate tmp profilename */
2039 : 0 : osl_ProfileGenerateExtension(pProfile->m_FileName,pszExtension,pszTmpName);
2040 : :
2041 [ # # ]: 0 : if ( pszTmpName[0] == 0 )
2042 : : {
2043 : 0 : return 0;
2044 : : }
2045 : :
2046 [ # # ]: 0 : if ( ! ( pProfile->m_Flags & osl_Profile_READLOCK ) )
2047 : : {
2048 : 0 : PFlags |= osl_Profile_WRITELOCK;
2049 : : }
2050 : :
2051 : : /* open this file */
2052 : 0 : pFile = openFileImpl(pszTmpName,pProfile->m_Flags | PFlags);
2053 : :
2054 : :
2055 : : /* return new pFile */
2056 : 0 : return pFile;
2057 : : }
2058 : :
2059 : 0 : static sal_Bool osl_ProfileSwapProfileNames(osl_TProfileImpl* pProfile)
2060 : : {
2061 : 0 : sal_Bool bRet = sal_False;
2062 : :
2063 : : sal_Char pszBakFile[PATH_MAX];
2064 : : sal_Char pszTmpFile[PATH_MAX];
2065 : : sal_Char pszIniFile[PATH_MAX];
2066 : :
2067 : 0 : pszBakFile[0] = '\0';
2068 : 0 : pszTmpFile[0] = '\0';
2069 : 0 : pszIniFile[0] = '\0';
2070 : :
2071 : 0 : osl_ProfileGenerateExtension(pProfile->m_FileName,"bak",pszBakFile);
2072 : :
2073 : 0 : strcpy(pszIniFile,pProfile->m_FileName);
2074 : :
2075 : 0 : osl_ProfileGenerateExtension(pProfile->m_FileName,"tmp",pszTmpFile);
2076 : :
2077 : : /* unlink bak */
2078 : 0 : unlink( pszBakFile );
2079 : :
2080 : : /* rename ini bak */
2081 : 0 : rename( pszIniFile, pszBakFile );
2082 : :
2083 : : /* rename tmp ini */
2084 : 0 : rename( pszTmpFile, pszIniFile );
2085 : :
2086 : 0 : return bRet;
2087 : : }
2088 : :
2089 : :
2090 : 0 : static void osl_ProfileGenerateExtension(sal_Char* pszFileName, sal_Char* pszExtension, sal_Char* pszTmpName)
2091 : : {
2092 : :
2093 : 0 : strcpy(pszTmpName,pszFileName);
2094 : 0 : strcat(pszTmpName,".");
2095 : 0 : strcat(pszTmpName,pszExtension);
2096 : :
2097 : 0 : return;
2098 : : }
2099 : :
2100 : :
2101 : 1012 : static osl_TProfileImpl* acquireProfile(oslProfile Profile, sal_Bool bWriteable)
2102 : : {
2103 : 1012 : osl_TProfileImpl* pProfile = (osl_TProfileImpl*)Profile;
2104 : 1012 : oslProfileOption PFlags=0;
2105 : :
2106 [ + + ]: 1012 : if ( bWriteable )
2107 : : {
2108 : 10 : PFlags = osl_Profile_DEFAULT | osl_Profile_WRITELOCK;
2109 : : }
2110 : : else
2111 : : {
2112 : 1002 : PFlags = osl_Profile_DEFAULT;
2113 : : }
2114 : :
2115 : :
2116 [ - + ]: 1012 : if (pProfile == NULL)
2117 : : {
2118 : : #ifdef DEBUG_OSL_PROFILE
2119 : : OSL_TRACE("AUTOOPEN MODE");
2120 : : #endif
2121 : :
2122 [ # # ]: 0 : if ( ( pProfile = (osl_TProfileImpl*) osl_openProfile(0, PFlags ) ) != NULL )
2123 : : {
2124 : 0 : pProfile->m_Flags |= FLG_AUTOOPEN;
2125 : : }
2126 : : }
2127 : : else
2128 : : {
2129 : : #ifdef DEBUG_OSL_PROFILE
2130 : : OSL_TRACE("try to acquire");
2131 : : #endif
2132 : :
2133 [ + - ]: 1012 : if (! (pProfile->m_Flags & osl_Profile_SYSTEM))
2134 : : {
2135 [ + - ]: 1012 : if (! (pProfile->m_Flags & (osl_Profile_READLOCK | osl_Profile_WRITELOCK | osl_Profile_FLUSHWRITE )))
2136 : : {
2137 : : osl_TStamp Stamp;
2138 : :
2139 : : #ifdef DEBUG_OSL_PROFILE
2140 : : OSL_TRACE("Profile acquire DEFAULT MODE");
2141 : : #endif
2142 [ + + ]: 1012 : if (! (pProfile->m_pFile = openFileImpl(pProfile->m_FileName, pProfile->m_Flags | PFlags )))
2143 : 10 : return NULL;
2144 : :
2145 : 1002 : Stamp = OslProfile_getFileStamp(pProfile->m_pFile);
2146 : :
2147 [ - + ]: 1002 : if (memcmp(&Stamp, &(pProfile->m_Stamp), sizeof(osl_TStamp)))
2148 : : {
2149 : 0 : sal_Bool bRet=sal_False;
2150 : :
2151 : 0 : pProfile->m_Stamp = Stamp;
2152 : :
2153 : 1002 : bRet=loadProfile(pProfile->m_pFile, pProfile);
2154 : : OSL_ASSERT(bRet);
2155 : : (void)bRet;
2156 : : }
2157 : : }
2158 : : else
2159 : : {
2160 : : #ifdef DEBUG_OSL_PROFILE
2161 : : OSL_TRACE("Profile acquire READ/WRITELOCK MODE");
2162 : : #endif
2163 : : /* A readlock file could not be written */
2164 [ # # ][ # # ]: 0 : if ((pProfile->m_Flags & osl_Profile_READLOCK) && bWriteable)
2165 : : {
2166 : 0 : return (NULL);
2167 : : }
2168 : : }
2169 : : }
2170 : : }
2171 : :
2172 : 1012 : return (pProfile);
2173 : : }
2174 : :
2175 : 496 : static sal_Bool releaseProfile(osl_TProfileImpl* pProfile)
2176 : : {
2177 : : #ifdef TRACE_OSL_PROFILE
2178 : : OSL_TRACE("In releaseProfile");
2179 : : #endif
2180 : :
2181 [ - + ]: 496 : if ( pProfile == 0 )
2182 : : {
2183 : : #ifdef TRACE_OSL_PROFILE
2184 : : OSL_TRACE("Out releaseProfile [profile==0]");
2185 : : #endif
2186 : 0 : return sal_False;
2187 : : }
2188 : :
2189 [ - + ]: 496 : if (pProfile->m_Flags & FLG_AUTOOPEN)
2190 : : {
2191 : : #ifdef TRACE_OSL_PROFILE
2192 : : OSL_TRACE("Out releaseProfile [AUTOOPEN]");
2193 : : #endif
2194 : 0 : return (osl_closeProfile((oslProfile)pProfile));
2195 : : }
2196 : : else
2197 : : {
2198 : : #ifdef DEBUG_OSL_PROFILE
2199 : : OSL_TRACE("DEFAULT MODE");
2200 : : #endif
2201 [ + - ]: 496 : if (! (pProfile->m_Flags & (osl_Profile_READLOCK | osl_Profile_WRITELOCK | osl_Profile_FLUSHWRITE )))
2202 : : {
2203 [ - + ]: 496 : if (pProfile->m_Flags & FLG_MODIFIED)
2204 : : {
2205 : 0 : sal_Bool bRet=storeProfile(pProfile, sal_False);
2206 : : OSL_ASSERT(bRet);
2207 : : (void)bRet;
2208 : : }
2209 : :
2210 : 496 : closeFileImpl(pProfile->m_pFile,pProfile->m_Flags);
2211 : 496 : pProfile->m_pFile = NULL;
2212 : : }
2213 : : }
2214 : :
2215 : : #ifdef TRACE_OSL_PROFILE
2216 : : OSL_TRACE("Out releaseProfile [ok]");
2217 : : #endif
2218 : 496 : return (sal_True);
2219 : : }
2220 : :
2221 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|