summaryrefslogtreecommitdiff
path: root/legacy/ethumb/src/bin/ethumbd.c
diff options
context:
space:
mode:
authorGustavo Sverzut Barbieri <barbieri@gmail.com>2010-03-02 00:34:40 +0000
committerGustavo Sverzut Barbieri <barbieri@gmail.com>2010-03-02 00:34:40 +0000
commit9345b211b0441ca431fc71b99c8ae89bb986d5be (patch)
tree4e95e959f3a5f107b0a73579bee67753ad5b0935 /legacy/ethumb/src/bin/ethumbd.c
parentd99f80aff77da19c1d4fcba9344a002bc8818f98 (diff)
fix llvm/clang and gcc errors.
NOTE: mixing write() and fprintf() to the same descriptor (stderr, done by ERR()), will likely cause problems :-/ SVN revision: 46753
Diffstat (limited to '')
-rw-r--r--legacy/ethumb/src/bin/ethumbd.c50
1 files changed, 46 insertions, 4 deletions
diff --git a/legacy/ethumb/src/bin/ethumbd.c b/legacy/ethumb/src/bin/ethumbd.c
index 0401d7902c..8faec801b3 100644
--- a/legacy/ethumb/src/bin/ethumbd.c
+++ b/legacy/ethumb/src/bin/ethumbd.c
@@ -48,6 +48,7 @@
48#define INF(...) EINA_LOG_INFO(__VA_ARGS__) 48#define INF(...) EINA_LOG_INFO(__VA_ARGS__)
49#define WRN(...) EINA_LOG_WARN(__VA_ARGS__) 49#define WRN(...) EINA_LOG_WARN(__VA_ARGS__)
50#define ERR(...) EINA_LOG_ERR(__VA_ARGS__) 50#define ERR(...) EINA_LOG_ERR(__VA_ARGS__)
51#define CRIT(...) EINA_LOG_CRIT(__VA_ARGS__)
51 52
52static const char _ethumb_dbus_bus_name[] = "org.enlightenment.Ethumb"; 53static const char _ethumb_dbus_bus_name[] = "org.enlightenment.Ethumb";
53static const char _ethumb_dbus_interface[] = "org.enlightenment.Ethumb"; 54static const char _ethumb_dbus_interface[] = "org.enlightenment.Ethumb";
@@ -354,6 +355,28 @@ _generated_cb(struct _Ethumbd *ed, Eina_Bool success, const char *thumb_path, co
354 ed->processing = NULL; 355 ed->processing = NULL;
355} 356}
356 357
358static Eina_Bool
359_write_safe(int fd, void *data, size_t size)
360{
361 unsigned char *buf = data;
362 size_t todo = size;
363 while (todo > 0)
364 {
365 size_t r = write(fd, buf, todo);
366 if (r > 0)
367 {
368 todo -= r;
369 buf += r;
370 }
371 else if ((r < 0) && (errno != EINTR))
372 {
373 ERR("could not write to fd=%d: %s", fd, strerror(errno));
374 return EINA_FALSE;
375 }
376 }
377 return EINA_TRUE;
378}
379
357static void 380static void
358_ethumbd_slave_cmd_ready(struct _Ethumbd *ed) 381_ethumbd_slave_cmd_ready(struct _Ethumbd *ed)
359{ 382{
@@ -369,7 +392,7 @@ _ethumbd_slave_cmd_ready(struct _Ethumbd *ed)
369 size_path = (int *)bufcmd; 392 size_path = (int *)bufcmd;
370 bufcmd += sizeof(*size_path); 393 bufcmd += sizeof(*size_path);
371 394
372 write(STDERR_FILENO, bufcmd, ed->slave.scmd); 395 _write_safe(STDERR_FILENO, bufcmd, ed->slave.scmd);
373 396
374 thumb_path = bufcmd; 397 thumb_path = bufcmd;
375 bufcmd += *size_path; 398 bufcmd += *size_path;
@@ -423,7 +446,8 @@ _ethumbd_slave_data_read_cb(void *data, int type, void *event)
423 ssize = ev->size; 446 ssize = ev->size;
424 sdata = ev->data; 447 sdata = ev->data;
425 448
426 write(STDERR_FILENO, sdata, ssize); 449 if (!_write_safe(STDERR_FILENO, sdata, ssize))
450 return 0;
427 451
428 while (ssize > 0) 452 while (ssize > 0)
429 { 453 {
@@ -713,14 +737,30 @@ _ethumb_table_append(struct _Ethumbd *ed)
713 { 737 {
714 int new_max = q->max_count + 5; 738 int new_max = q->max_count + 5;
715 int start, size; 739 int start, size;
740 void *tmp;
716 741
717 start = q->max_count; 742 start = q->max_count;
718 size = new_max - q->max_count; 743 size = new_max - q->max_count;
719 744
720 q->table = realloc(q->table, new_max * sizeof(struct _Ethumb_Object)); 745 tmp = realloc(q->table, new_max * sizeof(struct _Ethumb_Object));
721 q->list = realloc(q->list, new_max * sizeof(int)); 746 if (!tmp)
747 {
748 CRIT("could not realloc q->table to %zd bytes: %s",
749 new_max * sizeof(struct _Ethumb_Object), strerror(errno));
750 return -1;
751 }
752 q->table = tmp;
722 memset(&q->table[start], 0, size * sizeof(struct _Ethumb_Object)); 753 memset(&q->table[start], 0, size * sizeof(struct _Ethumb_Object));
723 754
755 tmp = realloc(q->list, new_max * sizeof(int));
756 if (!tmp)
757 {
758 CRIT("could not realloc q->list to %zd bytes: %s",
759 new_max * sizeof(int), strerror(errno));
760 return -1;
761 }
762 q->list = tmp;
763
724 q->max_count = new_max; 764 q->max_count = new_max;
725 } 765 }
726 766
@@ -874,6 +914,8 @@ _ethumb_dbus_ethumb_new_cb(E_DBus_Object *object, DBusMessage *msg)
874 goto end_new; 914 goto end_new;
875 915
876 i = _ethumb_table_append(ed); 916 i = _ethumb_table_append(ed);
917 if (i < 0)
918 goto end_new;
877 919
878 odata = calloc(1, sizeof(*odata)); 920 odata = calloc(1, sizeof(*odata));
879 odata->index = i; 921 odata->index = i;