forked from KittyHawkCorp/stripzip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port of StripZIP from Zee framework to be standalone
StripZIP application removed of Zee framework error handling with independent makefile. Readme updated with better usage example and some notes.
- Loading branch information
Matt Walker
committed
Feb 11, 2016
1 parent
692cb0f
commit 609a5c7
Showing
5 changed files
with
414 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
*.o | ||
|
||
stripzip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
GCC_OPTS = -std=gnu11 | ||
GCC_OPTS += -Wall -Wextra -Werror | ||
GCC_OPTS += -fdiagnostics-show-option | ||
GCC_OPTS += -Wcast-qual -Wconversion -Wno-sign-conversion -Wfloat-equal -Wno-missing-field-initializers | ||
|
||
GCC_OPTS += -O2 | ||
|
||
all: | ||
gcc $(GCC_OPTS) src/stripzip_app.c -o stripzip | ||
|
||
clean: | ||
rm *o stripzip | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/** | ||
* @file | ||
* Error reporting convienence macros. | ||
* Only the subset required for StripZIP. | ||
* | ||
* Copyright (c) 2016, Zee.Aero | ||
* All rights reserved. | ||
*/ | ||
|
||
/* Shim for error printing outside of a bigger framework */ | ||
#define err_printf(...) printf(__VA_ARGS__) | ||
|
||
#define ERR_PREFIX_(file, line, func) \ | ||
do { \ | ||
err_printf("%s:%d: %s:\n", file, line, func); \ | ||
} while (0) | ||
#define ERR_PREFIX() ERR_PREFIX_(__FILE__, __LINE__, __func__) | ||
|
||
/** | ||
* Print an error message and abort the current function (that is, return | ||
* \a ret) if the expression is false/zero. | ||
* | ||
* @param expr The expression. | ||
* @param ret The return value if \a expr is false/zero. | ||
*/ | ||
#define ERR_RET_IF_NOT(expr, ret) \ | ||
do { \ | ||
typeof(expr) expr_ = (expr); \ | ||
typeof(ret) ret_ = (ret); \ | ||
if (!expr_) \ | ||
{ \ | ||
ERR_PREFIX(); \ | ||
err_printf(" ERR_RET_IF_NOT(%s, %s)\n", \ | ||
(#expr), #ret); \ | ||
return ret_; \ | ||
} \ | ||
} while (0) | ||
|
||
/** | ||
* Print an error message if the two expressions are not equal. | ||
* | ||
* @param expr_1 The first expression. | ||
* @param expr_2 The second expression. | ||
* | ||
* @return True/nonzero if the message was printed (\a expr_1 and \a | ||
* expr_2 were not equal). | ||
*/ | ||
#define ERR_IF_NEQ(expr_1, expr_2) \ | ||
({ \ | ||
typeof(expr_1) expr_1_ = (expr_1); \ | ||
typeof(expr_2) expr_2_ = (expr_2); \ | ||
bool test = expr_1_ != expr_2_; \ | ||
if (test) \ | ||
{ \ | ||
ERR_PREFIX(); \ | ||
err_printf(" ERR_IF_NEQ(%s, %s)\n", \ | ||
(#expr_1), #expr_2); \ | ||
err_printf("\t%s = %jd\n", #expr_1, (intmax_t)expr_1_); \ | ||
err_printf("\t%s = %jd\n", #expr_2, (intmax_t)expr_2_); \ | ||
} \ | ||
test; \ | ||
}) | ||
|
||
/** | ||
* Print an error message and abort the current function (that is, return | ||
* \a ret) if the two expressions are not equal. | ||
* | ||
* @param expr_1 The first expression. | ||
* @param expr_2 The second expression. | ||
* @param ret The return value if two expressions are not equal. | ||
*/ | ||
#define ERR_RET_IF_NEQ(expr_1, expr_2, ret) \ | ||
do { \ | ||
typeof(expr_1) expr_1_ = (expr_1); \ | ||
typeof(expr_2) expr_2_ = (expr_2); \ | ||
typeof(ret) ret_ = (ret); \ | ||
if (expr_1_ != expr_2_) \ | ||
{ \ | ||
ERR_PREFIX(); \ | ||
err_printf(" ERR_RET_IF_NEQ(%s, %s, %s)\n", \ | ||
(#expr_1), #expr_2, #ret); \ | ||
err_printf("\t%s = %jd\n", #expr_1, (intmax_t)expr_1_); \ | ||
err_printf("\t%s = %jd\n", #expr_2, (intmax_t)expr_2_); \ | ||
return ret_; \ | ||
} \ | ||
} while (0) | ||
|
||
/** | ||
* Print an error message and abort the current function (that is, return | ||
* \a ret) if \a expr is negative. The message contains information | ||
* from errno. | ||
* | ||
* @param expr The expression. | ||
* @param ret The return value if \a expr is negative. | ||
*/ | ||
#define ERR_RET_ON_ERRNO(expr, ret) \ | ||
do { \ | ||
typeof(expr) expr_ = (expr); \ | ||
typeof(ret) ret_ = (ret); \ | ||
if (expr_ < 0) \ | ||
{ \ | ||
ERR_PREFIX(); \ | ||
err_printf(" ERR_RET_ON_ERRNO(%s, %s): errno = %s (%d)\n", \ | ||
(#expr), #ret, strerror(errno), errno); \ | ||
err_printf("\t%s = %d\n", #expr, expr_); \ | ||
return ret_; \ | ||
} \ | ||
} while (0) |
Oops, something went wrong.