[IIO] Removing fileno() accepted/tizen/unified/20190404.022039 submit/tizen/20190403.111722
authorParichay Kapoor <pk.kapoor@samsung.com>
Mon, 1 Apr 2019 05:26:23 +0000 (14:26 +0900)
committerMyungJoo Ham <myungjoo.ham@samsung.com>
Wed, 3 Apr 2019 11:12:34 +0000 (20:12 +0900)
Removed usage of fileno to file descriptor to compile without error with C89
as fileno() requires _POSIX_C_SOURCE >= 1 || _XOPEN_SOURCE || _POSIX_SOURCE

Using open() from fcntl directly instead of fopen() and fileno() combined
Resolves issue #1293

Signed-off-by: Parichay Kapoor <pk.kapoor@samsung.com>
gst/nnstreamer/tensor_source/tensor_src_iio.c
gst/nnstreamer/tensor_source/tensor_src_iio.h

index 18c0d9e..0299fc9 100644 (file)
@@ -51,6 +51,7 @@
 #include <glib.h>
 #include <string.h>
 #include <endian.h>
+#include <fcntl.h>
 #include <unistd.h>
 #include <errno.h>
 
@@ -1608,16 +1609,15 @@ gst_tensor_src_iio_start (GstBaseSrc * src)
   g_free (device_name);
 
   self->buffer_data_fp = g_new (struct pollfd, 1);
-  self->buffer_data_file = fopen (filename, "r");
-  if (self->buffer_data_file == NULL) {
+  self->buffer_data_fp->fd = open (filename, O_RDONLY | O_NONBLOCK);
+  if (self->buffer_data_fp->fd < 0) {
     GST_ERROR_OBJECT (self, "Failed to open buffer %s for device %s.\n",
         filename, self->device.name);
     g_free (filename);
     goto error_pollfd_free;
   }
-  self->buffer_data_fp->fd = fileno (self->buffer_data_file);
-  self->buffer_data_fp->events = POLLIN;
   g_free (filename);
+  self->buffer_data_fp->events = POLLIN;
 
   self->configured = TRUE;
   /** bytes every buffer will be fixed */
@@ -1725,8 +1725,8 @@ gst_tensor_src_iio_stop (GstBaseSrc * src)
   /** restore the iio device */
   gst_tensor_src_restore_iio_device (self);
 
+  close (self->buffer_data_fp->fd);
   g_free (self->buffer_data_fp);
-  fclose (self->buffer_data_file);
 
   gst_tensors_info_free (&self->tensors_config->info);
   g_free (self->tensors_config);
index 4a8652c..acb3725 100644 (file)
@@ -122,7 +122,6 @@ struct _GstTensorSrcIIO
   channels_enabled_options channels_enabled; /**< enabling which channels */
   guint scan_size; /**< size for a single scan of buffer length 1 */
   struct pollfd *buffer_data_fp; /**< pollfd for reading data buffer */
-  FILE *buffer_data_file; /**< file pointer for reading data buffer */
   guint num_channels_enabled; /**< channels to be enabled */
   gboolean merge_channels_data; /**< merge channel data with same type/size */
   gboolean is_tensor; /**< False if tensors is used for data */