Example #1
0
static Eet_File *
_open_temp_eet(Eina_Tmpstr **path, const char *rel)
{
   Eet_File *ef;
   int tmpfd;
   char buffer[PATH_MAX];

   {
      char *tmp;

      tmp = strdup(rel);
      snprintf(buffer, sizeof(buffer), "%s/efreet/%s.XXXXXX.cache",
               efreet_cache_home_get(), basename(tmp));
      free(tmp);
   }

   tmpfd = eina_file_mkstemp(buffer, path);
   if (tmpfd < 0) return NULL;
   close(tmpfd);

   ef = eet_open(*path, EET_FILE_MODE_READ_WRITE);
   if (!ef) goto on_error;

   return ef;

 on_error:
   eina_tmpstr_del(*path);
   *path = NULL;

   return NULL;
}
Example #2
0
// "owner" creates/frees the bufs, clients just open existing ones
Extnbuf *
_extnbuf_new(const char *base, int id, Eina_Bool sys, int num,
             int w, int h, Eina_Bool owner)
{
   Extnbuf *b;
   char file[PATH_MAX];
   mode_t mode = S_IRUSR;
   int prot = PROT_READ;
   int page_size;
   Eina_Tmpstr *tmp = NULL;

   page_size = eina_cpu_page_size();

   b = calloc(1, sizeof(Extnbuf));
   b->fd = -1;
   b->lockfd = -1;
   b->addr = MAP_FAILED;
   b->w = w;
   b->h = h;
   b->stride = w * 4;
   b->size = page_size * (((b->stride * b->h) + (page_size - 1)) / page_size);
   b->am_owner = owner;

   snprintf(file, sizeof(file), "/%s-%i.%i", base, id, num);
   b->file = eina_stringshare_add(file);
   if (!b->file) goto err;


   if (sys) mode |= S_IRGRP | S_IROTH;

   if (owner)
     {
        mode |= S_IWUSR;
        prot |= PROT_WRITE;
     }

   if (b->am_owner)
     {
        b->lockfd = eina_file_mkstemp("ee-lock-XXXXXX", &tmp);
        if (b->lockfd < 0) goto err;
        b->lock = eina_stringshare_add(file);
        if (!b->lock) goto err;
        b->fd = shm_open(b->file, O_RDWR | O_CREAT | O_EXCL, mode);
        if (b->fd < 0) goto err;
        if (ftruncate(b->fd, b->size) < 0) goto err;
     }
   else
     {
        b->fd = shm_open(b->file, O_RDONLY, mode);
        if (b->fd < 0) goto err;
     }
   b->addr = mmap(NULL, b->size, prot, MAP_SHARED, b->fd, 0);
   if (b->addr == MAP_FAILED) goto err;
   return b;
err:
   if (tmp) eina_tmpstr_del(tmp);
   _extnbuf_free(b);
   return NULL;
}
static void
_free_url_test(url_test *info)
{
   unlink(info->_test_file);
   eina_tmpstr_del(info->_test_file);
   close(info->_tmpfd);
   free(info);
}
Example #4
0
static Eina_Bool
_etui_epub_file_unzip(Etui_Provider_Data *pd)
{
    struct archive *a;
    struct archive_entry *entry;
    int r;

    if (!eina_file_mkdtemp("etui-epub-tmp-XXXXXX", &pd->doc.path))
        return EINA_FALSE;

    a = archive_read_new();
    if (!a)
        goto free_path;

    if (archive_read_support_filter_all(a) != ARCHIVE_OK)
        goto free_path;

    if (archive_read_support_format_zip(a) != ARCHIVE_OK)
        goto free_path;

    r = archive_read_open_filename(a, pd->doc.filename, 16384);
    if (r != ARCHIVE_OK)
        goto free_path;

    while (archive_read_next_header(a, &entry) == ARCHIVE_OK)
    {
        if (archive_entry_filetype(entry) == AE_IFREG)
        {
            char buf[PATH_MAX];
            const char *name;
            char *dir;
            char *base;
            size_t size;
            void *data;

            name = archive_entry_pathname(entry);
            dir = strdup(name);
            base = strdup(name);
            if (dir && base && (strcmp(dir, ".") != 0))
            {
                snprintf(buf, sizeof(buf), "%s/%s", pd->doc.path, dirname(dir));
                buf[sizeof(buf) - 1] = '\0';
                ecore_file_mkdir(buf);
                printf(" * %s %s %s\n", name, dirname(dir), basename(base));
            }

            if (base)
                free(base);
            if (dir)
                free(dir);

            size = archive_entry_size(entry);
            data = malloc(size);
            if (data)
            {
                size_t res;

                res = archive_read_data(a, data, size);
                if (res > 0)
                {
                    FILE *f;

                    snprintf(buf, sizeof(buf), "%s/%s", pd->doc.path, name);
                    buf[sizeof(buf) - 1] = '\0';
                    printf(" $ %s\n", buf);
                    f = fopen(buf, "wb");
                    if (f)
                    {
                        fwrite(data, 1, size, f);
                        fclose(f);
                    }
                }

                free(data);
            }
        }
        archive_read_data_skip(a);
    }

    archive_read_free(a);

    return EINA_TRUE;

  free_path:
    eina_tmpstr_del(pd->doc.path);

    return EINA_FALSE;
}
Example #5
0
static int
_evas_gl_common_shader_binary_save(Evas_GL_Shared *shared)
{
   char bin_dir_path[PATH_MAX];
   char bin_file_path[PATH_MAX];
   char tmp_file_name[PATH_MAX];
   int tmpfd = -1, copy;
   Eina_Tmpstr *tmp_file_path = NULL;
   Eet_File *ef = NULL;
   Evas_GL_Program *p;
   Eina_Iterator *it;
   char pname[32];

   /* use eet */
   if (!eet_init()) return 0;

   if (!evas_gl_common_file_cache_dir_check(bin_dir_path, sizeof(bin_dir_path)))
     {
        if (!evas_gl_common_file_cache_mkpath(bin_dir_path))
          return 0; /* we can't make directory */
     }

   copy = evas_gl_common_file_cache_file_check(bin_dir_path, SHADER_EET_CACHENAME,
                                               bin_file_path, sizeof(bin_dir_path));

   /* use mkstemp for writing */
   snprintf(tmp_file_name, sizeof(tmp_file_name), "%s.XXXXXX.cache", bin_file_path);
   tmpfd = eina_file_mkstemp(tmp_file_name, &tmp_file_path);
   if (tmpfd < 0) goto error;

   /* copy old file */
   if (copy)
     {
        ef = eet_open(tmp_file_path, EET_FILE_MODE_READ);
        if (!ef) goto save;
        if (!_evas_gl_common_shader_binary_checksum_check(shared, ef))
          copy = EINA_FALSE;
        eet_close(ef);
        if (copy)
          eina_file_copy(bin_file_path, tmp_file_path, EINA_FILE_COPY_DATA, NULL, NULL);
     }

save:
   ef = eet_open(tmp_file_path, copy ? EET_FILE_MODE_READ_WRITE : EET_FILE_MODE_WRITE);
   if (!ef) goto error;

   if (!_evas_gl_common_shader_binary_checksum_write(shared, ef))
     goto error;

   it = eina_hash_iterator_data_new(shared->shaders_hash);
   EINA_ITERATOR_FOREACH(it, p)
     {
        if (!p->bin_saved)
          {
             int len = 0;
             sprintf(pname, SHADER_PROG_NAME_FMT, p->flags);
             eet_read_direct(ef, pname, &len);
             if (len > 0)
               p->bin_saved = 1; // assume bin data is correct
             else
               _evas_gl_common_shader_program_binary_save(p, ef);
          }
     }
   eina_iterator_free(it);

   if (shared->shaders_cache)
     {
        eet_close(shared->shaders_cache);
        shared->shaders_cache = NULL;
        eet_shutdown();
     }

   if (eet_close(ef) != EET_ERROR_NONE) goto destroyed;
   if (rename(tmp_file_path, bin_file_path) < 0) goto destroyed;
   eina_tmpstr_del(tmp_file_path);
   close(tmpfd);
   eet_shutdown();

   shared->needs_shaders_flush = 0;
   return 1;

 destroyed:
   ef = NULL;

 error:
   if (tmpfd >= 0) close(tmpfd);
   if (ef) eet_close(ef);
   if (evas_gl_common_file_cache_file_exists(tmp_file_path))
     unlink(tmp_file_path);
   eina_tmpstr_del(tmp_file_path);
   eet_shutdown();
   return 0;
}