aboutsummaryrefslogtreecommitdiff
path: root/src/mime.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mime.c')
-rw-r--r--src/mime.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/mime.c b/src/mime.c
index d90cc3f..9fcf97b 100644
--- a/src/mime.c
+++ b/src/mime.c
@@ -1,5 +1,13 @@
+/**
+ * @file mime.c
+ */
#include "spm.h"
+/**
+ * Execute OS `file` command
+ * @param _filename path to file
+ * @return Process structure
+ */
Process *file_command(const char *_filename) {
char *filename = strdup(_filename);
Process *proc_info = NULL;
@@ -26,6 +34,11 @@ Process *file_command(const char *_filename) {
return proc_info;
}
+/**
+ * Execute the `file` command, parse its output, and return the data in a `Mime` structure
+ * @param filename path to file
+ * @return Mime structure
+ */
Mime *file_mimetype(const char *filename) {
char **output = NULL;
char **parts = NULL;
@@ -63,6 +76,10 @@ Mime *file_mimetype(const char *filename) {
return type;
}
+/**
+ * Free a `Mime` structure
+ * @param m
+ */
void mime_free(Mime *m) {
if (m != NULL) {
free(m->origin);
@@ -72,6 +89,11 @@ void mime_free(Mime *m) {
}
}
+/**
+ * Determine if a file is a text file
+ * @param filename
+ * @return yes=1, no=0
+ */
int file_is_text(const char *filename) {
int result = 0;
char *path = normpath(filename);
@@ -84,6 +106,11 @@ int file_is_text(const char *filename) {
return result;
}
+/**
+ * Determine if a file is a binary data file
+ * @param filename
+ * @return yes=1, no=0
+ */
int file_is_binary(const char *filename) {
int result = 0;
char *path = normpath(filename);