aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/ecore/efl_io_sizer_fd.c
blob: 9e9326a61277954dccba7140e29970afe0674be5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#define EFL_IO_SIZER_FD_PROTECTED 1

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include <Ecore.h>
#include "ecore_private.h"

#define MY_CLASS EFL_IO_SIZER_FD_CLASS

typedef struct _Efl_Io_Sizer_Fd_Data
{
   int fd;
} Efl_Io_Sizer_Fd_Data;

EOLIAN static void
_efl_io_sizer_fd_sizer_fd_set(Eo *o EINA_UNUSED, Efl_Io_Sizer_Fd_Data *pd, int fd)
{
   pd->fd = fd;
}

EOLIAN static int
_efl_io_sizer_fd_sizer_fd_get(Eo *o EINA_UNUSED, Efl_Io_Sizer_Fd_Data *pd)
{
   return pd->fd;
}

EOLIAN static Eina_Error
_efl_io_sizer_fd_efl_io_sizer_resize(Eo *o, Efl_Io_Sizer_Fd_Data *pd EINA_UNUSED, uint64_t size)
{
   int fd = efl_io_sizer_fd_sizer_fd_get(o);
   if (ftruncate(fd, size) < 0) return errno;
   efl_event_callback_legacy_call(o, EFL_IO_SIZER_EVENT_SIZE_CHANGED, NULL);
   return 0;
}

EOLIAN static uint64_t
_efl_io_sizer_fd_efl_io_sizer_size_get(Eo *o, Efl_Io_Sizer_Fd_Data *pd EINA_UNUSED)
{
   int fd = efl_io_sizer_fd_sizer_fd_get(o);
   struct stat st;
   int r;

   EINA_SAFETY_ON_TRUE_RETURN_VAL(fd < 0, 0);

   r = fstat(fd, &st);
   EINA_SAFETY_ON_TRUE_RETURN_VAL(r < 0, 0);

   return st.st_size;
}

#include "efl_io_sizer_fd.eo.c"