--- function.c	2010-07-12 18:20:40.000000000 -0700
+++ function_new.c	2011-12-15 15:06:19.445412100 -0800
@@ -1117,6 +1117,36 @@
   return o;
 }
 
+static char *
+func_withfile (char *o, char **argv, const char *funcname)
+{
+    FILE *fp = NULL;
+    char *filename = argv[0];
+    char *filemode = argv[1];
+    char *data = argv[2];
+    
+    // trim filemode
+    while(*filemode==' ') filemode++;
+    // check for valid filemode, w and a 
+    if (strcmp(filemode, "a") &&
+        strcmp(filemode, "a+") && 
+        strcmp(filemode, "w") && 
+        strcmp(filemode, "w+"))
+    {
+        error (reading_file, "Error while opening file [%s] with mode [%s], the mode is not valid", filename, filemode);
+        return o;
+    }
+
+    fp = fopen(filename, filemode);
+    if (fp == NULL) {
+        error (reading_file, "Error while opening file [%s] with mode [%s]", filename, filemode);
+        return o;
+    }
+    
+    fwrite(data, strlen(data), 1, fp);
+    fclose(fp);
+    return o;
+}
 
 /*
   chop argv[0] into words, and sort them.
@@ -2130,6 +2160,7 @@
   { 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("withfile"),      3,  3,  1,  func_withfile}, 
 #ifdef EXPERIMENTAL
   { STRING_SIZE_TUPLE("eq"),            2,  2,  1,  func_eq},
   { STRING_SIZE_TUPLE("not"),           0,  1,  1,  func_not},
