aboutsummaryrefslogtreecommitdiffstats
path: root/awk.h
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2014-11-22 20:38:31 +0200
committerArnold D. Robbins <arnold@skeeve.com>2014-11-22 20:38:31 +0200
commit838f65088cda84edc2df609d3e388acb3c8eb13d (patch)
tree9841c5f5bcec1057c38d9d1480c8a1d4ec57dbc3 /awk.h
parent1fc15398cbd381b83e20bca3913c12ee7aa34bd4 (diff)
downloadegawk-838f65088cda84edc2df609d3e388acb3c8eb13d.tar.gz
egawk-838f65088cda84edc2df609d3e388acb3c8eb13d.tar.bz2
egawk-838f65088cda84edc2df609d3e388acb3c8eb13d.zip
Dork around with xmalloc for z/OS.
Diffstat (limited to 'awk.h')
-rw-r--r--awk.h45
1 files changed, 36 insertions, 9 deletions
diff --git a/awk.h b/awk.h
index 9b72a53c..84c8ca0e 100644
--- a/awk.h
+++ b/awk.h
@@ -1245,13 +1245,42 @@ DEREF(NODE *r)
#define cant_happen() r_fatal("internal error line %d, file: %s", \
__LINE__, __FILE__)
-#define emalloc(var,ty,x,str) (void)((var=(ty)malloc((size_t)(x))) ||\
- (fatal(_("%s: %s: can't allocate %ld bytes of memory (%s)"),\
- (str), #var, (long) (x), strerror(errno)),0))
-#define erealloc(var,ty,x,str) (void)((var = (ty)realloc((char *)var, (size_t)(x))) \
- ||\
- (fatal(_("%s: %s: can't allocate %ld bytes of memory (%s)"),\
- (str), #var, (long) (x), strerror(errno)),0))
+#define fatal set_loc(__FILE__, __LINE__), r_fatal
+
+static inline void *
+emalloc_real(size_t count, const char *where, const char *var, const char *file, int line)
+{
+ void *ret;
+
+ if (count == 0)
+ fatal("%s:%d: emalloc called with zero bytes", file, line);
+
+ ret = (void *) malloc(count);
+ if (ret == NULL)
+ fatal(_("%s:%d:%s: %s: can't allocate %ld bytes of memory (%s)"),
+ file, line, where, var, (long) count, strerror(errno));
+
+ return ret;
+}
+
+static inline void *
+erealloc_real(void *ptr, size_t count, const char *where, const char *var, const char *file, int line)
+{
+ void *ret;
+
+ if (count == 0)
+ fatal("%s:%d: erealloc called with zero bytes", file, line);
+
+ ret = (void *) realloc(ptr, count);
+ if (ret == NULL)
+ fatal(_("%s:%d:%s: %s: can't reallocate %ld bytes of memory (%s)"),
+ file, line, where, var, (long) count, strerror(errno));
+
+ return ret;
+}
+
+#define emalloc(var,ty,x,str) (void) (var = (ty) emalloc_real((size_t)(x), str, #var, __FILE__, __LINE__))
+#define erealloc(var,ty,x,str) (void) (var = (ty) erealloc_real((void *) var, (size_t)(x), str, #var, __FILE__, __LINE__))
#define efree(p) free(p)
@@ -1285,8 +1314,6 @@ force_number(NODE *n)
#endif /* GAWKDEBUG */
-#define fatal set_loc(__FILE__, __LINE__), r_fatal
-
extern jmp_buf fatal_tag;
extern bool fatal_tag_valid;