]> wimlib.net Git - wimlib/blobdiff - include/wimlib/progress.h
Update progress functions
[wimlib] / include / wimlib / progress.h
diff --git a/include/wimlib/progress.h b/include/wimlib/progress.h
new file mode 100644 (file)
index 0000000..387afd8
--- /dev/null
@@ -0,0 +1,31 @@
+#ifndef _WIMLIB_PROGRESS_H
+#define _WIMLIB_PROGRESS_H
+
+#include "wimlib.h"
+
+/* If specified, call the user-provided progress function and check its result.
+ */
+static inline int
+call_progress(wimlib_progress_func_t progfunc,
+             enum wimlib_progress_msg msg,
+             union wimlib_progress_info *info,
+             void *progctx)
+{
+       if (progfunc) {
+               enum wimlib_progress_status status;
+
+               status = (*progfunc)(msg, info, progctx);
+
+               switch (status) {
+               case WIMLIB_PROGRESS_STATUS_CONTINUE:
+                       return 0;
+               case WIMLIB_PROGRESS_STATUS_ABORT:
+                       return WIMLIB_ERR_ABORTED_BY_PROGRESS;
+               default:
+                       return WIMLIB_ERR_UNKNOWN_PROGRESS_STATUS;
+               }
+       }
+       return 0;
+}
+
+#endif