summaryrefslogtreecommitdiff
path: root/make-3.82-gbuild
diff options
context:
space:
mode:
authorNorbert Thiebaud <nthiebaud@gmail.com>2012-03-25 11:19:14 -0500
committerNorbert Thiebaud <nthiebaud@gmail.com>2012-03-25 12:46:33 -0500
commit75c7ee67633fac25b0fb70bc96b6df31c2a450e6 (patch)
tree7fd0d9fefb4beb66c0377331e16fc6636cdc7311 /make-3.82-gbuild
parentdd898f9b1cd2629eedd07b5ac00570149b63b69f (diff)
back-port the $(file function
Diffstat (limited to 'make-3.82-gbuild')
-rw-r--r--make-3.82-gbuild/function.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/make-3.82-gbuild/function.c b/make-3.82-gbuild/function.c
index f488f37..7a172f1 100644
--- a/make-3.82-gbuild/function.c
+++ b/make-3.82-gbuild/function.c
@@ -2051,6 +2051,45 @@ func_realpath (char *o, char **argv, const char *funcname UNUSED)
}
static char *
+func_file (char *o, char **argv, const char *funcname UNUSED)
+{
+ char *fn = argv[0];
+
+ if (fn[0] == '>')
+ {
+ FILE *fp;
+ const char *mode = "w";
+
+ /* We are writing a file. */
+ ++fn;
+ if (fn[0] == '>')
+ {
+ mode = "a";
+ ++fn;
+ }
+ fn = next_token (fn);
+
+ fp = fopen (fn, mode);
+ if (fp == NULL)
+ fatal (reading_file, _("open: %s: %s"), fn, strerror (errno));
+ else
+ {
+ int l = strlen (argv[1]);
+ int nl = (l == 0 || argv[1][l-1] != '\n');
+
+ if (fputs (argv[1], fp) == EOF || (nl && fputc('\n', fp) == EOF))
+ fatal (reading_file, _("write: %s: %s"), fn, strerror (errno));
+
+ fclose (fp);
+ }
+ }
+ else
+ fatal (reading_file, _("Invalid file operation: %s"), fn);
+
+ return o;
+}
+
+static char *
func_abspath (char *o, char **argv, const char *funcname UNUSED)
{
/* Expand the argument. */
@@ -2137,6 +2176,7 @@ static struct function_table_entry function_table_init[] =
{ STRING_SIZE_TUPLE("and"), 1, 0, 0, func_and},
{ STRING_SIZE_TUPLE("value"), 0, 1, 1, func_value},
{ STRING_SIZE_TUPLE("eval"), 0, 1, 1, func_eval},
+ { STRING_SIZE_TUPLE("file"), 1, 2, 1, func_file},
#ifdef EXPERIMENTAL
{ STRING_SIZE_TUPLE("eq"), 2, 2, 1, func_eq},
{ STRING_SIZE_TUPLE("not"), 0, 1, 1, func_not},