/*
- * $XFree86: xc/lib/fontconfig/fontconfig/fontconfig.h,v 1.4 2002/02/28 16:51:48 keithp Exp $
+ * $XFree86: xc/lib/fontconfig/fontconfig/fontconfig.h,v 1.5 2002/03/01 01:00:54 keithp Exp $
*
* Copyright © 2001 Keith Packard, member of The XFree86 Project, Inc.
*
FcSetApplication = 1
} FcSetName;
+typedef struct _FcAtomic FcAtomic;
+
#if defined(__cplusplus) || defined(c_plusplus) /* for C++ V2.0 */
#define _FCFUNCPROTOBEGIN extern "C" { /* do not leave open across includes */
#define _FCFUNCPROTOEND }
FcPattern *p,
FcObjectSet *os);
+/* fcatomic.c */
+
+FcAtomic *
+FcAtomicCreate (const FcChar8 *file);
+
+FcBool
+FcAtomicLock (FcAtomic *atomic);
+
+FcChar8 *
+FcAtomicNewFile (FcAtomic *atomic);
+
+FcChar8 *
+FcAtomicOrigFile (FcAtomic *atomic);
+
+FcBool
+FcAtomicReplaceOrig (FcAtomic *atomic);
+
+void
+FcAtomicDeleteNew (FcAtomic *atomic);
+
+void
+FcAtomicUnlock (FcAtomic *atomic);
+
+void
+FcAtomicDestroy (FcAtomic *atomic);
+
/* fcmatch.c */
FcPattern *
FcFontSetMatch (FcConfig *config,
EXPATLIB=-lexpat
REQUIREDLIBS=$(LDPRELIBS) $(FREETYPE2LIB) $(EXPATLIB)
-SRCS=fcblanks.c fccache.c fccfg.c fccharset.c fcdbg.c fcdefault.c fcdir.c \
- fcfreetype.c fcfs.c fcinit.c fclist.c fcmatch.c fcmatrix.c fcname.c \
- fcpat.c fcstr.c fcxml.c
+SRCS=fcatomic.c fcblanks.c fccache.c fccfg.c fccharset.c fcdbg.c \
+ fcdefault.c fcdir.c fcfreetype.c fcfs.c fcinit.c fclist.c fcmatch.c \
+ fcmatrix.c fcname.c fcpat.c fcstr.c fcxml.c
-OBJS=fcblanks.o fccache.o fccfg.o fccharset.o fcdbg.o fcdefault.o fcdir.o \
- fcfreetype.o fcfs.o fcinit.o fclist.o fcmatch.o fcmatrix.o fcname.o \
- fcpat.o fcstr.o fcxml.o
+OBJS=fcatomic.o fcblanks.o fccache.o fccfg.o fccharset.o fcdbg.o \
+ fcdefault.o fcdir.o fcfreetype.o fcfs.o fcinit.o fclist.o fcmatch.o \
+ fcmatrix.o fcname.o fcpat.o fcstr.o fcxml.o
#include <Library.tmpl>
/*
- * $XFree86: xc/lib/fontconfig/src/fccache.c,v 1.3 2002/02/19 07:50:43 keithp Exp $
+ * $XFree86: xc/lib/fontconfig/src/fccache.c,v 1.4 2002/03/01 01:00:54 keithp Exp $
*
* Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc.
*
FcFileCacheSave (FcFileCache *cache,
const FcChar8 *cache_file)
{
- FcChar8 *lck;
- FcChar8 *tmp;
FILE *f;
int h;
- FcFileCacheEnt *c;
+ FcFileCacheEnt *c;
+ FcAtomic *atomic;
if (!cache->updated && cache->referenced == cache->entries)
return FcTrue;
- lck = malloc (strlen ((char *) cache_file)*2 + 4);
- if (!lck)
+ atomic = FcAtomicCreate (cache_file);
+ if (!atomic)
goto bail0;
- tmp = lck + strlen ((char *) cache_file) + 2;
- strcpy ((char *) lck, (char *) cache_file);
- strcat ((char *) lck, "L");
- strcpy ((char *) tmp, (char *) cache_file);
- strcat ((char *) tmp, "T");
- if (link ((char *) lck, (char *) cache_file) < 0 && errno != ENOENT)
+ if (!FcAtomicLock (atomic))
goto bail1;
- if (access ((char *) tmp, F_OK) == 0)
- goto bail2;
- f = fopen ((char *) tmp, "w");
+ f = fopen ((char *) FcAtomicNewFile(atomic), "w");
if (!f)
goto bail2;
if (fclose (f) == EOF)
goto bail3;
- if (rename ((char *) tmp, (char *) cache_file) < 0)
+ if (!FcAtomicReplaceOrig (atomic))
goto bail3;
- unlink ((char *) lck);
+ FcAtomicUnlock (atomic);
+ FcAtomicDestroy (atomic);
+
cache->updated = FcFalse;
return FcTrue;
bail4:
fclose (f);
bail3:
- unlink ((char *) tmp);
+ FcAtomicDeleteNew (atomic);
bail2:
- unlink ((char *) lck);
+ FcAtomicUnlock (atomic);
bail1:
- free (lck);
+ FcAtomicDestroy (atomic);
bail0:
return FcFalse;
}
/*
- * $XFree86: xc/lib/fontconfig/src/fcint.h,v 1.3 2002/02/18 22:29:28 keithp Exp $
+ * $XFree86: xc/lib/fontconfig/src/fcint.h,v 1.4 2002/02/19 08:33:23 keithp Exp $
*
* Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc.
*
int referenced;
};
+struct _FcAtomic {
+ FcChar8 *file; /* original file name */
+ FcChar8 *new; /* temp file name -- write data here */
+ FcChar8 *lck; /* lockfile name (used for locking) */
+ FcChar8 *tmp; /* tmpfile name (used for locking) */
+};
+
struct _FcBlanks {
int nblank;
int sblank;