예제 #1
0
FcBool
FcFileIsDir (const FcChar8 *file)
{
    struct stat	    statb;

    if (FcStat ((const char *) file, &statb) != 0)
	return FcFalse;
    return S_ISDIR(statb.st_mode);
}
예제 #2
0
static FcFileTime
FcConfigNewestFile (FcStrSet *files)
{
    FcStrList	    *list = FcStrListCreate (files);
    FcFileTime	    newest = { 0, FcFalse };
    FcChar8	    *file;
    struct  stat    statb;

    if (list)
    {
	while ((file = FcStrListNext (list)))
	    if (FcStat (file, &statb) == 0)
		if (!newest.set || statb.st_mtime - newest.time > 0)
		{
		    newest.set = FcTrue;
		    newest.time = statb.st_mtime;
		}
	FcStrListDone (list);
    }
    return newest;
}
static int
FcDirCacheOpenFile (const FcChar8 *cache_file, struct stat *file_stat)
{
    int	fd;

#ifdef _WIN32
    if (FcStat (cache_file, file_stat) < 0)
        return -1;
#endif
    fd = FcOpen((char *) cache_file, O_RDONLY | O_BINARY);
    if (fd < 0)
	return fd;
#ifndef _WIN32
    if (fstat (fd, file_stat) < 0)
    {
	close (fd);
	return -1;
    }
#endif
    return fd;
}
예제 #4
0
FcBool FcAtomicLock(FcAtomic *atomic) {
    int ret;
    struct stat lck_stat;

#ifdef HAVE_LINK
    int fd = -1;
    FILE *f = 0;
    FcBool no_link = FcFalse;

    strcpy((char *)atomic->tmp, (char *)atomic->file);
    strcat((char *)atomic->tmp, TMP_NAME);
    fd = FcMakeTempfile((char *)atomic->tmp);
    if (fd < 0) return FcFalse;
    f = fdopen(fd, "w");
    if (!f) {
        close(fd);
        unlink((char *)atomic->tmp);
        return FcFalse;
    }
    ret = fprintf(f, "%ld\n", (long)getpid());
    if (ret <= 0) {
        fclose(f);
        unlink((char *)atomic->tmp);
        return FcFalse;
    }
    if (fclose(f) == EOF) {
        unlink((char *)atomic->tmp);
        return FcFalse;
    }
    ret = link((char *)atomic->tmp, (char *)atomic->lck);
    if (ret < 0 && errno == EPERM) {
        /* the filesystem where atomic->lck points to may not supports
         * the hard link. so better try to fallback
         */
        ret = mkdir((char *)atomic->lck, 0600);
        no_link = FcTrue;
    }
    (void)unlink((char *)atomic->tmp);
#else
    ret = mkdir((char *)atomic->lck, 0600);
#endif
    if (ret < 0) {
        /*
         * If the file is around and old (> 10 minutes),
         * assume the lock is stale.  This assumes that any
         * machines sharing the same filesystem will have clocks
         * reasonably close to each other.
         */
        if (FcStat(atomic->lck, &lck_stat) >= 0) {
            time_t now = time(0);
            if ((long int)(now - lck_stat.st_mtime) > 10 * 60) {
#ifdef HAVE_LINK
                if (no_link) {
                    if (rmdir((char *)atomic->lck) == 0)
                        return FcAtomicLock(atomic);
                } else {
                    if (unlink((char *)atomic->lck) == 0)
                        return FcAtomicLock(atomic);
                }
#else
                if (rmdir((char *)atomic->lck) == 0)
                    return FcAtomicLock(atomic);
#endif
            }
        }
        return FcFalse;
    }
    (void)unlink((char *)atomic->new_file);
    return FcTrue;
}