summaryrefslogtreecommitdiff
path: root/src/lib/ecore/efl_io_positioner_fd.c
blob: 310078951ce6ffee927cf5196a5d1e5fd2b19caf (plain)
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
54
55
56
57
58
59
60
61
62
63
64
65
#define EFL_IO_POSITIONER_FD_PROTECTED 1

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

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

#define MY_CLASS EFL_IO_POSITIONER_FD_CLASS

typedef struct _Efl_Io_Positioner_Fd_Data
{
   int fd;
} Efl_Io_Positioner_Fd_Data;

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

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

static inline int
_efl_io_positioner_whence_convert(Efl_Io_Positioner_Whence whence)
{
   switch (whence)
     {
      case EFL_IO_POSITIONER_WHENCE_START: return SEEK_SET;
      case EFL_IO_POSITIONER_WHENCE_CURRENT: return SEEK_CUR;
      case EFL_IO_POSITIONER_WHENCE_END: return SEEK_END;
     }
   return SEEK_SET;
}

EOLIAN static Eina_Error
_efl_io_positioner_fd_efl_io_positioner_seek(Eo *o, Efl_Io_Positioner_Fd_Data *pd EINA_UNUSED, int64_t offset, Efl_Io_Positioner_Whence whence)
{
   int fd = efl_io_positioner_fd_get(o);
   if (lseek(fd, (off_t)offset, _efl_io_positioner_whence_convert(whence)) < 0)
     return errno;
   efl_event_callback_call(o, EFL_IO_POSITIONER_EVENT_POSITION_CHANGED, NULL);
   return 0;
}

EOLIAN static uint64_t
_efl_io_positioner_fd_efl_io_positioner_position_get(Eo *o, Efl_Io_Positioner_Fd_Data *pd EINA_UNUSED)
{
   int fd = efl_io_positioner_fd_get(o);
   off_t offset;

   EINA_SAFETY_ON_TRUE_RETURN_VAL(fd < 0, 0);

   offset = lseek(fd, 0, SEEK_CUR);
   EINA_SAFETY_ON_TRUE_RETURN_VAL(offset < 0, 0);

   return offset;
}

#include "efl_io_positioner_fd.eo.c"