swig: add unexport() calls to be used by destructors in object api
[contrib/mraa.git] / src / gpio / gpio.c
index 0561570..ecd179e 100644 (file)
@@ -158,16 +158,20 @@ maa_gpio_write(maa_gpio_context *dev, int value)
     if (dev->value_fp == NULL) {
         maa_gpio_get_valfp(dev);
     }
-    fseek(dev->value_fp, SEEK_SET, 0);
+    if (fseek(dev->value_fp, SEEK_SET, 0) != 0) {
+        return MAA_ERROR_INVALID_RESOURCE;
+    }
     fprintf(dev->value_fp, "%d", value);
-    fseek(dev->value_fp, SEEK_SET, 0);
+    if (fseek(dev->value_fp, SEEK_SET, 0) != 0) {
+        return MAA_ERROR_INVALID_RESOURCE;
+    }
     if (ferror(dev->value_fp) != 0)
         return MAA_ERROR_INVALID_RESOURCE;
     return MAA_SUCCESS;
 }
 
 maa_result_t
-maa_gpio_close(maa_gpio_context *dev)
+maa_gpio_unexport(maa_gpio_context *dev)
 {
     FILE *unexport_f;
 
@@ -179,6 +183,12 @@ maa_gpio_close(maa_gpio_context *dev)
     fclose(unexport_f);
     if (ferror(dev->value_fp) != 0)
         return MAA_ERROR_INVALID_RESOURCE;
+}
+
+maa_result_t
+maa_gpio_close(maa_gpio_context *dev)
+{
+    maa_gpio_unexport(dev);
     free(dev);
     return MAA_SUCCESS;
 }