فهرست منبع

moved rgpgfs_gpgme_data_to_file() to new src/gpgme.c

Fabian Peter Hammerle 6 سال پیش
والد
کامیت
db6f05ea53
4فایلهای تغییر یافته به همراه43 افزوده شده و 31 حذف شده
  1. 4 1
      Makefile
  2. 35 0
      src/gpgme.c
  3. 3 0
      src/gpgme.h
  4. 1 30
      src/main.c

+ 4 - 1
Makefile

@@ -15,7 +15,10 @@ default : rgpgfs
 src/fs.o : src/fs.c src/fs.h
 	$(CC) $(CFLAGS) -c $< -o $@
 
-src/main.o : src/main.c src/fs.h
+src/gpgme.o : src/gpgme.c src/gpgme.h
+	$(CC) $(CFLAGS) -c $< -o $@
+
+src/main.o : src/main.c src/fs.h src/gpgme.h
 	$(CC) $(CFLAGS) -c $< -o $@
 
 rgpgfs : src/*.o

+ 35 - 0
src/gpgme.c

@@ -0,0 +1,35 @@
+#include "src/gpgme.h"
+
+#include <gpgme.h>
+
+#include <stdio.h>
+
+int rgpgfs_gpgme_data_to_file(const char *path, gpgme_data_t data) {
+  if (gpgme_data_seek(data, 0, SEEK_SET) != 0) {
+    perror("rgpgfs_gpgme_data_to_file: failed to seek");
+    return 1;
+  }
+
+  FILE *file = fopen(path, "wb");
+  if (file == NULL) {
+    perror("rgpgfs_gpgme_data_to_file: failed to open file");
+    return 1;
+  }
+
+  ssize_t count;
+  char buf[BUFSIZ];
+  while ((count = gpgme_data_read(data, buf, BUFSIZ)) > 0) {
+    if (fwrite(buf, 1, count, file) != count) {
+      fprintf(stderr,
+              "rgpgfs_gpgme_data_to_file: failed to write data to file");
+      return 1;
+    }
+  }
+  if (count != 0) {
+    perror("rgpgfs_gpgme_data_to_file: failed to load data into buffer");
+    return 1;
+  }
+
+  fclose(file);
+  return 0;
+}

+ 3 - 0
src/gpgme.h

@@ -0,0 +1,3 @@
+#include <gpgme.h>
+
+int rgpgfs_gpgme_data_to_file(const char *path, gpgme_data_t data);

+ 1 - 30
src/main.c

@@ -1,4 +1,5 @@
 #include "src/fs.h"
+#include "src/gpgme.h"
 
 // http://libfuse.github.io/doxygen/globals.html
 #define FUSE_USE_VERSION 31
@@ -26,36 +27,6 @@ static const char gpgme_recip_fpr[] =
     "1234567890ABCDEF1234567890ABCDEF12345678";
 static gpgme_key_t gpgme_recip_key;
 
-static int rgpgfs_gpgme_data_to_file(const char *path, gpgme_data_t data) {
-  if (gpgme_data_seek(data, 0, SEEK_SET) != 0) {
-    perror("rgpgfs_gpgme_data_to_file: failed to seek");
-    return 1;
-  }
-
-  FILE *file = fopen(path, "wb");
-  if (file == NULL) {
-    perror("rgpgfs_gpgme_data_to_file: failed to open file");
-    return 1;
-  }
-
-  ssize_t count;
-  char buf[BUFSIZ];
-  while ((count = gpgme_data_read(data, buf, BUFSIZ)) > 0) {
-    if (fwrite(buf, 1, count, file) != count) {
-      fprintf(stderr,
-              "rgpgfs_gpgme_data_to_file: failed to write data to file");
-      return 1;
-    }
-  }
-  if (count != 0) {
-    perror("rgpgfs_gpgme_data_to_file: failed to load data into buffer");
-    return 1;
-  }
-
-  fclose(file);
-  return 0;
-}
-
 static int rgpgfs_encrypt(const char *source_path, char *cache_path) {
   // fprintf(stderr, "rgpgfs_encrypt('%s', %p)\n", source_path, cache_path);
   size_t source_path_len = strnlen(source_path, FUSE_PATH_BUF_LEN);